fix(daemon): avoid duplicate startup work and clean cancellation#67
Merged
Merged
Conversation
This was referenced Jul 12, 2026
Warm the dispatch surface once, keep a timed-out background warmup alive explicitly, and release async-write and lifecycle resources safely when startup cancellation escapes the inner run loop. Designed by Marsu — Refined by Codex. Co-Authored-By: Codex <codex@openai.com>
d829d50 to
a128c5d
Compare
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.
Problem
The daemon warmed the dispatch surface once before binding the socket and then
repeated the same encode inside the remaining boot warm-up. A timeout around
the pre-bind worker also cancelled its asyncio task even though the underlying
thread could not be cancelled, leaving that continuation implicit. Finally,
cancellation escaping the inner run loop could bypass async-write and lifecycle
lock cleanup.
The original regression test also cancelled startup after a fixed 150 ms. Once
the duplicate eager encode was removed, that sleep could expire before the real
pre-bind warm-up ran, producing a false
0 callsfailure on loaded macOSrunners.
Solution
the bounded wait;
guarded by current-process lock ownership;
warm_dispatch_surfacecall instead of sleeping for an arbitrary duration,while always cancelling and awaiting the daemon in
finally.Guarantees and scope
The daemon protocol, socket lifecycle, and normal hibernation policy are
unchanged. The patch removes duplicate startup work and makes cancellation
cleanup explicit. The synchronized test remains red on the previous duplicate
encode path and green only when exactly one dispatch warm-up occurs.
Validation
Designed by Marsu — Refined by Codex.
Public CI result
The amended macOS run confirms that
test_prewarm_called_once_at_bootnow passes. Its remaining 14 failures are all pre-existing baseline failures addressed by the next two stacked PRs: 11 by #68 and the final 3 spatial cases by #69.The cumulative #69 tip is fully green, including the synchronized daemon regression, wheel build, and secret scan.