Skip to content

fix(daemon): avoid duplicate startup work and clean cancellation#67

Merged
CodeAbra merged 1 commit into
CodeAbra:mainfrom
Marsu6996:pr/fix-daemon-startup-cleanup
Jul 13, 2026
Merged

fix(daemon): avoid duplicate startup work and clean cancellation#67
CodeAbra merged 1 commit into
CodeAbra:mainfrom
Marsu6996:pr/fix-daemon-startup-cleanup

Conversation

@Marsu6996

@Marsu6996 Marsu6996 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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 calls failure on loaded macOS
runners.

Solution

  • construct and retain one pre-bind warm-up task, shielding its worker across
    the bounded wait;
  • tell the remaining boot warm-up not to repeat the dispatch encode;
  • keep the warmed embedder without issuing a second eager encode;
  • release async-write state and the lifecycle lock from the outer cleanup path,
    guarded by current-process lock ownership;
  • use the canonical daemon socket override in daemon tests;
  • synchronize the pre-warm regression test on completion of the actual
    warm_dispatch_surface call 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

  • synchronized pre-warm regression: 20/20 repeated isolated runs;
  • daemon, boot warm-up, and async-write cleanup set: 31 passed, 1 skipped;
  • focused socket, cancellation, and watchdog coverage;
  • exhaustive default-suite result recorded on the final stacked tip;
  • adversarial review incorporated the task-lifetime and lock-ownership checks.

Designed by Marsu — Refined by Codex.

Public CI result

The amended macOS run confirms that test_prewarm_called_once_at_boot now 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.

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>
@Marsu6996 Marsu6996 force-pushed the pr/fix-daemon-startup-cleanup branch from d829d50 to a128c5d Compare July 12, 2026 23:32
@CodeAbra CodeAbra marked this pull request as ready for review July 13, 2026 03:09
@CodeAbra CodeAbra merged commit b80535a into CodeAbra:main Jul 13, 2026
1 of 2 checks passed
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.

2 participants