Repository navigation
fix(hopper): let failed one-shot commands exit while retaining a lease - #1763
Conversation
A Hopper target lease retained after unconfirmed cleanup kept its listening socket referenced, so a one-shot CLI emitted its final cleanup_incomplete result but never exited, and its live lease rejected every retry for the same target as already open. Unreference the lease listener. A live MCP process still holds the lease for as long as it runs; a completed CLI exits with status 1, and the stale socket it leaves is recovered by the next acquirer. Fixes #1751 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 610bccb7ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (const name of await listLeases()) | ||
| if (!leasesBefore.has(name)) | ||
| await rm(join(HOPPER_TARGET_LEASE_DIRECTORY, name), { | ||
| force: true, | ||
| }); |
There was a problem hiding this comment.
Scope teardown to this test's lease
When another REA process creates a Hopper lease after leasesBefore is captured (including a concurrent test), this teardown treats its name as this test’s and unlinks its live socket from the shared per-user lease directory. That removes the mutual-exclusion path while its owner is still running, so a later REA process can open the same target concurrently; record and remove only the socket for this test's target.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e11d131. The teardown still considers only sockets created during the test, but now removes one only when it refuses connections (its owner exited). It holds the same <socket>.recovery reservation that production stale recovery uses, so a live lease, or one another acquirer is recovering, is left untouched.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e11d13130d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // The lease lives exactly as long as its owning process. A lease retained | ||
| // after unconfirmed cleanup must not keep a completed one-shot command | ||
| // alive; process exit leaves a stale socket that later acquirers recover. | ||
| server.unref(); |
There was a problem hiding this comment.
Keep the lease alive after unconfirmed cleanup
When a one-shot command reaches the retained-cleanup path, HopperCleanup deliberately keeps launch unless both process stop and document shutdown are confirmed. Unrefing this listener lets the CLI exit normally, which closes and unlinks the Unix socket; the next invocation therefore finds no lock and can open the same target while the prior Hopper document/process remains unconfirmed. Use a process-independent reservation (or keep the owner alive) until cleanup is verified.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The target lease never gave protection after its owner exits. It is scoped to the owning process by design: acquireLease treats a socket whose owner is gone as stale and reclaims it ("recovers a socket left by a process that exited without releasing it" in HopperTargetLease.test.ts). So on main, a retained lease already ends when the CLI is killed, crashes, or gets a signal. In the failed one-shot path, the only thing that kept it "alive" was the process never exiting. The issue's reporter, and any agent or script with a timeout, ends up killing that process anyway, and the target is reopenable afterward either way.
What this PR keeps:
- A live MCP process still holds a retained lease until a cleanup retry succeeds, and still refuses competing opens.
- The one-shot result still reports
cleanup_incomplete, the unconfirmedhopper-document, and the retained runtime root (with itsownership.json), so the caller is told what to inspect.
A reservation that outlives the process and blocks reopening until a later run proves the old document closed would be a new mechanism. It would need its own verified recovery path. Otherwise every launch denial would lock the target until someone removes it by hand, which conflicts with the issue's restoration check that a corrected retry must succeed. I'd prefer to leave that to a follow-up design if maintainers want it, rather than keep the indefinite hang.
Fixes #1751.
Problem
When Hopper startup fails and cleanup cannot be confirmed (for example, the launcher helper exits
2with an Automation denial), REA keeps the target lease as it should. But the lease'snet.Serverlistener stayed referenced. Sorea analyze ... --provider hopperprinted its finalcleanup_incompleteJSON and then never exited. While that process stayed alive, every retry on the same target got "already open in REA session …".Change
tryAcquireLeasenow callsunref()on the lease listener. The lease still lasts exactly as long as its owning process:1and still reportscleanup_incomplete, the retained runtime root, and the launcher diagnostics.No document ownership check is weakened, and nothing extra is closed or killed.
Validation
main. The CLI printed its failure and hung until the 40s alarm (exit 142). With the fix, it exits1with the same structured failure.tests/boundary/cli/hopperLaunchFailureCli.test.tsruns the compiled CLI twice against the same target with a failing launcher. Each run must exit1within 30s with the launcher diagnostics, and the retry must not be rejected as already open. It fails onmain(deadline exceeded) and passes with the fix (~2s). It is skipped off macOS, where no target lease is taken on this route.npm run test:focused -- tests/boundary/providers/hopper/*.test.ts tests/composition/analysis-sessions/binarySessionCleanupRetry.test.tspasses (137 passed, 2 skipped). This includes the retained-lease cleanup-retry coverage.npm run check:fastpasses.Not verified: a real Hopper installation (none on this machine) and the Linux demo application lease route.
🤖 Generated with Claude Code