Skip to content

fix(daemon): drop a lease whose connection closed while its open waited - #81

Merged
yaacovcorcos merged 1 commit into
mainfrom
claude/daemon-open-lease-20261123
Nov 23, 2026
Merged

yaacovcorcos merged 1 commit into
mainfrom
claude/daemon-open-lease-20261123

Conversation

@yaacovcorcos

Copy link
Copy Markdown
Contributor

Fixes a daemon bug in Oh My Pi that Codex found while reviewing #80. If a client's connection closes while its open is still waiting for the unit to be created (its own creation, or another client's creation of the same unit), UnitTable.open() takes the lease after disconnected() has already run. Nothing ever drops that lease, so the unit stays pinned: it never idles out and keeps running until the daemon exits.

Fix. It is marked as new contract SA-DAEMON-OPEN-LEASE, one marker block in units.ts. Right after #addLease, if the connection is closed, open() drops the lease the way disconnected() would:

  • it sets the reconnect grace;
  • it calls #dropLease, which also runs the module's released() hook;
  • it removes the connection's lease set, which #addLease had recreated.

Upstream. The same change was offered to Oh My Pi as can1357/oh-my-pi#20263. Both the ledger entry and the SCIENT.md row say to realign at the next alignment: retire the contract as upstreamed if Oh My Pi merges #20263, or replace it with Oh My Pi's own fix if they fix it differently.

Proof. The new owned test test/scient/daemon-open-lease.test.ts drives UnitTable in-process with a fake module whose open waits on a gate, so there is no timing dependence.

  • Without the fix both cases fail (leases 1 vs 0, and 2 vs 1). With it they pass.
  • With only the grace line removed, both cases still fail, so the grace is covered.
  • Codex reviewed the upstream version twice. The first round found two problems, both fixed: the leftover lease set, and tests that didn't check the grace.
  • Typecheck, oxlint, oxfmt and the divergence check pass.
  • The daemon suite matches main locally. Three tests fail on this machine without the change too: mutex hint single-flight, the blob URL index, and client convergence.

Footprint. +1 marker block, +10 lines in 1 Oh My Pi file, plus 1 owned test.

Not in this PR. Codex found a similar pre-existing gap in Oh My Pi's LSP module: acquire can reserve a slot after its connection's disconnect hook ran, and the reservation expires after 30 s. That needs its own fix.

Platforms: the daemon code is shared across platforms and the change has no platform branches. The test runs in-process wherever the daemon tests run.

🤖 Generated with Claude Code

UnitTable.open() takes the connection's lease after awaiting the unit's
creation, or another client's creation of the same unit. When the
connection closed in that window, disconnected() had already run without
the lease, so nothing dropped it and the unit stayed pinned. open() now
drops such a lease as disconnected() would, reconnect grace and module
released() hook included, and removes the closed connection's lease set.

New contract SA-DAEMON-OPEN-LEASE, offered to Oh My Pi; realign at the
next alignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos
yaacovcorcos merged commit 1ef96fc into main Nov 23, 2026
22 checks passed
@yaacovcorcos
yaacovcorcos deleted the claude/daemon-open-lease-20261123 branch November 23, 2026 11:44
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