Repository navigation
feat(chatd): give workflow runs an owner and a heartbeat - #379
Conversation
A journaled workflow run now names the chatd process that executes it (owner_id, the chatd worker ID) and carries its heartbeat. The startup sweep and every heartbeat tick interrupt only runs whose heartbeat went stale, so a new process leaves the live runs of other processes alone. Close releases the runs of this process at once. Engine journal writes are fenced by the owner, a resume claims the run in one statement, and a stop on a non-owner reaches the owner through pubsub. Part of #303
@codex review |
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: 429313ae19
ℹ️ 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".
…wnership A failed terminal write keeps the run heartbeating and retries the write, so no sweep reopens a run that ended. A journal read error no longer counts as ownership. A local stop confirms the ownership first and goes to the new owner when the run moved. Resumes of one run on one process serialize from the claim to the registry.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5a8f2a062
ℹ️ 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".
…ed copies A stop that finds a run's row owned by this process while the registry is empty now takes the resume lock, so it stops the run a resume registers instead of journaling a stop under it. An ended run whose row another process claimed leaves the registry. The journal snapshot of a run that another process executes keeps the reuse flag of its rows.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82bde3b6ef
ℹ️ 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: 410aa627ab
ℹ️ 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 |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 980a5872fc
ℹ️ 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".
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c3920d169
ℹ️ 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: 2b09223728
ℹ️ 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: d7b82eba65
ℹ️ 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: d7b82eba65
ℹ️ 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 |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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 at head Gates on this exact head:
Tests I ran on
Review notes:
Not exercised:
|
Part of #303 (part A: run ownership). Part B, the step signal from
workflow_report, follows in a second PR that closes #303.What changed
Behind the existing
fork-workflowsexperiment.workflow_runs.owner_idandheartbeat_at, and a partial indexworkflow_runs_running_idxonheartbeat_atof running rows (built concurrently, outside a transaction). No node already onmainwas edited.api.ID), so there is no new identity scheme. The owner renews the heartbeat of its live runs every 10 s. A running run whose heartbeat is older than 30 s belongs to a dead process.Closereleases the runs this process still owns: after the script goroutines drain it marks theminterruptedat once, so a graceful restart (autodeploy) needs no 30 s wait. After a crash, another process's tick sweeps them within about 40 s. I rejected a "heartbeat older than my start is dead" rule: with live replicas it would interrupt runs they still execute.workflow_reportand the reuse mark stay unfenced.fork_workflow_owner:<owner>. The journaled stop path stays for runs whose owner is gone, claims the run first, and fails the stop when itsstoppedwrite fails.running: the run keeps heartbeating and every tick retries the write, andClosetries once more before it releases. A journal read error no longer counts as ownership. A local stop confirms the ownership first and goes to the new owner when the run moved. Two resumes of one run on one process serialize from the claim to the registry. (Codex review fixes, f5a8f2a.)reserveRun), so a slow resume or journal-only stop of one run does not hold up the others, as on main, and a wait for it ends with the request context. The heartbeat renews every reserved run. (Seventh Codex round, d7b82eb.)coderd/x/chatd/ARCHITECTURE.mdgains a "Fork-workflows run ownership" section.Hook lines in upstream files:
chatd.gopassesworkerIDtoforkInitWorkflowJournaland callsforkCloseWorkflowJournalinClose.Tests run
All with
flock ~/.fork-go.lock, Postgres 16 on 127.0.0.1.go test ./coderd/x/chatd/... -count=1: all 21 packages ok.go test -race ./coderd/x/chatd/ -run TestForkWorkflowOwnership -count=5: ok. New subtests:NewProcessKeepsALiveRun,StaleRunResumesOnAnotherProcess,ConcurrentResumeExecutesOnce,StopFromAnotherProcessReachesTheOwner,HeartbeatNoticesALostRun,CloseReleasesTheRuns, and after the reviewTerminalWriteRetries,StopOnALostRunReachesTheNewOwner,AnEndedRunThatLostItsRowLeavesTheRegistry,StopWaitsForAResumeOfThisProcess,CleanupRetriesAFailedOwnershipCheck,JournaledStopReturnsAFailedWrite,HeartbeatRenewsAClaimWhileItRehydrates,HeartbeatRenewsAClaimWhileAJournaledStopRuns,ReservationOfOneRunLeavesOthersAlone(-race -count=2 -run 'Workflow|Waker', ok). No sleeps; the timing tests use a quartz mock clock.go test -race ./coderd/x/chatd/ -run Workflow -count=1: ok.go test ./coderd/database/... -count=1: ok exceptTestPubsub_Disconnect, which needs Docker (dial unix /var/run/docker.sock), not present in this workspace.CHATDMIG_TEST_DATABASE_URL=... go test ./coderd/database/migrations/chatdmig/... -count=1: ok.chatdmig check: ok.go test ./coderd/ -run TestForkWorkflowRunsRoutes -count=1 -v: 7 PASS.TestWorkflowRunSweepPlan(forkdb): runsEXPLAIN (FORMAT JSON)of the sweep over 10000 rows, 1% running, afterANALYZE, and asserts the plan usesworkflow_runs_running_idxand no Seq Scan.golangci-lint run --new-from-merge-base=origin/mainon the changed packages: 0 issues. Same with.golangci.new-code.yaml.make lint/emdash lint/architecture lint/markdown lint/migrations: ok.Negative controls:
terminalPendingfromliveRunsfailsTerminalWriteRetries(the peer sweep interrupts the ended run). Skipping the ownership check instopHeldRunfailsStopOnALostRunReachesTheNewOwner.stopOwnerlessRunfailsStopWaitsForAResumeOfThisProcess("the stop went past the resume"); skipping the eviction inrecheckOwnershipfailsAnEndedRunThatLostItsRowLeavesTheRegistry; the old hardcodedReused: truefailsNewProcessKeepsALiveRun.confirmOwnershiponce ininterruptOpenStepsagain failsCleanupRetriesAFailedOwnershipCheck(the retry timer is never created).updateRunStatuscall instopJournaledRunfailsJournaledStopReturnsAFailedWrite("An error is expected but got nil").HeartbeatRenewsAClaimWhileItRehydrates(expected "running", actual "interrupted").stopOwnerlessRunfailsHeartbeatRenewsAClaimWhileAJournaledStopRuns(expected "running", actual "interrupted").ReservationOfOneRunLeavesOthersAlone(RequireReceive: context expired).UpdateWorkflowRunStatusinto a no-op failsStaleRunResumesOnAnotherProcess("the old owner's terminal write is fenced", "the fenced write left the new owner's row").Not verified
Serverinstances on one test database.await_workflowon a non-owner returns the journal snapshot at once instead of waiting, and a runner can send one step reminder before its next heartbeat notices it lost the run.