Skip to content

fix(hopper): let failed one-shot commands exit while retaining a lease - #1763

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/hopper-failed-session-exit
Oct 11, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/hopper-failed-session-exit

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Fixes #1751.

Problem

When Hopper startup fails and cleanup cannot be confirmed (for example, the launcher helper exits 2 with an Automation denial), REA keeps the target lease as it should. But the lease's net.Server listener stayed referenced. So rea analyze ... --provider hopper printed its final cleanup_incomplete JSON and then never exited. While that process stayed alive, every retry on the same target got "already open in REA session …".

Change

tryAcquireLease now calls unref() on the lease listener. The lease still lasts exactly as long as its owning process:

  • MCP: a live server still holds the lease, and still refuses competing opens, until cleanup succeeds or the process ends.
  • One-shot CLI: exits with status 1 and still reports cleanup_incomplete, the retained runtime root, and the launcher diagnostics.
  • Next acquirer: recovers the stale socket the exited process leaves behind, using the existing stale-lease recovery path.

No document ownership check is weakened, and nothing extra is closed or killed.

Validation

  • Reproduced the issue's failing-helper scenario on macOS arm64 against main. The CLI printed its failure and hung until the 40s alarm (exit 142). With the fix, it exits 1 with the same structured failure.
  • New tests/boundary/cli/hopperLaunchFailureCli.test.ts runs the compiled CLI twice against the same target with a failing launcher. Each run must exit 1 within 30s with the launcher diagnostics, and the retry must not be rejected as already open. It fails on main (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.ts passes (137 passed, 2 skipped). This includes the retained-lease cleanup-retry coverage.
  • npm run check:fast passes.

Not verified: a real Hopper installation (none on this machine) and the Linux demo application lease route.

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T08:19:31.895652Z e11d131 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +46 to +50
for (const name of await listLeases())
if (!leasesBefore.has(name))
await rm(join(HOPPER_TARGET_LEASE_DIRECTORY, name), {
force: true,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 unconfirmed hopper-document, and the retained runtime root (with its ownership.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.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit e8528ce into main Oct 11, 2026
31 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/hopper-failed-session-exit branch October 11, 2026 08:38
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added area: cli CLI adapter and one-shot commands provider: hopper Analysis provider / engine: hopper labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: hopper Analysis provider / engine: hopper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hopper): failed one-shot analysis stays alive and holds its target lease

2 participants