Why: Account disable could be followed by late Backend business writes, API key creation could implicitly create users, account bootstrap locks could invert, and directory cursors were process-local or leaked out-of-scope changes. Evidence: Local go test ./... and isolated PostgreSQL package suites passed on the staged candidate; exact committed-head SELF replay and stage 6 human review remain pending. Impact: Adds final account transactions and external-effect checks across HTTP, Host, Bus and run manager; tightens API key issuance and persists versioned cursor signing. Delegated RDM rename still needs the separately proposed real-operator contract, so A1 and stage 6 are not complete. Refs: Documents U3 r1, approved A1-A4 amendment fb3a821, pending delegated-projection amendment 5783940, Dev feature/iam-u3-account-directory-recovery.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"agent-system-backend/internal/runmgr"
|
|
)
|
|
|
|
func (s *Server) listCheckpoints(w http.ResponseWriter, r *http.Request) {
|
|
id := r.PathValue("id")
|
|
owner := s.owner(r)
|
|
if _, err := s.st.GetConversation(owner, id); err != nil {
|
|
writeStoreErr(w, err)
|
|
return
|
|
}
|
|
messageID := r.URL.Query().Get("messageId")
|
|
plan, err := s.mgr.PlanRewind(owner, id, messageID)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]any{"restored": plan.Restored, "skipped": plan.Skipped})
|
|
}
|
|
|
|
func (s *Server) rewindFiles(w http.ResponseWriter, r *http.Request) {
|
|
id := r.PathValue("id")
|
|
owner := s.owner(r)
|
|
if _, err := s.st.GetConversation(owner, id); err != nil {
|
|
writeStoreErr(w, err)
|
|
return
|
|
}
|
|
var req struct {
|
|
MessageID string `json:"messageId"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || req.MessageID == "" {
|
|
http.Error(w, "messageId required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if err := s.mgr.ClaimConversation(id, owner); err != nil {
|
|
if errors.Is(err, runmgr.ErrConversationBusy) {
|
|
http.Error(w, "conversation busy", http.StatusConflict)
|
|
return
|
|
}
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
defer s.mgr.ReleaseConversation(id)
|
|
res, err := s.mgr.RewindFiles(owner, id, req.MessageID)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]any{"restored": res.Restored, "skipped": res.Skipped})
|
|
}
|