Skip to content

test(daemon): rejoin after the daemon drops the closed connection's lease - #80

Merged
yaacovcorcos merged 2 commits into
mainfrom
claude/ci-daemon-rejoin-20261123
Nov 23, 2026
Merged

yaacovcorcos merged 2 commits into
mainfrom
claude/ci-daemon-rejoin-20261123

Conversation

@yaacovcorcos

@yaacovcorcos yaacovcorcos commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the flake that turned main red on 11-22 (run 45051468599) and failed a PR run the same day: daemon unit lifecycle › a client reconnecting within the grace adopts the same process expected leases 1, got 2.

Cause. The test harness's close() settles when the client socket closes, but the daemon drops that connection's lease later, when it handles the close (server.ts #onClose → units.disconnected). When the second client's open was handled first, the stale lease was still counted. The daemon's behaviour is correct (connection-bound lease accounting), so only the test changes.

Fix (test only, new contract SA-DAEMON-REJOIN). Before reopening, the test waits until describe shows the daemon has dropped the lease, the same until() + describe() wait the grace test just above it already uses. The harness is unchanged (Codex review: an earlier version added an event waiter to the upstream harness file, which is logic rather than a small hook).

Proof. With the daemon's close handling delayed by 300 ms, the old test fails exactly as CI did (expected 1, received 2); the new test passes 3/3 with the delay, and the whole lifecycle file passes 5/5 without it (10 tests each). Typecheck, oxlint and oxfmt are clean, and the divergence check passes locally.

Footprint. +1 marker block / +6 lines in 1 Oh My Pi test file. It's an inherited flake, so it needs an upstream fix.

Found in review, not changed here. Pre-existing in Oh My Pi's daemon (units.ts open()): if a client disconnects while its open is still creating the unit, disconnected() runs before open() adds that client's lease, so the lease is never dropped and the unit stays pinned. Separate product fix, upstream first.

Platforms: the test file is skipped on Windows; same behaviour on macOS and Linux.

🤖 Generated with Claude Code

…ease

The reconnect-within-grace test reopened the unit as soon as the first
client's socket closed, but the daemon handles that close later. When the
second open won the race the old lease was still counted (leases 2), which
failed main on 11-22 (run 45051468599) and a PR run the same day.

The test now watches unit events on the second connection and reopens only
after the daemon broadcasts the lease drop, the state the test describes.
The harness's event wait now resolves when the event arrives instead of
polling its buffer every 25 ms. Both changes sit in SA-DAEMON-REJOIN marker
blocks in Oh My Pi's test files.

Proven by delaying the daemon's close handling by 300 ms: the old test fails
exactly as CI did (expected 1, received 2 at line 110), 3/3; the new test
passes with and without the delay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos
yaacovcorcos force-pushed the claude/ci-daemon-rejoin-20261123 branch from 8e50dd2 to 5dc528c Compare November 23, 2026 05:30
…ness unchanged

Codex review: a waiter implementation inside an upstream harness file is
logic, not a small hook. The grace test above already waits for this exact
lease drop with until() and describe(), so the rejoin test reuses it and the
harness is back to Oh My Pi's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos
yaacovcorcos merged commit 206d096 into main Nov 23, 2026
22 checks passed
@yaacovcorcos
yaacovcorcos deleted the claude/ci-daemon-rejoin-20261123 branch November 23, 2026 09:17
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.

1 participant