Repository navigation
feat(chatd): journal workflow runs so a restart resumes them - #257
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.
…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.
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.
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
Here are some automated review suggestions for this pull request.
Reviewed commit: 85772738e5
ℹ️ 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: 45558e0bf5
ℹ️ 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
Known limit: the startup sweep is unscoped, so this assumes a single chatd replica. Replica leases are follow-up work. |
Part of #226 (workflow runs): the durable run journal. PR1a (#228) wired the workflow tools, PR1b (#238) added the in-memory engine, PR1c (#242) gated them to deployment owners. This PR journals every run so a restart resumes it instead of dropping it.
What changed
01a1d041-1628-77af-9c39-d4e3e711e0d3_workflow_journal.up.sql:workflow_runs(id, chat_id, model_config_id, script, args, status running|interrupted|completed|failed|stopped, error, result jsonb, created_at) andworkflow_steps(id = the step's child chat id, run_id, spec_key, occurrence, ordinal, title, status running|reminded|reported|failed, value jsonb, error), UNIQUE(run_id, spec_key, occurrence).queries/workflow_runs.sql): 8 journal queries (get/insert run and step, list steps of a run, update run status + step, mark open runs interrupted). Nullable jsonb columns and params usepqtype.NullRawMessageso an empty document journals as a real SQL NULL, not an empty string.fork_workflow_journal.go):startWorkflowRunwrites the run row before the script executes,startStepwrites each step after its child chat exists (a crash between the two self-heals on resume),waitStepjournals reminded/reported transitions, andfinishjournals the terminal status with the full result snapshot. The startup sweep marks still-running rowsinterruptedwith a fixed error, soresume_run_idcan pick them up.resume_run_idon an open run re-executes the deterministic script from the top; the k-th call of a spec maps onto journaled occurrence k, finished steps return their journaled report withreused: trueand unfinished ones reuse their child chat. Resuming a terminal (completed/failed/stopped) run replays the stored snapshot without executing anything.dbauthz/dbmetrics(MarkOpenWorkflowRunsInterruptedis system-scoped).Resume observability note
A resumed open run answers
run_workflowbefore the script re-executes, so that snapshot hassteps: []andstatus: running;reused: trueappears in theawait_workflowresult. A resumed terminal run returns the full step list withreused: trueimmediately.Known limits
runningafter a mid-turn crash is pre-existing PR1b behavior.Size note
Hand-written code plus tests is ~940 lines; the 372-line gen commit is sqlc/goimports/mockgen output over the 10 fork queries. The lead approved landing the stack as one PR instead of splitting tests out.
Validation
Container slot r8 (ops-verified, script sha1 693e3e731c): sqlc regen + build + vet + gofmt + chatdmig check green on 8577273's source commits, and the full
TestForkWorkflow*chatd suite passed on real Postgres for both this branch (step2 rc=0) and the stacked 2b compile+tests (step3/step4 rc=0). Log sha1 f8919b7bec. fork-ci on this head is the authority for the coderd route tests and everything else.