Repository navigation
fix(chatd): adopt a workflow step another runner journaled, and fix fork-ci flakes - #375
Conversation
The startup sweep marks every open workflow run interrupted, so a run can be resumed while the process that started it still runs the script. Step IDs derive from the run and the step spec, so both runners insert the same workflow_steps key. The later insert failed with a duplicate key and interrupted the other runner's child chat. startStep now adopts the journaled row and replays it like a rehydrated step. Also fix the root causes of the other fork-ci flakes: - TestInTx: each parallel subtest makes its own context. A shared WaitShort context expired while the subtests waited for a slot. - FallbackRearmsWhileTheTokenIsHeld: read the attempt count and the timer under one lock. The timer callback counts the attempt before it re-arms, so separate reads raced the re-arm. - ReplayKeepsACappedTail and ReplayReEmitsAFailureLineOnce: wait for the full journaled state before the restart. - TestPlugins/LinkSendAndDeliver: link a user of its own. Delivery made the unlabeled chat of a parallel subtest the link's active chat. - TestForkChatSecretAnswer(Expired): disable the chat worker. The fake busy chat has no runner, so the worker acquired it and promoted the queued answer before the test deleted it. Closes #373 Closes #353
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. |
Merged at head Gates on this exact head:
Tests I ran on
Review notes: the duplicate key was a product race, not only a test flake. The startup sweep marks every open run interrupted, so a second runner can resume a run while the first still runs its script. Both derive the same step ID. Not exercised: two coderd replicas or a rolling restart against a real database. The |
Fixes the root causes of the fork tests that failed fork-ci on main. No retries, skips, longer sleeps or reruns.
Closes #373
Closes #353
Product race: duplicate
workflow_steps_pkeyThe most common failure:
journal the workflow step: pq: duplicate key value violates unique constraint "workflow_steps_pkey", in 3 subtests across 4 runs (StopLinesBypassTheEchoSuppression among them).The startup sweep
MarkOpenWorkflowRunsInterruptedmarks every open run interrupted. A run can then be resumed while the process that started it still runs the script, for example during a rolling restart, on another replica, or with the two servers of the test. Step IDs derive from the run and the step spec, so both runners insert the same key. The later insert failed, andstartStepalso interrupted the child chat of the other runner.startStepnow adopts the journaled row on that unique violation (adoptJournaledStep). It checks the run ID, rebuilds the step with the helper the rehydrate loop now shares (journaledWorkflowStep), and replays it like a rehydrated step. The child chat keeps running.New subtest
TestForkWorkflowJournal/ResumeAdoptsAStepAnotherRunnerJournaled. Negative control: with the adopt branch disabled it fails with the exact CI error.Test fixes
forkdbTestInTxWaitShortcontext. In CI log 43965522540 they ran about 12s after the parent made it, so it had expired (context canceled,context deadline exceeded).FallbackRearmsWhileTheTokenIsHeldjournalMulock and stop only when both hold.ReplayKeepsACappedTailReplayReEmitsAFailureLineOnceReplaySkipsAnUnmatchedBaselineLine.TestPlugins/LinkSendAndDeliver(#353)ConverseScopeOnlyReachesChatsmakes an unlabeled chat for the shared member, and delivery makes it the idle link's active chat (intended behavior), sosendposts to the chat with label"".TestForkChatSecretAnswer,TestForkChatSecretAnswerExpiredTestForkChatSecretQuestionQueuedMessagealready does.Evidence (all under the workspace Go lock, race builds unless noted)
Negative controls, original code vs fix:
workflow_steps_pkey; fix passes.t.Parallel(), the original failed with all three CI errors; the fix passed.-count=20failed 2/20 withexpected "bridge", actual "".Stress on the fix:
TestForkWorkflowLiveLogs|TestForkWorkflowJournal-count=50 -cpu 1,2: PASS.TestInTx-count=50 -cpu 1,2: PASS.TestPlugins-count=50(default GOMAXPROCS): 50/50 PASS.-run '(?i)chat|skill|mcp|plugin' ./coderd-cpu 4 -count=2: PASS.golangci-lint --new-from-rev origin/mainon the three packages: 0 issues.gofmt -l: clean.Not verified
TestPluginsand thecoderdsecret answer tests cannot run under race at-cpu 1or-cpu 2on this VM, with or without this change. On main,TestPluginsfailed 2/2 at-cpu 1and 6/10 at-cpu 2: the plugin'scoder_on_httphits its 10s limit and the 60s context expires (a chat create took 7.7s, a plugin install 10.3s). At-cpu 1the secret tests time out inCreateFirstUserandcreateChatModel. That is a load limit, separate from these flakes. CI runs without race on 4 vCPUs.TestWakeupPullRequestReadFailures/OtherErrorandPhaseBuiltinsRejectBadNamesfailed only on branches before their merge; main already has the fixes. Not changed.TestRunnerManager_HeartbeatDoesNotReviveStaleLeaseis upstream and already skipped in fork-ci.