Repository navigation
feat(chatd): journal workflow run args, step reuse and live logs - #341
Conversation
The run detail endpoint now returns what a run did and what it is doing: - WorkflowRunDetail gains args, the JSON object main(args) received. - workflow_steps carries a reused flag. The engine journals it at start and on every replay, a resume of a terminal run marks its rows reused, and a chatdmig node backfills the flag from stored snapshots. The API reads the row instead of the hardcoded false. - A live run writes its log lines through to the journal as the script logs, capped to the last workflowLiveLogs lines, and the detail reads them while the run still runs. The terminal snapshot keeps precedence.
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. |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e62f93e7fa
ℹ️ 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".
Review of #341 found that a log-heavy script wrote one journal row per line, that a restart replay shortened the retained log lines to the lines the replay printed so far, and that a replayed or reported step could clobber its durable state: - The log write-through paces itself. A run flushes at most once per workflowLogFlushInterval, a burst lands in one write, and finish lands the last burst before the run ends. - A rehydrated run starts its logs from the journal column, so the first replayed line extends the retained tail instead of replacing it. - The replay of a finished step flips only the reuse flag, through the new MarkWorkflowStepReused query, so status, value and finished_at stay as the journal holds them. The resume of a terminal run marks its steps through MarkWorkflowStepsReusedByRun, best effort. - workflow_report keeps the reused flag of the row it records, so an accepted report of an already reused step cannot write false back. Generated API artifacts follow the query changes.
…tail-a # Conflicts: # coderd/database/forkdb/sqlc.yaml
Addressed the first review in cdf2bbc and resolved the merge with main in dc97a4d:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc97a4d898
ℹ️ 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".
Second review round: - The immediate log flush now marks itself in flight under journalMu, so the first burst cannot launch one goroutine per line and a slower older write cannot land after a newer one. - The replay of a journaled step always flips only the reuse flag, open rows included. A report the child sent while the run was interrupted can land between the rehydration and the replay, and the full update would reset that row to running.
Second round, in 376e17b:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 376e17bd21
ℹ️ 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".
A line appended while the immediate log flush is in flight dropped its scheduling request, so it stayed unjournaled until the next log call or the end of the run. The completed flush now re-arms one for pending lines. The replay of a restored run duplicated the retained pre-restart lines: the restored baseline and the replayed echo both landed in the view and the journal. appendLogLocked now suppresses the replayed lines that still match the baseline and drops the baseline on the first diverging line. await_workflow for a run this replica does not hold now reports the journaled live lines instead of an empty log.
The generated artifacts of the journal commit picked up a canceled spelling for ChatTodoStatus that the server never had: swag collects enum constants in map order, so the regenerated files drifted from the source. This restores the enum to cancelled and reorders the ChatContextResourceKind enum the way a fresh run of the generator in this tree writes it, which check-apidoc sorts before comparing.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8c3a17e50
ℹ️ 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".
Review of the echo suppression found two more holes: - The baseline held only the retained tail of a capped run, so a replay from the first line broke the match at once and dropped the tail. The suppression now tolerates a baseline that starts mid-stream: an unmatched prefix of the baseline never breaks the match, and the replayed lines the tail dropped append after it. - Two overlapping flushes could still write out of order: the seq check ran before the write, so a stalled write of an older snapshot could replace newer lines. The callers now take a per-run write token before the check and release it after the write, and the SetWorkflowRunLogs query only replaces the column when the stored fork_seq is not ahead, so a stalled write is dropped on the database side as well.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c6f410887
ℹ️ 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".
The logs column of a live run now holds the lines with their journal sequence, but the route still decoded it as a plain array and failed with a 500 for every running run that had logged. It decodes through chatd.RestoreWorkflowRunLogs now, which also keeps the plain array of the backfill readable.
Main gained the list_workflows tool (#338), so forkWorkflowTools now returns three tools; the journal tests assert the new layout.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f74970915d
ℹ️ 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".
…ve logs The capped-tail test resumed through the old fixture server, which still held the run in its registry and returned it without a replay, so the test passed without exercising the replay path. The resume now goes through the restarted server. The generated schema described logs as a terminal-snapshot field only; the comment now says the lines are written through while the run runs, and the artifacts follow.
The echo suppression broke on a capped baseline: the tail starts at line 30 of a run that replayed from line 0, so the first comparison failed and the suppression could drop or reorder the retained tail. The replay now skips the lines the baseline does not name while the match can still continue, keeps the journal writes off until the replay has echoed the whole baseline, and hands back to live output once the replay prints more unmatched lines than the baseline holds. The terminal snapshot always writes the final lines.
…tail-a # Conflicts: # coderd/database/forkdb/sqlc.yaml
…m and determinize the pacing tests The engine log path now appends through its own locked helper, so the echo credit cannot swallow an engine line and an engine line cannot consume a replay echo. flushLogs reports its outcome, and only a missed write token re-arms the fallback: a nothing-pending drop and the closing flag of the end stop the rounds, so no timer outlives the run. The pacing tests count flush attempts with an independent deadline instead of sleeping, and every held write token goes through one helper that cannot double send.
Round 4 on top of df23315, one fix commit cba659e plus a merge of main f9ac8b9:
Evidence: go test -race -count=1 ./coderd/x/chatd/ -run Workflow passes; TestForkWorkflowLiveLogs and TestForkWorkflowStop pass 10 times in a row with -race; TestForkWorkflowEngineLogBypass passes 5 times. The new tests fail against the df23315 production file (build or behavior failure), so they cover the fixes. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9ac8b909e
ℹ️ 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".
…lush and describe the live-log write-through The paced fallback timer stamps its attempt when it fires, on the write and drop outcomes alike, so a line that lands right after a timer write waits out the interval instead of writing back to back. The immediate flush goroutine re-arms on every completed outcome, not only a write: a line that lands while a flush is in flight no longer strands until the next log call or the end of the run, and the nothing-pending re-check keeps that from looping. NoFlushTimerAfterFinish now appends a late line while the terminal flush waits for the held token, which fails when the flushClosing checks are removed. TestForkWorkflowLogPacing pins one write per interval across a timer write followed by a new line, and it fails against the f9ac8b9 timer. The Fork-workflows runs note of the chatd architecture document describes the live-log write-through, its pacing, retention cap and replay, and the workflow run detail marks its args and result as arbitrary JSON in OpenAPI.
Round 5, one commit e194a69 on top of f9ac8b9:
Evidence: go test -race -count=1 ./coderd/x/chatd/ -run Workflow passes; TestForkWorkflowLiveLogs, TestForkWorkflowStop and TestForkWorkflowLogPacing pass 10 times with -race; gofmt and go vet clean. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e194a693fb
ℹ️ 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".
…a and close the round-6 review findings Round 6 of the run-detail review on PR #341: - WorkflowRunDetail.Args and Result lose json.RawMessage and the swaggertype tag: swag renders any as an unconstrained schema, which is what an args value is, so the OpenAPI no longer claims an object. Args keeps no omitempty: the column is non-null and every response sets it. The route tests marshal the fields before JSONEq. - TimerWritePacesTheNextLine no longer re-takes the write token: the token stays free after the timer write, so the stamp alone paces the next line, and the sub-test observes the journal instead of a fixed sleep window. It fails on the pre-round-5 code for the stale-stamp reason. SustainedLoggingWritesOncePerInterval states what it counts and bounds the attempts per elapsed interval instead of a fixed window, so a slow runner cannot trip it. - NoFlushTimerAfterFinish logs the late line through run.log, so the scheduleLogFlush attempt is covered too, and the mutation proof with the closing guards disabled fails on the attempts leak. - The lastLogFlush field comment and the ARCHITECTURE live-logs note name exactly the two paths that stamp the attempt, say that replay suppression is by count, and that a journaled failed step re-emits its failure line through the counted path. - Both new chatdmig node files end in a newline; TestUpgradeMatchesFresh passes.
@codex review New head: 6c85139. Round 6: args and result are any, the pacing and closing tests are load-bearing with mutation proofs, the stamp comments are exact, and both new migration nodes end in a newline. |
The 01a1d05b node ran on the production database already, so its checksum in the chatdmig ledger is immutable: a newline would make NewRunner refuse to start with the node changed after it ran. Only 01a1e3a6, the run-detail node new in this PR, keeps the trailing newline.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c851391b5
ℹ️ 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".
The run detail of a failed or stopped run stored the JSON null literal of the snapshot in Result, so the response carried a present "result": null. The raw bytes of a JSON null are four characters, so the guard compares against that literal too. A route test now pins that a failed run omits the result key. The pacing test no longer depends on wall clock between ticks: it sleeps one half interval, asserts the journal still holds two lines, then waits for the third. Its mutation proof fails at the timer stamp. The Args and Result field comments note that the Go client decodes numbers as float64, and the API docs and TS types are regenerated. The mock run detail of the UI test helper carries args, which the type check needs since args lost its omitempty.
@codex review Round 7 head: b3d4d0b |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3d4d0b290
ℹ️ 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".
- codersdk: WorkflowRunDetail.UnmarshalJSON decodes Args and Result from the raw JSON when present, so large integers keep exact values instead of rounding through float64. - coderd: the result guard keeps only non-empty snapshots, so a failed or stopped run never gains a result key and a completed run keeps its value, including the encoded null of a script whose main returned None. - chatd: log flush timing moves onto r.p.clock (quartz), so the pacing tests run on a mock clock with no wall-time sleeps. - chatd: NoFlushTimerAfterFinish accepts either correct terminal failure line (the stop reason or the no-report failure) and prints the logs it last saw if the terminal flush never carries them. - regen: apidoc, schemas.md, typesGenerated.ts; the Experiment enum order matches main again. - tests: CompletedNoneReturnsNull, FailedRunHasNoResultKey omits the key, TestWorkflowRunDetailUnmarshalExactNumbers, mock-clock pacing tests.
@codex review Round 8 head: 650911a |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 650911a23a
ℹ️ 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".
Journal the args bytes the caller sent instead of re-encoding the decoded Args, so a number outside the float64 exact range reaches main(args) unrounded. Test with 9007199254740993. NoFlushTimerAfterFinish: wait for the step to be open before stop, drop the impossible no-report candidate, wait with testutil.Eventually and stamp with the run clock. Pin the pacing comment to the mock clock. Tag the quartz flush Now reads and the timer Stop with chatd and workflow_log_flush. Reword the args and result doc text and restore the origin/main enum order in the generated docs.
Round 9, head 1c4042b. For the Codex thread on inline args rounding: fixed rather than reworded. startWorkflowRun now prefers args.rawArgs, the args bytes exactly as the model sent them, when journaling, so main(args) and the run detail read the same value; marshaling args.Args stays the fallback. Covers the 9007199254740993 case with TestForkWorkflowInlineArgsExact (commit 1c4042b). Also in this round: NoFlushTimerAfterFinish waits for the step to be open before stop, drops the impossible no-report candidate, and waits with testutil.Eventually on the run clock; the quartz flush Now reads and the timer Stop are tagged chatd, workflow_log_flush; the args and result docs no longer name UnmarshalJSON; the generated enum order is back to origin/main and check-apidoc passes. @codex review this head please. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c4042b5bd
ℹ️ 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".
Restore the files a lint run reformatted to their round 8 content and keep only the pacing comment fix. No lint flag was used.
A raw null in the args field journals as the empty object again, so main(args) receives a dict and not None; rawArgs is used only when the decode produced a value. InlineArgsExact drives the run_workflow tool handler, so the rawArgs capture is under test. NullArgs covers the inline and saved paths. The codersdk absent-key tests assert the field is nil directly and that a re-marshal keeps the key absent, and they fail with the raw guards removed. The paced flush timer arms with the chatd and workflow_log_flush tags, which quartz v0.3 accepts after fn. NoFlushTimerAfterFinish logs the logs it saw from inside the eventually. The docs generator refreshed schemas.md, typesGenerated.ts and the fixture args.
Round 10, head fe0bd52. All three Codex threads from 1c4042b are fixed, plus five findings from our own round review:
@codex review this head please. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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 as 0f391d6 (squash, Gates on head fe0bd52:
Not exercised: a live run on the dev server (live logs in the run detail page, stop from the UI, restart replay). The UI half of #324 follows in a separate PR. |
Part of #324 (items 2 and 5 of #226). The UI lands in a stacked PR on top of this one, which closes the issue.
The run detail endpoint now returns what a run did and what it is doing:
WorkflowRunDetailgainsargs, the JSON objectmain(args)received.workflow_stepscarries areusedflag. The engine journals it at start and on every replay, a resume of a terminal run marks its rows reused, and a chatdmig node backfills the flag from stored snapshots. The API reads the row instead of the hardcodedfalse.workflowLiveLogslines, and the detail reads them while the run still runs. The terminal snapshot keeps precedence.With
fork-workflowsoff, nothing changes. Stop and resume behavior (#323) and phases (#325) are untouched.Tests: chatd journal engine tests for live logs (write through while running, cap) and reuse journaling (fresh false, resume true, terminal-resume rows marked), a chatdmig backfill test against Postgres, dbauthz authorizer cases for the two new forkdb queries, and coderd route tests for
args,reusedand live logs in the detail.