Skip to content

fix(chatd): journal workflow reports from recovered step chats - #259

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/chat-workflows-report-interrupted
Nov 12, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/chat-workflows-report-interrupted

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Part of #226.

Note: This PR was authored and submitted by Xum (an autonomous agent) acting on Mike's behalf.

Problem (found in UAT-256 U6b)

A workflow run that was mid-step when the coderd process restarted stays interrupted in the journal. Chat recovery re-ran the step child's turn, the model called workflow_report, and the tool answered "Value accepted. The workflow has your result." But nothing read that value: the run's waitStep loop died with the process, so the step row stayed running without a value and the run row stayed interrupted. Autodeploy restarts the server on every merge, so this path happens in practice.

Fix

workflow_report now binds to the step chat it serves and records the report where it will actually be read:

  • Run still executing (including after a resume_run_id): unchanged. The tool validates, answers, and the run's waitStep reads the value from the chat history as before.
  • Run not live (registry lost it): the tool writes the value to the journal step (status=reported, value), so the answer is true and a later resume replays the value without running the child again. The journal write is not best-effort here: a failed write answers with an error the model can retry.
  • Run that already ended (terminal journal row, whether or not the registry still holds it): the tool fails with the run's status instead of accepting a value nothing will read. Same for a step row that is missing (crash between child-chat creation and its journal row) or already failed.

The journal path reuses the existing UpdateWorkflowStep query and its authorizer; no schema changes.

Tool-name collision warning

appendDynamicTools warned "dynamic tool name collides with built-in tool, tool_name=workflow_report" on every step-chat turn: the step chat's dynamic tools column holds chatd's own placeholder for the name, and chatd injects the real server tool built from that same column. The built-in owning the name is the design, so the deliberate collision is now silent; collisions with any other built-in still warn.

Tests

  • TestForkWorkflowReportJournal/RecoveredStepChildJournalsItsReport: restart marks the run interrupted, a report through the step chat's tool lands in the journal, and resume_run_id completes the run off the journaled value without sending the child a new prompt. Fails without the fix (the resume re-runs the child instead).
  • ReportOnEndedRunFails: a late report on a completed run errors and does not overwrite the journaled value.
  • ReportWithoutJournalRowFails: a step child whose run row is gone gets a clear error.
  • TestForkWorkflowReportCollision: the step chat's own collision stays silent; an unrelated collision still warns.

Validation

  • go build ./coderd/..., go vet, gofmt clean.
  • chatd tests run in CI and an ops container (chatd does not link on the host).

A step child that was mid-turn when the process restarted recovers
through chat recovery and calls workflow_report while its run sits
interrupted in the journal. The tool validated the value and answered
"Value accepted", but no live run was waiting to scan the chat
history, so the step stayed running without a value and the run stayed
interrupted: the report reached nothing.

workflow_report now binds to its step chat. When the run is still
executing, the tool answers as before and the run's own waitStep picks
the value up. Otherwise the tool writes the value to the journal step,
so a resume_run_id replays it without running the child again, and a
late report on a run that already ended fails with the run's status
instead of accepting a value nothing will read.

appendDynamicTools no longer warns about the collision between a step
chat's own workflow_report definition and the server tool built from
that same column: the built-in owning the name is the design, and the
warning fired on every step-chat turn.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T20:16:28.184348Z a3a9764 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1f95fe9f0

ℹ️ 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".

Comment thread coderd/x/chatd/fork_workflow_report.go Resolved
Comment thread coderd/x/chatd/fork_workflow_report.go Resolved
OtherCollisionsStillWarn built its dynamic column from
workflowStepTools, which defines only workflow_report, so the column
never collided with the other_tool built-in and the warning the test
expects never fired.
The warning names the tool in a log field, so a message-contains
assertion on the tool name never matched.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Note: This comment was posted by Xum (an autonomous agent) acting on Mike's behalf while preparing PR #259 for review.

Please review the current head a3a9764: fix(chatd) journals workflow reports from recovered step chats (interrupted-run reports now reach the journal so resume_run_id replays them; late reports on ended runs fail clearly; the deliberate step-chat tool-name collision no longer warns).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3a9764cbb

ℹ️ 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".

Comment thread coderd/x/chatd/fork_workflow_report.go Resolved
Comment thread coderd/x/chatd/fork_workflow_report.go Resolved
Comment thread coderd/x/chatd/fork_workflow_report.go Resolved
@ibetitsmike
ibetitsmike merged commit 70e38b3 into main Nov 12, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-workflows-report-interrupted branch November 12, 2026 20:20
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged head a3a9764cbb as squash commit 70e38b3ce8. Gates on that head:

  • fork-ci run 43294698852: all 7 jobs passed.
  • Codex review 5881377090: the P1 on the collision warning test was fixed in ea9a9589b1. Five P2/P3 findings were declined as edge cases off the normal path. 0 unresolved threads.
  • Ops containerized TestForkWorkflow* run against Postgres 17 passed on this head (rerun2). RecoveredStepChildJournalsItsReport fails without the fix.
  • No live UAT: this changes backend behavior on the restart path and has no UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant