Files
archie/internal/webui/api_tasks_debug.go
T
sam 2ef962912a feat(tasks): attribute events, changes and config to the attempt that produced them
The events table had no attempt column, so two attempts of the same task were
indistinguishable: a retried task's stage events interleaved into one timeline and
nothing could say which run produced a given result.

- events gains an `attempt` column through the existing presence-gated
  migrateTasks loop rather than a version bump, so user_version stays 3 and an
  existing archie.db is migrated in place. A legacy-database test builds the
  pre-change schema and proves both that existing rows survive unattributed
  (attempt = 0) and that a new value round-trips.
- Event.attempt = 11 and ReadTaskLogRequest.stage = 9 are field additions to
  existing messages: no new RPC, no new table, and no change to any canonical error
  message that crosses the state-store wire.
- Every task event the workflow engine emits now carries the attempt. Producers
  that have no attempt yet (task_queued, binding_dispatch_failure) stay
  unattributed rather than guessing one.
- Changed files are captured as a durable changes_captured event at commit and push
  time, reusing the existing three-dot diff primitive: paths from FilePatches(),
  counts from Stats(), base_sha recorded as the merge base actually diffed rather
  than the base tip, a 200-file cap with totals kept complete. Consumption goes
  through an unexported optional interface so workflow.Trees -- the yaegi capability
  surface for interpreted stage plugins -- is not widened. A capture is also taken
  once the pull request exists, so the capture can link it.
- The per-attempt configuration is captured as a durable config_captured event
  carrying the non-secret config.TaskConfig, instead of a new table plus two new
  state-store RPCs: events are already this system's per-attempt provenance stream,
  so a table would have given one feature two provenance mechanisms. Redaction is
  proven against canary secrets. Measured payload: 539 bytes typical, 2333 bytes at
  20 models.
- Captures carry a schema marker and are refused unless their key set matches the
  declared payload shape, so drift surfaces as "recorded but could not be read"
  rather than as a capture of zeroes.
- Three read endpoints serve the attempt rail, the changed-file captures and a raw
  debug view, mapping to UI-owned response types rather than dumping store types.
- The task-log read gains a stage filter, bound to the stage logger for that
  stage's own lines; agent and tool output records no stage.

A task-scoped grant may already insert events on its own task, so this provenance
is exactly as trustworthy as the rest of that task's event stream. That limit is
documented rather than papered over.
2026-09-18 18:32:59 +10:00

46 lines
1.7 KiB
Go

package webui
import (
"net/http"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/events"
)
// taskDebugView is GET /api/tasks/{id}/debug: the stored task record as it is,
// and every event recorded for the task. It is deliberately not a generic
// store-dump route -- the task list is capped at 100 rows, so a page that wanted
// to show an older task's raw provenance had no row to join against. Nothing
// here is projected, filtered or re-spelled: reading it is the point.
//
// Events are UNFILTERED. A debug view that silently hid the events of other
// attempts would be worse than useless; each event carries its own attempt, so
// the operator sees everything and can attribute it. Attempt reports only which
// attempt the page had selected. No log payload is included: the log tab already
// serves it, and embedding it would duplicate a large body for no new
// information.
type taskDebugView struct {
TaskID int64 `json:"task_id"`
Attempt int `json:"attempt"`
Task task.Task `json:"task"`
Events []events.Event `json:"events"`
}
// handleTaskDebug serves the task's raw record together with its whole event
// list, for whichever attempt the request names.
func (s *Server) handleTaskDebug(w http.ResponseWriter, r *http.Request) {
t, attempt, ok := s.taskAttemptTarget(w, r)
if !ok {
return
}
evs, err := s.Store.TaskEvents(r.Context(), t.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if evs == nil {
evs = []events.Event{}
}
writeJSON(w, taskDebugView{TaskID: t.ID, Attempt: attempt, Task: *t, Events: evs})
}