Skip to content

feat(chatd): add the workflow run engine behind fork-workflows - #238

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/chat-workflows-1b-starlark
Nov 12, 2026
Merged

ibetitsmike merged 7 commits into
mainfrom
mike/chat-workflows-1b-starlark

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Part of #226. Second PR of the chat-workflows stack: the Starlark run engine that the PR 1a plumbing serves. Behind fork-workflows; with the flag off, chatd behaves exactly like upstream.

What this adds

  • fork_workflow.go: the run_workflow and await_workflow chat tools and the run lifecycle. run_workflow compiles the script, returns running at once, and the program continues in a chatd inflight goroutine. Its agent() / spawn() / wait() / log() built-ins create step children through the PR 1a plumbing, block on them, and combine their workflow_report values. await_workflow blocks until the run ends or its wait elapses; with no awaiter the run queues an end notice on the parent, which the first awaiter deletes. Limits: 64 KiB script, 50 steps per run, 10,000,000 Starlark execution steps, 64 KiB result, one reminder per unreported step.
  • fork_workflow_starlark.go: the Starlark host, verbatim from the prototype. while loops on, no load(), no clock, no files, no network; errors keep the Starlark backtrace with the line number.
  • Resume: the registry keeps runs in one replica's memory (the durable journal is later stack work), so after a restart the model calls run_workflow again with resume_run_id; the deterministic step IDs reuse the finished step chats instead of re-running them.
  • script_path: the script can come from a workspace file, read once at run start through the live turn's agent connection. appendForkTools gains a variadic option carrying that connection from the single turn_environment.go hook line, so every existing caller stays valid and run_workflow serializes after the other tool calls of its batch (a write in the same batch lands first).
  • One hook line changed in turn_environment.go; the Server gains the per-replica workflows registry next to forkPacks.
  • Tests: script-path reads and limits, the replay/resume round trip, the reminder path, the parent end notice (idle parent gets a message, busy parent gets a queued one that await deletes), the step limit, compile and runtime errors, and the turn gate (experiment, root chat, plan mode, explore mode).

Differences from the upstream prototype this ports (coder#31189)

  • The gate moves into appendForkTools as forkWorkflowTools (p.experiments, root chat, no plan mode, no explore mode); the workspace connection travels as a variadic option instead of the prototype's rootChatToolsOptions field.
  • startStep delegates chat creation to PR 1a's createWorkflowStepChat (which validates the exact report tool contract before persisting a child) instead of the prototype's inline creation, and applies the spec defaults before the step key so a resumed run derives the same IDs.
  • The step reminder goes through the fork's sendSubagentMessage (resume validation and family limits apply, as for the other runtime-to-child sends).
  • ARCHITECTURE.md gains one TODO for the run lifecycle for Mike, next to the PR 1a step-chat TODO; the document itself is the human author's.

Xum opened this PR on behalf of @ibetitsmike.

Known gaps

  • A script that deliberately generates and reuses huge spawn/agent prompts or titles can grow step children without a byte cap. Every normal-path input is bounded (script, schema, result, log lines), but the step prompt and title are not. Rejected for this stack as abnormal input; a cap belongs in the same pass as the durable run journal.

Xum updated this PR body on behalf of @ibetitsmike to record the review triage.

run_workflow starts a Starlark program that runs sub-agent steps and
combines their workflow_report values; await_workflow waits for the
result. The registry keeps the runs of one replica in memory, so a
restart loses a run and the model resumes it with resume_run_id: the
deterministic step IDs reuse the finished step chats (PR 1a plumbing).

script_path reads the script from the workspace through the live turn's
agent connection, and run_workflow serializes after the other tool calls
of its batch, so a write in the same batch lands first.

Part of #226
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

@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-12T10:57:14.371110Z 60ce015 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: e60e3e8cca

ℹ️ 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/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
forkWorkflowTools returns run_workflow and await_workflow regardless of
the connection option; the nil-connection subtest asserted one tool.
…d keep the one-reminder limit

Codex round 1 P1 fixes on PR #238:
- The result and step schema budgets now walk the Starlark value before
  json.encode materializes its string, so a script that builds a huge
  value by doubling a string fails with the size error instead of
  allocating the encoded copy first.
- A script that ends without waiting for a spawned step no longer leaves
  the child chat working to its step deadline: execute interrupts the
  child chats of unreported steps and marks the steps failed.
- The one-reminder limit no longer relies on matching the reminder text
  in the child history, which a user_prompt_submit hook rewrite breaks:
  the run records its own send on the step.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

This review request was posted by Xum, an agent working for Mike (repository owner), on Mike's behalf.

@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: 2b9d02ba5b

ℹ️ 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.go Resolved
…t steps

Codex round 2 fixes on PR #238:
- The budget walk now counts each string byte that escapes as six output
  bytes and any other byte as one, matching how the json module quotes
  printable ASCII with strconv.AppendQuote and hands the rest to
  json.Marshal. The advertised 64 KiB result and schema limits are real
  again for ordinary values, and the estimate still never under-counts.
- The size errors carry their context (result or schema) so the tests
  can assert them.
- A step that passes its deadline now interrupts its child chat before
  waitStep returns: the terminal cleanup no longer sees a failed step.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

This review request was posted by Xum, an agent working for Mike (repository owner), on Mike's behalf.

@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: 567f7851cf

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

- log() and print retained their full value: maxWorkflowLogs bounded only
  the line count, so a script could keep 50 unbounded strings alive and
  duplicate them into every run snapshot. Each retained line is now cut
  to 4 KiB on a rune boundary and the retained lines total at most
  maxResultBytes, dropping the oldest first.
- the pre-encode walk charged every small integer 12 bytes, so a valid
  numeric result under 64 KiB (6000 zeroes, for example) was rejected;
  small integers now cost their exact decimal width and big integers
  keep the conservative digit estimate.
- SchemaSizeBeforeEncode used a 20 KB description that passes the exact
  64 KiB budget, so the run completed instead of failing; the payload
  now exceeds the budget on its own.
- ReminderFlagOutlivesScanBlindness blocked inside waitStep: after the
  reminder the step waits for the child's turn to end, and on the
  passive fixture only the test can end it. The subtest now ends the
  turn once the reminder is on record.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

@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: 60ce015745

ℹ️ 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.go Resolved
Comment thread coderd/x/chatd/fork_workflow.go Resolved
@ibetitsmike
ibetitsmike merged commit 6507316 into main Nov 12, 2026
10 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merge gates on head 60ce015:

  • fork-ci run 43203555473 passed, and all check runs on the head passed.
  • Codex review 5873189673 covered this head. Its 1 P1 and 3 P2 findings were declined: the P1 needs abnormal input (huge generated prompts) and is listed under Known gaps, and the P2s are optional. 0 review threads are unresolved.
  • UAT-238 on :3100 passed S0 to S3: the flag gates the tools, fan-out works, and a run resumes across a restart with its steps reused. S4 (script_path) was skipped because :3100 had no workspace.
  • The branch is 0 commits behind main.

fork-workflows stays gated. The owner-gate PR must land before fork-workflows is enabled anywhere.

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