ci / vet-and-test (pull_request) Successful in 39s
Why: workspace writes had no checkpoint, and a 5xx before any output stopped the turn instead of trying the next configured model. Evidence: GOWORK=off go test ./internal/runtime/ ./internal/runmgr/ ./internal/tools/ ./internal/settings/ ./internal/server/ ./internal/app/ Impact: models.chat.fallbacks defaults to empty, so existing runs keep their model. Rewind restores only tracked writes and appends a system note. Usage records the model that served. Refs: feature/durable-rewind Co-authored-by: Cursor <cursoragent@cursor.com>
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); 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})
|
|
}
|