Skip to content

fix(session): verify retained client liveness on open fast path - #1776

Merged
N0zoM1z0 merged 6 commits into
morluto:mainfrom
sx4im:fix/open-binary-liveness-check
Oct 11, 2026
Merged

N0zoM1z0 merged 6 commits into
morluto:mainfrom
sx4im:fix/open-binary-liveness-check

Conversation

@sx4im

@sx4im sx4im commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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_binary now 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

  • Read operationHealthSnapshot() from the retained provider before taking the same-target/profile fast path. Only idle and busy permit reuse; recorded exited, unreachable, unknown, and incomplete-startup states trigger the existing retirement path.
  • Preserve cancellation, snapshot import behavior, and the existing cleanup ownership/retry mechanism. No eager provider startup is added.
  • Add production-composed session tests for healthy reuse, dead/unknown/incomplete-startup recovery, health fallback, and cancellation, plus distinct Hopper startup and cleanup-retry health regressions.
  • CLI/MCP input and output shapes, Evidence semantics, advertised schemas, and provider authority are unchanged.

Validation

  • Exact PR head ea2176b0c0b8b8ae6e952425c3654e31b5c3800c: all 31 current checks, including CI required, passed.
  • Integrated with pinned main d802304c542b20bc86e22cc492718e89a8a5579b in a separate review branch. The resulting tree is a7520fd76c947612cc44c8e44e3a753e668692fa.
  • Fresh runtime and packaged-skill build, then the declared focused-test plan's 11 exact files: 85 passed, using one Vitest worker. The default test:focused artifact-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.
  • Actual Linux Hopper 6.4.2 demo, headless private display, official SDK stdio MCP, a 23,264-byte source-owned ELF (SHA-256 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.
  • Baseline main reproduced success from open_binary followed by provider_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.
  • Input bytes remained unchanged, the retired runtime root was absent, and the final provider/runtime directories were empty. The target was not executed. No visible desktop window or unrelated Hopper process was controlled.
  • CPU affinity was limited to two cores. Authentic Flameox V8 launcher artifacts and payload digests were retained; these do not measure child compiler, test-worker, or Hopper CPU hotspots. The real fixed workflow completed in 17.45 seconds without reaching its resource limits.

Remaining coverage

The real workflow covers Linux native Hopper child failure and recovery. macOS, saved .hop documents, 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.

@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-11T16:19:10.733908Z ea2176b 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: 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;

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 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.
@sx4im
sx4im force-pushed the fix/open-binary-liveness-check branch from 3b5b927 to 39851cb Compare October 11, 2026 09:31

@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: 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".

Comment thread src/application/binary/BinarySession.ts Outdated
return (
snapshot.state === "idle" ||
snapshot.state === "busy" ||
snapshot.state === "not_started"

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

@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: 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";

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

@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: 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;

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

sx4im and others added 3 commits October 11, 2026 15:55
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.

@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: 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;

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 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(

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 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 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@N0zoM1z0
N0zoM1z0 merged commit e59db2f into morluto:main Oct 11, 2026
31 checks passed
@morluto morluto mentioned this pull request Oct 13, 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 the area: tests Test suite and verification label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: tests Test suite and verification bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants