Repository navigation
feat: workflow run list, detail, and stop API - #258
Conversation
A nil json.RawMessage parameter is not a driver NULL: database/sql converts it to a zero-length []byte, which lib/pq sends as an empty string and Postgres rejects on a jsonb column (invalid input syntax for type json). Route the three nullable jsonb params through pqtype.NullRawMessage via sqlc column overrides and a jsonbValue helper.
The run list, run detail and stop_workflow of a chat, as the API side
of the fork-workflows experiment:
- GET /api/v2/chats/fork/{chat}/workflow-runs (keyset page, step counts)
- GET /api/v2/chats/fork/{chat}/workflow-runs/{run} (script, steps,
result and logs of the terminal snapshot)
- POST /api/v2/chats/fork/{chat}/workflow-runs/{run}/stop (409 terminal)
Every route is gated like the workflow tools: the fork-workflows
experiment and the chat owner's deployment owner role. The stop runs
through chatd.ForkStopWorkflowRun: a live run unwinds on a canceled
script context and journals stopped with a snapshot that carries the
failed open steps; a run this replica does not hold is stopped through
its journal rows.
A chatdmig node adds workflow_runs.updated_at/finished_at and
workflow_steps.started_at/finished_at, which the run status updates
stamp. The generated forkdb output, the apidoc swagger entries and
typesGenerated.ts are not in this commit yet.
…olumns The sqlc.arg(...)::jsonb casts cut the params off from the column overrides, so InsertWorkflowStepParams.Value and the Update* result and value params generated as json.RawMessage and did not compile against jsonbValue's pqtype.NullRawMessage. An uncast param keeps the override: the generated param is NullRawMessage, which sends a real SQL NULL for an empty document instead of the zero-length string Postgres rejects on jsonb. The models already scanned NullRawMessage, so this completes the same fix as the column overrides.
…s-2b-run-api # Conflicts: # coderd/database/forkdb/queries/workflow_runs.sql
The merge of the jsonb param fix duplicated the method after FailOpenWorkflowStepsOfRun; vet caught the redeclaration.
A resumed run returned journaled steps without setting reused, so the await result showed reused false for steps the restart did not run again. The journal read path already hardcodes reused for the same reason.
…b-run-api # Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/dbmetrics/fork_forkdb.go # coderd/database/forkdb/queries/workflow_runs.sql # coderd/database/forkdb/sqlc.yaml # coderd/x/chatd/fork_workflow.go # coderd/x/chatd/fork_workflow_journal.go # coderd/x/chatd/fork_workflow_journal_internal_test.go
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
coder/coderd/x/chatd/fork_workflow.go
Lines 495 to 496 in aee11f5
If a stop request wins the requestStop lock after program.run has returned successfully but before finish stores the result, requestStop reports success and cancels the context, yet this path only checks stopRequested when err != nil and unconditionally records completed for the successful return. The caller therefore receives a successful stop even though the run completes normally; check the stop flag after program.run regardless of its error result.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e786e767e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Merged head
|
Part of #226 (items 3-4 of the W12 workflow stack: stop_workflow plus the run list/detail API). Follows #257 (durable journal).
What
Stops and introspection for workflow runs, on top of the PR2a journal:
POST /api/v2/chats/fork/{chat}/workflow-runs/{run}/stop: stops a running run. The script context is canceled, open steps fail with "stopped by user" (FailOpenWorkflowStepsOfRunjournals them), and their child chats stop. The run readsstoppedafterwards. A run that already ended answers 409; an interrupted run is not stoppable either, because the agent continues it withresume_run_id. Sentinels:ErrForkWorkflowRunNotFound,ErrForkWorkflowRunTerminal.GET /api/v2/chats/fork/{chat}/workflow-runs: one keyset page (?limitdefault 50 at most 100,?after=<RFC3339 created_at>/<run id>), newest first, with per-run step counts (total/running/done/failed; done = reported, running = running or reminded). List items omit the script and carryscript_preview(first 200 chars).GET /api/v2/chats/fork/{chat}/workflow-runs/{run}: full detail: script, steps (id == child chat id, status, reused, ordinal, started/finished), terminal result and the last 50 log lines of the terminal snapshot.01a1d05b-..._workflow_run_timestamps.up.sql:workflow_runs.updated_at/finished_at,workflow_steps.started_at/finished_at;UpdateWorkflowRunStatus/UpdateWorkflowStepstamp them via CASE on the terminal statuses.requestStopcancels the script context,executemapsstopRequested && ctx.Err()tostopped,interruptOpenStepsruns on a fresh inflight context, and shutdown still journalsinterrupted, notstopped.All three routes live under the fork chat routes with the experiment flag and the owner gate (deployment owners only, 403 fail-closed), and carry
@x-apidocgen {"skip": true}so the markdown reference docs are untouched; swagger.json, docs.go and typesGenerated.ts are regenerated and committed.Known gaps
runningafter a mid-turn crash is pre-existing PR1b behavior.reusedflag; only the terminal result snapshot has it. The detail view of a resumed run therefore reportsreused: falsefor its steps; theawait_workflowresult is authoritative for reuse.Tests
TestForkWorkflowStop/{StopsALiveRun,InterruptedRunIsNotStoppable}(registry stop, interrupted 409 semantics), journal stop path in the restart tests.TestForkWorkflowRunsRoutes/{ExperimentOff,ListAndDetail}(403 with the flag off, list step counts, detail logs/result, 409 stopping a terminal run, 404 unknown run).TestForkQueriercases forGetWorkflowRunsByChat,GetWorkflowRunStepCountsByChat,FailOpenWorkflowStepsOfRun(read/update through the owning chat;FailOpenWorkflowStepsOfRunauthorizes via the run's chat).