Repository navigation
fix(session): verify retained client liveness on open fast path - #1776
Conversation
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: 3b5b927492
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| options: Pick<BinarySessionOpenOptions, "signal" | "snapshot">, | ||
| ): Promise<boolean> { | ||
| try { | ||
| return (await client.execute("health", {}, options)).ok; |
There was a problem hiding this comment.
Revalidate the actual retained provider before fast-pathing
In the production CLI/MCP composition (src/composition/binary.ts:28-35), every route includes auxiliary providers, so selectableRoute wraps the selected deep provider in a CompositeProvider (SessionProviderRouter.ts:117-126); that client's health branch returns ok unconditionally without dispatching to an instantiated child (CompositeProvider.ts:95-107). Consequently, after a Hopper/Ghidra child dies this line still evaluates to true and retains the dead binding; even forwarding health would still miss a dead Ghidra bridge because its health implementation reuses cached start() state while GhidraClient.ping() performs the live request. The direct fake fixture explicitly avoids the production composite, so this needs a production-composed regression and a genuine child-liveness probe.
AGENTS.md reference: AGENTS.md:L44-L44
Useful? React with 👍 / 👎.
BinarySession#open short-circuited on sameTarget && sameProfile without checking the retained provider client was still live. A client torn down out from under the session was silently reused, so open_binary reported success while subsequent operations failed. The fast path now probes the retained child through operationHealthSnapshot, the codebase's child-liveness signal: the production CompositeProvider aggregates it from its instantiated children, and HopperClient reports a recorded process exit through it. A child reporting exited, unreachable, or an uncharacterized failure counts as dead, so the call falls through to the slow path, which retires the dead client and starts a real one. Where no snapshot signal exists, the probe keeps the previous health admission. An aborted caller leaves the session untouched. Fixes morluto#1719.
3b5b927 to
39851cb
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39851cb7c6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return ( | ||
| snapshot.state === "idle" || | ||
| snapshot.state === "busy" || | ||
| snapshot.state === "not_started" |
There was a problem hiding this comment.
Reject
not_started clients from the live fast path
When Hopper startup times out and cleanup remains incomplete, HopperClient.#rememberStartupFailure leaves operationHealth() in not_started (src/hopper/HopperClient.ts:437-450), while the retained resources make the next start() fail until close() retries cleanup (covered in tests/boundary/providers/hopper/hopperClient.cleanupRetry.test.ts:103-117,208-215). Classifying that state as live makes a same-target open_binary return success without entering the retire path, so subsequent analysis still hits the wedged client; let not_started fall through so cleanup is retried before replacement.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
A Hopper startup timeout leaves operationHealth() in not_started while retained resources block the next start() until close() retries cleanup. Classifying that state as live let a same-target open_binary return success without entering the retire path, so subsequent analysis hit the wedged client. Only idle/busy now count as alive; not_started falls through to retire (close runs, cleanup retried) before replacement. Addresses chatgpt-codex-connector P2 on morluto#1776.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a857c29ad
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ): Promise<boolean> { | ||
| const snapshot = client.operationHealthSnapshot?.(); | ||
| if (snapshot !== undefined) | ||
| return snapshot.state === "idle" || snapshot.state === "busy"; |
There was a problem hiding this comment.
Preserve failed startup state through a blocked retry
For a Hopper startup timeout with incomplete cleanup, one intervening analysis retry makes this test incorrectly pass: HopperClient.#start clears #operationFailure before rejecting the retained resources with HopperProtocolError (src/hopper/HopperClient.ts:314-320), and #rememberStartupFailure does not restore that error (:437-450), so operationHealth() reports idle even though another start() is still blocked. The same-target open_binary then fast-paths the wedged client instead of retrying cleanup; preserve the producer's failed-startup state until cleanup succeeds and cover timeout → retry → reopen. Fresh evidence beyond the earlier not_started finding is this retry-induced transition to the accepted idle state.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
A Hopper startup timeout records not_started via #rememberStartupFailure, but #start cleared the record before rejecting retained resources with HopperProtocolError. That error is not a remembered failure type, so operationHealth() reported idle for a client whose next start was still wedged — and a same-target open_binary fast-pathed it instead of retrying cleanup. The record is now cleared only once a fresh attempt actually proceeds. Addresses chatgpt-codex-connector P2 on morluto#1776.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2421a54a98
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // actually proceeds. | ||
| return err(new HopperProtocolError("Hopper client is already started")); | ||
| } | ||
| this.#operationFailure = undefined; |
There was a problem hiding this comment.
Record all retained-resource startup failures
When startup ends in a failure that #rememberStartupFailure does not record (for example, a cancelled startup or an invalid health handshake yielding HopperProtocolError) and cleanup retains a socket, launch, or runtime root, moving the reset here still leaves #operationFailure undefined. operationHealth() consequently reports idle, the production composite forwards that snapshot, and the new same-target fast path returns success even though every subsequent start() remains blocked by Hopper client is already started; record an unknown/not_started producer state for every failed startup that leaves owned resources.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Upstream 069308b independently landed the Hopper-side failure recording (retained-resources guard returns the recorded #startupFailureResult; #rememberStartupFailure fails closed), so the conflict resolution adopts the upstream implementation. The BinarySession liveness probe for morluto#1719 is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea2176b0c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| target, | ||
| options, | ||
| ); | ||
| if (fastPath !== undefined) return fastPath; |
There was a problem hiding this comment.
Preserve records when dead-client cleanup fails
When the retained client reports a dead state and its close() cannot confirm cleanup (for example, Hopper retains a document or runtime), this new fallthrough reaches the existing failure branch at lines 290–293, where clearSessionRecords() erases every accumulated Evidence/Unknown and the analysis snapshot before open_binary returns the cleanup error. A same-target reopen should retain those local records alongside the pending cleanup owner so a provider crash plus cleanup failure does not destroy the investigation.
AGENTS.md reference: AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
| return ok(target); | ||
| const retained = sameTarget && sameProfile ? this.#active : undefined; | ||
| if (retained !== undefined) { | ||
| const fastPath = await this.#tryRetainedFastPath( |
There was a problem hiding this comment.
Recheck cancellation after the liveness await
If the caller aborts after #tryRetainedFastPath performs its internal signal check but before this awaiting continuation resumes (for example, a provider hook schedules the abort in a following promise reaction), there is no post-await check here: a live result is returned as success, while a dead result immediately clears and closes the active binding and only notices cancellation after cleanup. Recheck options.signal at this async boundary before consuming fastPath so a cancelled same-target open neither succeeds nor mutates the session.
AGENTS.md reference: AGENTS.md:L44-L44
Useful? React with 👍 / 👎.
N0zoM1z0
left a comment
There was a problem hiding this comment.
Reviewed exact head ea2176b0c0b8b8ae6e952425c3654e31b5c3800c and its clean merge tree with pinned main d802304c542b20bc86e22cc492718e89a8a5579b.
Actual Linux Hopper 6.4.2 headless stdio MCP reproduced the main-side bug: after terminating only this test's verified Hopper child, same-target open_binary succeeded but its next query still returned provider_unavailable. The integrated PR recovered the query with a new run ID and launcher PID; a subsequent healthy reopen reused the live run. Target bytes were unchanged, close succeeded, old provider roots were removed, and SDK ping still worked.
Fresh runtime/skill artifacts and 11 exact focused-plan files passed 85 tests with one worker. The normal focused artifact-preparation phase exceeded our 1.5 GiB family limit; it was stopped and is not reported as passing. The serial artifact build plus the declared test plan passed separately. All 31 checks on this exact PR head, including CI required, are successful.
The PR description now uses Refs #1719: this verifies Hopper recovery, while the original Ghidra snapshot case and provider liveness hooks are outside this evidence. Ghidra's expected lazy open should not be described as a failure by itself. No blocking code finding remains for the scoped change.
Summary
After an owned Hopper child exits, reopening the same target and analysis profile reported success while subsequent queries continued to fail against the retained client.
open_binarynow retires a retained client reporting a failed operation-health state and creates a fresh provider route. The next query starts the replacement child. A healthy retained client is reused, and an aborted probe leaves the active session intact.Refs #1719. This fixes the reproduced retained-Hopper-client failure. It does not establish a fix for the original Ghidra snapshot report: Ghidra and IDA have no operation-health snapshot hook, so their existing health admission remains the fallback. Ghidra's lazy startup on the first query remains unchanged.
Change and scope
operationHealthSnapshot()from the retained provider before taking the same-target/profile fast path. Onlyidleandbusypermit reuse; recordedexited,unreachable,unknown, and incomplete-startup states trigger the existing retirement path.Validation
ea2176b0c0b8b8ae6e952425c3654e31b5c3800c: all 31 current checks, includingCI required, passed.d802304c542b20bc86e22cc492718e89a8a5579bin a separate review branch. The resulting tree isa7520fd76c947612cc44c8e44e3a753e668692fa.test:focusedartifact-preparation phase exceeded the private 1.5 GiB process-family limit; verification instead built the required artifacts serially and ran the same exact test plan against them. The interrupted preparation is not claimed as a passing command.9a87b653669278120c7c207b7acf5a38e5dfe9a4394b45cd6f5d2e7932443a9b): start and query, terminate only the verified owned Hopper child through a PID-bound kernel handle, observe the transport failure, reopen the same target, query, repeat a healthy open, close, status, and ping.open_binaryfollowed byprovider_unavailable. The integrated fix recovered the query with a fresh run ID and launcher PID; another healthy open retained that run ID. All 13 named tool calls were validated against their output contracts and success text/structured parity.Remaining coverage
The real workflow covers Linux native Hopper child failure and recovery. macOS, saved
.hopdocuments, Ghidra/IDA child-liveness recovery, the reporter's historical Ghidra version/25 MB PE/snapshot, and default-client-deadline behavior remain unverified by this PR. The related broader issues stay open.