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.
This commit is contained in:
1 parent
14e7512d14
commit
2c09f42ff4
39 files changed
+4264
-83
No files matched your search
@@ -38,6 +38,15 @@ type Query struct {
|
||||
Levels []string
|
||||
// Component matches the "component" field exactly. Empty means any.
|
||||
Component string
|
||||
// Stage matches the entry's own "stage" field exactly (case-insensitive).
|
||||
// Empty means any.
|
||||
//
|
||||
// Only entries a stage tagged carry that field. Agent and tool output is
|
||||
// logged by the runtime that produced it and carries no stage, so a stage
|
||||
// filter NARROWS the file rather than covering it: the caller is obliged to
|
||||
// say that, because an honest-looking filter over a partial field is worse
|
||||
// than no filter. An entry with no stage never matches.
|
||||
Stage string
|
||||
// Contains matches the message or any field value, case-insensitively.
|
||||
Contains string
|
||||
// Limit caps returned entries. Zero selects DefaultTailLines; values
|
||||
@@ -563,6 +572,12 @@ func (q Query) matches(e Entry) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if q.Stage != "" {
|
||||
got, _ := e.Fields["stage"].(string)
|
||||
if !strings.EqualFold(got, q.Stage) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if !q.withinTimeBounds(e.Time) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -29,6 +29,52 @@ func line(level, msg string, extra ...string) string {
|
||||
return s.String() + "}"
|
||||
}
|
||||
|
||||
func TestTailStageFilter(t *testing.T) {
|
||||
path := writeLog(
|
||||
t,
|
||||
line("INFO", "stage starting", `"stage":"prepare"`),
|
||||
line("INFO", "stage finished", `"stage":"prepare"`, `"component":"daemon"`),
|
||||
line("INFO", "stage starting", `"stage":"implement"`),
|
||||
line("INFO", "agent turn", `"component":"daemon"`),
|
||||
line("INFO", "stage starting", `"stage":"PREPARE"`),
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
query Query
|
||||
want []string
|
||||
}{
|
||||
{"stage selects only that stage's entries", Query{Stage: "prepare"}, []string{"stage starting", "stage finished", "stage starting"}},
|
||||
{"stage match is case-insensitive", Query{Stage: "Implement"}, []string{"stage starting"}},
|
||||
{"an entry with no stage never matches", Query{Stage: "prepare"}, []string{"stage starting", "stage finished", "stage starting"}},
|
||||
{"stage combines with level", Query{Stage: "prepare", Levels: []string{"INFO"}}, []string{"stage starting", "stage finished", "stage starting"}},
|
||||
{"stage combines with component", Query{Stage: "prepare", Component: "daemon"}, []string{"stage finished"}},
|
||||
{"a stage nothing carries is empty, not an error", Query{Stage: "nonexistent"}, nil},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := Tail(path, tc.query)
|
||||
if err != nil {
|
||||
t.Fatalf("Tail: %v", err)
|
||||
}
|
||||
got := make([]string, 0, len(res.Entries))
|
||||
for _, e := range res.Entries {
|
||||
got = append(got, e.Message)
|
||||
}
|
||||
if len(got) != len(tc.want) {
|
||||
t.Fatalf("got %v, want %v", got, tc.want)
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tc.want[i] {
|
||||
t.Errorf("got %v, want %v", got, tc.want)
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTailFilters(t *testing.T) {
|
||||
path := writeLog(
|
||||
t,
|
||||
|
||||
Reference in new issue
Block a user