Improve orch status reconciliation view

This commit is contained in:
2026-03-20 17:57:58 +08:00
parent 693a79345b
commit cf3c3cbe60
11 changed files with 374 additions and 21 deletions
@@ -375,6 +375,120 @@ func TestOrchStatusReturnsRunSummaryAndTaskList(t *testing.T) {
if got, _ := task["status"].(string); got != "done" {
t.Fatalf("expected task status done, got %#v", task["status"])
}
if got := nestedString(t, task, "latest_attempt", "assigned_to"); got != "worker-a" {
t.Fatalf("expected latest_attempt.assigned_to worker-a, got %q", got)
}
if got := nestedString(t, task, "latest_attempt", "status"); got != "done" {
t.Fatalf("expected latest_attempt.status done, got %q", got)
}
if got := nestedString(t, task, "latest_message", "kind"); got != "result" {
t.Fatalf("expected latest_message.kind result, got %q", got)
}
if got := nestedString(t, task, "latest_message", "summary"); got != "Retry policy implemented" {
t.Fatalf("expected latest_message.summary to match result summary, got %q", got)
}
}
func TestOrchStatusAutoReconcilesAndIncludesBlockedContext(t *testing.T) {
t.Parallel()
dbPath := filepath.Join(t.TempDir(), "coord.db")
runOrchCommand(
t,
"--db", dbPath,
"--json",
"run", "init",
"--run", "run_blog_status_002",
"--goal", "Build blog MVP",
)
runOrchCommand(
t,
"--db", dbPath,
"--json",
"task", "add",
"--run", "run_blog_status_002",
"--task", "T1",
"--title", "Implement retry policy",
"--default-to", "worker-a",
)
dispatchOut := runOrchCommand(
t,
"--db", dbPath,
"--json",
"dispatch",
"--run", "run_blog_status_002",
"--task", "T1",
"--body", "Implement retry handling for the HTTP client.",
)
var dispatchResp map[string]any
mustDecodeJSON(t, dispatchOut, &dispatchResp)
threadID := nestedString(t, dispatchResp, "data", "attempt", "thread_id")
runInboxCommand(
t,
"--db", dbPath,
"--json",
"claim",
"--agent", "worker-a",
"--thread", threadID,
)
runInboxCommand(
t,
"--db", dbPath,
"--json",
"update",
"--agent", "worker-a",
"--thread", threadID,
"--status", "blocked",
"--summary", "Need logging decision",
"--payload-json", `{"question":"Should retry attempts be logged?"}`,
)
statusOut := runOrchCommand(
t,
"--db", dbPath,
"--json",
"status",
"--run", "run_blog_status_002",
)
var statusResp map[string]any
mustDecodeJSON(t, statusOut, &statusResp)
if got := nestedString(t, statusResp, "data", "run", "status"); got != "blocked" {
t.Fatalf("expected run status blocked after status auto-reconcile, got %q", got)
}
tasks := nestedArray(t, statusResp, "data", "tasks")
if len(tasks) != 1 {
t.Fatalf("expected one task in status response, got %#v", tasks)
}
task, ok := tasks[0].(map[string]any)
if !ok {
t.Fatalf("expected task object, got %#v", tasks[0])
}
if got := nestedString(t, task, "status"); got != "blocked" {
t.Fatalf("expected task status blocked, got %q", got)
}
if got := nestedString(t, task, "latest_attempt", "status"); got != "blocked" {
t.Fatalf("expected latest_attempt.status blocked, got %q", got)
}
if got := nestedString(t, task, "latest_attempt", "thread_id"); got != threadID {
t.Fatalf("expected latest_attempt.thread_id %q, got %q", threadID, got)
}
if got := nestedString(t, task, "latest_message", "kind"); got != "question" {
t.Fatalf("expected latest_message.kind question, got %q", got)
}
if got := nestedString(t, task, "latest_message", "summary"); got != "Need logging decision" {
t.Fatalf("expected latest_message.summary to match blocked update, got %q", got)
}
if got := nestedString(t, task, "blocked_question", "summary"); got != "Need logging decision" {
t.Fatalf("expected blocked_question.summary to match latest question, got %q", got)
}
if got := nestedString(t, task, "blocked_question", "kind"); got != "question" {
t.Fatalf("expected blocked_question.kind question, got %q", got)
}
}
func TestOrchReconcileMapsFailedThreadToTerminalTaskState(t *testing.T) {
@@ -28,7 +28,12 @@ func newStatusCmd(root *rootOptions) *cobra.Command {
}
defer sqlDB.Close()
overview, err := store.NewOrchStore(sqlDB).GetRunOverview(ctx, opts.runID)
orchStore := store.NewOrchStore(sqlDB)
if _, err := orchStore.ReconcileRun(ctx, opts.runID); err != nil {
return err
}
overview, err := orchStore.GetRunStatusView(ctx, opts.runID)
if err != nil {
return err
}