Skip to content

feat(chatd): run saved workflows by name - #338

Merged
ibetitsmike merged 51 commits into
mainfrom
mike/issue-322-saved-workflows-d
Nov 15, 2026
Merged

ibetitsmike merged 51 commits into
mainfrom
mike/issue-322-saved-workflows-d

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Part 4 of 4 for #322. Stacked on #337 (org routes), which is stacked on #336 (user routes) and #335 (storage).

What changed

  • run_workflow takes a new name argument. With name, chatd loads the saved workflow and runs its script with args. The lookup runs as the chat owner through dbauthz: the owner's personal workflow in the chat's organization first, then an organization workflow shared with the owner. A personal workflow hides an organization one with the same name.
  • If the saved workflow has an args schema, args must match it before the run starts. The check uses the same validator and number rules as workflow_report. Missing args validate as {}.
  • name together with script or script_path is an error. An unknown name, or one the owner cannot read, gives the same "no saved workflow is named" error.
  • The journal stores the resolved script, so a retry or resume_run_id replays that script even if the saved workflow is edited later.
  • New read-only tool list_workflows. Without name it lists the runnable workflows: name, tier, a description cut to 300 bytes, phases and has_args_schema. With name it returns the full description, args schema and phases.
  • With fork-workflows off, forkWorkflowTools still returns nothing, so there is no name argument and no list_workflows.

Why a list_workflows tool and not the tool description

An organization can hold many saved workflows, each with a description up to 4 KiB and an args schema up to 12 KiB. Putting them in the run_workflow description would add that to every turn's tool definitions. Tool definitions sit in the cached prompt prefix, so any edit by another user would also break prompt caching for every chat in the organization. A lazy tool costs nothing until the agent needs it and needs no database query on each turn. The run_workflow description tells the agent to call list_workflows.

No agent tool writes saved workflows

  • The workflow tool set is exactly run_workflow, await_workflow and list_workflows. list_workflows takes only name.
  • A test lists, reads and runs a saved workflow and checks that the row is unchanged afterwards.
  • TestForkSavedWorkflowsNoWriter parses every non-test Go file under coderd/x/chatd and fails on any call named Insert*SavedWorkflow, Update*SavedWorkflow*, Upsert*SavedWorkflow* or Delete*SavedWorkflow*. Only the coderd routes write them.

Tests

flock ~/.fork-go.lock go test ./coderd/x/chatd/ -run 'TestForkWorkflow|SavedWorkflow' -count=1 -v

All pass. New tests:

  • TestForkSavedWorkflowTools/RunByName: runs a personal workflow by name with args, checks the step, the journaled script and args, and the completed result.
  • TestForkSavedWorkflowTools/PersonalHidesOrganization: list output, tiers, and that the personal one runs.
  • TestForkSavedWorkflowTools/ListDetails: truncation on a rune boundary, full detail by name, missing name.
  • TestForkSavedWorkflowTools/RejectsBadInput: schema mismatch, unknown name, name with script or script_path. No run starts.
  • TestForkSavedWorkflowTools/RestartReadsSavedWorkflow: a fresh chatd on the same database lists and runs the saved workflow.
  • TestForkSavedWorkflowTools/ToolsOnlyRead and TestForkSavedWorkflowsNoWriter: see above.
  • TestForkSavedWorkflowsAuthz: with a real dbauthz store, a member sees their own personal workflows and the shared org one. They cannot load another member's personal workflow or an unshared org one. A user outside the organization sees nothing.

Existing tests now expect 3 workflow tools.

golangci-lint run --fix=false ./coderd/x/chatd/ reports nothing in the changed lines. The remaining reports in fork_workflow.go are on lines this PR does not touch.

Not verified

Closes #322

@ibetitsmike

Copy link
Copy Markdown
Owner Author

$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 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-15T19:11:12.082718Z be34553 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.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@ibetitsmike

Copy link
Copy Markdown
Owner Author

$> Coder Agents acted on behalf of @ibetitsmike.\n\n@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: 9c52a202a6

ℹ️ 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_saved_workflows.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@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: 6b85b80be0

ℹ️ 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_saved_workflows.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged -c forward. That brings in main with #335, #339 and #340. The build, the saved workflow tool tests, the workflow tests, the wakeup tests and the route tests pass.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: fc6d128bec

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

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a6982f346a

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

…workflows-c

# Conflicts:
#	coderd/fork_chat_routes.go
#	coderd/fork_saved_workflows.go
#	coderd/fork_saved_workflows_test.go
#	coderd/x/chatd/ARCHITECTURE.md
#	codersdk/fork_saved_workflows.go
Base automatically changed from mike/issue-322-saved-workflows-c to main November 15, 2026 18:47
…workflows-d

# Conflicts:
#	coderd/fork_saved_workflows.go
#	coderd/fork_saved_workflows_test.go
#	coderd/x/chatd/ARCHITECTURE.md
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: be3455391c

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

@ibetitsmike
ibetitsmike merged commit 05bc672 into main Nov 15, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-322-saved-workflows-d branch November 15, 2026 19:34
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged as 05bc672 (squash, --match-head-commit be3455391c5000cb857c47fb0c1674b2980b37e6). Its parent is 895036c, the main I verified.

Gates on head be34553, checked by script right before the merge:

  1. Head and main (895036c) equal the SHAs I verified.
  2. All check runs on the head passed. fork-ci run 43749000470 succeeded on this exact head.
  3. Codex receipt on be34553: "Didn't find any major issues".
  4. No unresolved review threads.
  5. Not behind main.
  6. Independent Opus review on this exact head: merge OK, no P1 or P2. It confirmed saved workflows are read as the chat owner through dbauthz, personal wins over org on a name collision, and the script is journaled at run start. Commands it ran, all PASS: go test ./coderd/x/chatd/ -run 'TestForkWorkflow|TestForkSavedWorkflow', go test ./coderd/ -run 'TestForkUserSavedWorkflows|TestForkOrganizationSavedWorkflows', go test ./coderd/database/dbauthz/ -run SavedWorkflow, go vet ./coderd/x/chatd/ ./coderd/. P3 items go to a follow-up issue.

The previous deploy (895036c) was live before this merge. Not exercised: run_workflow name=... and list_workflows in a live chat on the running server, make lint and the full package suites.

ibetitsmike added a commit that referenced this pull request Nov 15, 2026
Main gained the list_workflows tool (#338), so forkWorkflowTools now
returns three tools; the journal tests assert the new layout.
ibetitsmike added a commit that referenced this pull request Nov 16, 2026
* feat(chatd): journal workflow run args, step reuse and live logs

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.

* fix(chatd): address the review of the workflow run journal

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.

* fix(chatd): serialize the workflow log flush and flag-only step reuse

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.

* fix(chatd): recover dropped log flushes and de-duplicate replayed logs

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.

* fix: regenerate the API artifacts with the server's cancelled spelling

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.

* fix(chatd): order and serialize the journal log writes

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.

* chore: regen forkdb models comment for the logs column

* fix(coderd): decode the live-log envelope in the run detail route

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.

* chore: merge origin/main and fix the workflow tools count in tests

Main gained the list_workflows tool (#338), so forkWorkflowTools now
returns three tools; the journal tests assert the new layout.

* fix: cover the capped-tail replay through the new server, document live 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.

* fix(chatd): keep the journal tail while a capped run replays

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.

* chore: retrigger fork-ci

* chore: order the fork nodes in sqlc.yaml by graph order

* fix(chatd): make the restart log test wait for the paced flush

The test asserted that the restart keeps the third line, but the paced
write of that line lands within the flush interval, so a fast runner
restarted the run before the write and the line was never journaled.
The test now waits for the paced write before the restart.

* fix(chatd): land the terminal log flush and prune the run-list columns

Round-2 review fixes on the workflow run journal.

A terminal flush now waits for an in-flight writer instead of dropping
its write, and a paced flush never re-arms after the run ended. A stopped
run journals the failure log lines of its open steps, so the run detail
reads them from the journal column. A step without an explicit title
keeps the fallback title of its prompt instead of an empty string, which
is what the failure line names.

The rehydrate of a capped run starts its counters at the sequence the
journal payload carries, so the next write lands past the stored
sequence instead of behind it.

The run-list query no longer reads the logs, args and result columns,
which the list never used and logs alone can hold per row.

* test(chatd): give the terminal flush test a fresh context

Waiting for the first journal line can take most of the sub-test
WaitLong budget on a slow CI runner, which left the post-stop checks
with an already expired context. Reacquire the context after the
first journal line so the stop and the final poll get their own
budget.

* Revert "fix(chatd): land the terminal log flush and prune the run-list columns"

This reverts commit 8811be5.

* fix(chatd): land the terminal log flush and prune the run-list columns

Round-2 review fixes on the workflow run journal.

A terminal flush now waits for an in-flight writer instead of dropping
its write, and a paced flush never re-arms after the run ended. A stopped
run journals the failure log lines of its open steps, so the run detail
reads them from the journal column. A step without an explicit title
keeps the fallback title of its prompt instead of an empty string, which
is what the failure line names.

The rehydrate of a capped run starts its counters at the sequence the
journal payload carries, so the next write lands past the stored
sequence instead of behind it.

The run-list query no longer reads the logs, args and result columns,
which the list never used and logs alone can hold per row.

* fix(chatd): keep the original spelling and imports the terminal flush commit touched

* fix(chatd): keep the reused flag, dedupe replayed logs and stop dup failure lines

Review fixes on the run detail work:

- UpdateWorkflowStep ORs the reused flag so a workflow_report from a
  step a resume reused does not clear the flag.
- The replay echo suppression skips unmatched baseline lines instead of
  counting misses, so a baseline that holds a failure line the replay
  never prints again does not swallow live lines after it.
- finish logs only the failure lines of the steps the stop failed, so a
  stop after a step already failed does not log the line twice.
- A no-op resume of a terminal run does not journal reused.
- A flush that lost the lock race does not re-arm over a pending timer.

* fix(chatd): bound the paced log flush write with a timeout

The flush write is best effort and ran on an unbounded background
context, so a stalled journal write could outlive the run and the
server close. A five second timeout bounds each write; the terminal
flush of finish already waits for an in-flight writer, so the final
lines still land.

* test(chatd): cover the reused flag, the baseline skip and the stop lines

Regression tests for the review fixes: a late report of a reused step
keeps the flag, a replay whose baseline holds a failure line skips the
unmatched lines, and a stop after a failed step logs no failure line
twice. The runs end through stop_workflow instead of awaiting, which a
passive fixture never reaches, and the reused-flag test reports through
the recovered child of an interrupted run.

* fix(chatd): explain the nolints the review fixes introduced

The unexported result field keeps its json tag for the serializer, and
flushLogs keeps its terminal flag, so both carry a nolint with the
reason instead of a lint failure.

* fix(chatd): echo by count, journal-only stop logs, review fixes

Review fixes for the workflow run detail PR:

- The replay echo suppresses by count, not by content: rehydrated as
  max(fork_seq, len(baseline)), so a capped tail whose prefix repeats
  keeps one copy of every line. A journaled failed step re-emits its
  failure line during the replay, which keeps the count aligned.
- stopJournaledRun journals a snapshot whose logs come from the row's
  live column, and terminalWorkflowRun fills the same logs when the row
  carries no result, so await and the run detail read the history of a
  journal-only stop.
- The terminal flush runs before done closes, and the journal sequence
  and last-flush time advance only after the write landed, so a failed
  write retries instead of going silent. A run without a journal log
  channel skips the flush schedule.
- The interrupted steps field drops its json tag, the dead journal
  write-done channel goes away, and the SetWorkflowRunLogs comment
  names maxWorkflowLogs (sqlc regen included).
- apitypings maps the raw JSON fields of the run detail to unknown
  instead of Record<string, string>, and typesGenerated regenerates.
- Tests: capped replay with a repeated prefix, identical failure lines
  across a resume, a journal-only stop that carries logs, and the
  terminal flush test now waits for the step row before the stop.

* fix(chatd): keep the reuse flag on orphan reports and rearm from the timer

Two review fixes:

- workflow_report.accept carries the loaded row's reuse flag into the
  journal update, so a report on an interrupted run that a resume
  already replayed cannot clear the durable reused state.
- The timer flush re-arms after its write: lines that landed while the
  write was in flight dropped their own request, and the re-arm had
  only guarded the immediate flush. rearmLogFlush compares the
  sequence, so a re-arm for lines the write already carried is a
  no-op.

* fix(chatd): stop the log rearm spin, bound the stop wait, move the workflow typings mutation

The token holder rescheduled the flush timer forever while it held the token without an in-flight write: lastLogFlush now stamps before the write and both re-arm sites gate on an attempted write, with a regression test counting the observations under a held token. The stop test now asserts a bounded return instead of hanging the test binary. WorkflowRunRawJSON moved to a fork file and fails loudly when the workflow types vanish from a codersdk-sized generation.

* fix(forkdb): read the phase columns in the run-list query

The merge kept the pruned run-list SELECT but the list item reads the phase rail, so sqlc dropped the two columns and coderd did not build. The list still reads no logs, args or result.

* style: gofmt the merged runWorkflowResult struct

* fix(chatdmig): order the run-detail node after the phases node

The run-detail node and the merged phases node both added columns to workflow_runs and workflow_steps with no ordering between them, so an upgraded database kept a different column order than a fresh one and TestUpgradeMatchesFresh failed. The run-detail node was never applied on a shared database, so it is replaced by a freshly generated node that requires the phases node, in graph order in sqlc.yaml. The backfill test follows the new node name.

* fix(chatd): arm a paced fallback for a dropped flush attempt

The immediate-goroutine path in scheduleLogFlush can have its attempt
dropped, which left no timer armed and stalled journal writes until the
next log. Add armLogFlushTimerLocked and use it in the dropped branch so
the pending flush is retried at the next interval boundary.

Also backdate lastLogFlush in HeldTokenDoesNotSpin so the test actually
exposes the spin it guards against, and bound the observer goroutine so
a held token cannot delay the stop path.

* fix(chatd): keep the journaled step title, re-arm the dropped fallback, count flush attempts, and bypass echo suppression for engine lines

Four review fixes:

- The journaled step title comes from the child chat again, like main:
  stepTitle(spec) lost the hook-rewritten and trimmed titles that
  createChildSubagentChatWithOptions applies before it persists the
  child. stepTitle had no other caller and is gone.
- A fallback timer that fires into a still held write token stamps its
  attempt and arms one more paced timer, instead of leaving the lines
  unjournaled until the next log() or the end of the run. Each re-arm
  paces to the interval, so it cannot spin on the holder.
- The pacing tests count flushAttempts, the counter the flush path
  advances on every attempt, instead of sampling logFlushInFlight,
  which a poll can miss entirely.
- The engine's own failure lines, a stop or a failed step, bypass the
  replay echo suppression: a replayed script cannot print them again,
  so a stop racing the replay must not lose them to the count.

* fix(chatd): make the engine log bypass real, bound the fallback re-arm 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.

* fix(chatd): pace the fallback timer write, rearm on every completed flush 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.

* fix(chatd): make the pacing tests load-bearing, untype the args schema 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.

* fix(chatdmig): restore the run-timestamps node bytes

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.

* fix(workflows): omit null result key, keep Args and Result as any

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.

* fix(workflows): round 8 review fixes

- 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.

* fix(workflows): round 9 review fixes

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.

* fix(workflows): drop unrelated churn from round 9

Restore the files a lint run reformatted to their round 8 content and
keep only the pacing comment fix. No lint flag was used.

* fix(workflows): round 10 review fixes

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.
ibetitsmike added a commit that referenced this pull request Nov 17, 2026
* fix(chatd): saved workflow polish from the #338 review

Reword the list_workflows description so it is true for org admins and
auditors, fix the validateSavedWorkflowArgs comment and say "args" in
the args-path out-of-range number error, mention "name" in the script
field description and the empty-input error, reject hidden characters in
saved workflow descriptions with the phase-name rule, cap run args at
64 KiB like the script, and document the phase-name Cf rule and the args
cap in ARCHITECTURE.md.

Tests: a description with a bidi or zero-width character is rejected on
create and update, args over 64 KiB are rejected for inline and named
runs, a resume after an edit or delete of the saved workflow replays the
journaled script, and an org admin subject sees a private organization
workflow in list_workflows while a plain member does not.

* fix(chatd): apply the workflow args cap only to fresh runs

The cap ran before the journal lookup, so a journaled run with larger
args from an older version could not replay after a restart. Move the
check after the journal lookup and drop the stale comment claim that a
resumed run passes through it.

* fix(coderd): allow line breaks and tabs in saved workflow descriptions

The description check reused the phase-name rule, which rejects every
control character, so a multi-line description with a newline or tab
got 400 where main accepted it. Add chatd.ValidateWorkflowDescription,
which keeps the phase-name rule but allows \\n, \\r and \\t, and use it
for the create and update paths.

Also fix two review gaps: list_workflows lists the organization
workflows that the owner can read, not the ones shared with the owner,
and the script_path description mentions name.

* chore: regenerate api docs and mise.lock after the upstream sync merge

make gen on the merge commit reorders the fork experiment keys in the
generated swagger to the order codersdk declares them and refreshes
mise.lock for the pnpm platforms the lockfile tool now records.

* chore: restore mise.lock to main

The mise.lock hunk in the regeneration commit came from installing helm
through mise in this workspace, not from make gen. Revert it.
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.

coderd, chatd: saved workflows resource and run_workflow by name

1 participant