Conversation
An exiting T3 worker stopped its server first and removed daemon.json and its lock last. In between, /health failed while the registry still named a live pid: status read "not running" over a file that was still there (the connected-session flake at line 172), and a command arriving then started a worker that found the lock held by a silent live pid and refused to start. cleanup now removes the lock, then daemon.json (only while it is still this worker's), and only then stops the timer, reviews, bridge, server and client. The connected-session test checks the same contract after an explicit stop, and the compiled-installer test gets an explicit 30 s limit (it timed out at 6.4 s against bun's 5 s default in CI).
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the recurring "T3 daemon.json race" in the "OpenCode 2 installed package" job, plus the 5 s timeout of the compiled-installer test beside it.
Root cause: product
When a T3 worker exits (idle exit,
/stop, SIGTERM/SIGINT),cleanupstopped the HTTP server first and removeddaemon.jsonand therunninglock last:Between
server.stop(true)and the twormSynccalls,/healthfails whiledaemon.jsonstill names a live pid. In that window:daemonStatusreportsrunning: falseover a registry that is still there (what the test caught at line 172).ensureDaemonfinds the registry unhealthy and spawns a worker, whoseserveDaemonfinds the lock held by a pid that is alive but no longer answers and refuses with "A T3 companion is still starting or unresponsive". The command then fails with "T3 companion failed to start".The idle-exit code even says "Unregister first, so a command arriving now starts a fresh worker", but the code did not.
Seen locally with a probe in the test: at the moment status read "not running", the worker's pid was alive, its log already said "No open reviews for 4s; the T3 companion … exits", and
daemon.jsonwas gone 500 ms later.Fix
packages/t3-code/daemon.ts:cleanupnow unregisters before anything stops answering:runninglock (first, so this worker can never remove a lock a new worker has just taken),daemon.json, only while it still holds this worker's token,So once a worker stops answering, its registry is already gone, and a command arriving during the exit starts a fresh worker instead of failing.
Tests
connected-session.test.ts: the same "not running implies nodaemon.json" check is added after the explicit/stoptoo (the earlier step), so both exit paths are guarded.install-hook.test.ts: "the compiled installer helper registers an executable hook…" starts the compiled binary five times; it timed out at 6.4 s against bun's 5 s default on a loaded runner (run 38618833740, attempt 1). It now has an explicit 30 s limit.Proof
connected-session.test.tsagainst the compiled binary (bun build … --compilewith the release flags), each run in its own tempHOMEandPLANNOTATOR_DATA_DIR,PLANNOTATOR_BROWSER=/usr/bin/true,PLANNOTATOR_INBOX_CONNECT=0. "Before" is a binary compiled fromorigin/main, "after" one from this branch; both use this branch's test. macOS, 18 cores.Without the new post-stop assertion, the original line-172 check failed 1 in 7 unloaded and 1 in 48 under load on
main.Not caused by this race: in one loaded "before" round three parallel runs stalled for about 16 minutes (the machine slept), and in another round three runs waited past
eventually's 15 s for the review decision. Neither repeated in the 60 loaded "after" runs.bun test packages/t3-codewithT3_TEST_EXECUTABLEset passes, andtsc --noEmitfor the package is clean.