Skip to content

fix(hopper): name the unconfirmed shutdown step in retained cleanup - #10594

Merged
morluto merged 3 commits into
mainfrom
fix/hopper-cleanup-names-unconfirmed-exit
Nov 14, 2026
Merged

morluto merged 3 commits into
mainfrom
fix/hopper-cleanup-names-unconfirmed-exit

Conversation

@morluto

@morluto morluto commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

Refs #10556. When close_binary keeps a Hopper document, the cleanup diagnostics now say why document shutdown was not confirmed. They record whether the shutdown request was sent, what it returned, and what the final exit check saw for the authenticated application. The flaky handshake-recovery test now asserts the projected error, so the next Linux CI failure prints those facts in the job log.

This PR does not claim to fix the flake. I could not reproduce it, and I am not shipping a speculative timing change.

Problem and expected behavior

tests/boundary/providers/hopper/hopperClient.handshakeRecovery.test.ts > "recovers an application exit after the first valid handshake occurs during cleanup" fails intermittently on Linux CI. client.close() returns ProviderCleanupError ("Provider hopper adapter failed during close_binary"). It has failed on both close sites: :288 after the cleanup handshake and :315 after the restart.

The job log shows only the message. The retained diagnostics are in the vitest blob reports, and I decoded them for four failures:

Run Shard Test line Decoded diagnostics
43595781705 (main 2caa259) 8/12 315 hopper-document "authenticated shutdown acknowledgement was not observed" + runtime root "Private runtime retained because process or native document closure was not confirmed"; authenticated_application: "readable"
43591101342 (PR) 10/12 288 same
43603926315 (PR) 11/12 315 same
43605482884 (PR #10551) 2/12 288 same error in the log; blob not available (the job was rerun)

The "Portable tests" job only merges shard reports, so it repeats these failures rather than adding new ones.

So the identity was readable, and both issues come from resources.shutdownConfirmed staying false: recordUnconfirmedDocument (HopperCleanup.ts:334) and the runtime-root retention branch (HopperCleanup.ts:110). In this fixture (exit-without-ack), only confirmExternalApplicationExit after the shutdown request (HopperCleanup.ts:103) can set it. That means one of three things happened, and the current diagnostics cannot say which:

  1. The shutdown request was never sent (no transport, transport closed, or an active request).
  2. The request failed for a reason other than the fixture exiting.
  3. The request failed at the fixture's EOF, but the exit check still saw the application as present or unverified.

Expected behavior: a retained-document cleanup error names the step that failed.

Change and scope

  • src/hopper/HopperCleanup.ts: CleanupState records shutdownRequest and applicationExit. When hopper-document is retained, the details also include:

    • shutdown_request: one of
      • { method, status: "confirmed" | "unconfirmed" | "failed", error_tag?, provider_state? }
      • { status: "not_sent", reason: "no_bridge_transport" | "bridge_transport_closed" | "bridge_operation_active" | "shutdown_already_confirmed" }
    • application_exit: "exiting" | "present" | "unverified"

    confirmExternalApplicationExit now returns its observation instead of void. Cause messages are not copied into the details; only tags and states are.

  • src/process/ProcessOwnershipObservation.ts: observeProcessStartIdentityExit reports a positively observed Linux exit in progress (PF_EXITING before state Z) as "exiting" instead of "present". It still does not confirm exit, and the only consumer (confirmExternalApplicationExit) treats every non-"exited" result as unconfirmed, so behavior does not change. This separates the "kernel exit window" hypothesis from "application still running" on the next failure.

  • hopperClient.handshakeRecovery.test.ts: both close sites assert projectAnalysisError(...) is null instead of rethrowing the error. A failure now prints the full diagnostics diff.

Not included: no timeout, retry, or settle loop. The obvious candidate fix (wait for an observed exiting identity to reach Z) is not backed by evidence yet; see "Evidence".

Contribution scope: not applicable (diagnostics within the existing Hopper cleanup boundary; no new authority or side effects).

Contract and boundary impact

  • Semantic owner and earliest changed stage: cleanupHopperSession (HopperCleanup.ts) owns the retained-cleanup facts. observeProcessStartIdentityExit owns the exit observation. The only consumer of the new value is HopperCleanup.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: additive fields in cleanup_incomplete diagnostics for a retained Hopper document. The error code, resources, and remediation are unchanged. No schema change.
  • Provider, bridge, target-format, or platform compatibility: none. "exiting" can only be observed on Linux, where procfs reports PF_EXITING.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): cleanup decisions are unchanged. Every non-exited observation still retains the document and runtime root.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/hopper/HopperCleanup.test.ts: a new test uses the test process's own real start identity (a live application) and a failed shutdown_document request. It asserts shutdown_request { method: "shutdown_document", status: "failed", error_tag: "HopperProcessError", provider_state: "unreachable" } and application_exit: "present". On the base revision it would fail because neither field exists. The "does not confirm" case now also covers exiting.
    • src/process/ProcessStartIdentity.test.ts: a readable, matching identity with lifecycle exiting maps to "exiting".
  • Base reproduction or other evidence (executed, Docker node:24.22.1-bookworm-slim, kernel 6.12.54-linuxkit, --cpus=4):
    • With temporary instrumentation (not committed) logging each cleanup step, the target test passed 30/30 runs under 8 CPU-bound processes. Twelve concurrent copies per vitest run passed 10/10 runs (120 instances), then 40/40 runs (480 instances) with continuous background process churn (load average around 25 to 43 on 4 CPUs). In the runs whose logs I inspected, shutdown_document failed with HopperProcessError / unreachable, and the exit check after shutdown found the fixture already reaped (exited).
    • A standalone probe read /proc/<pid>/stat right after the peer socket closed because the peer called process.exit(0) (the fixture's exit-without-ack path). It never saw a non-zombie or PF_EXITING state: idle {ENOENT: 299, ESRCH: 1}; 24 CPU hogs on 2 CPUs {ENOENT/ESRCH: 1423, Z: 77} (every ESRCH followed by kill(pid, 0) = ESRCH); synchronous read on end under --cpus=0.2 {Z: 300}. That evidence argues against the PF_EXITING window being the cause in this environment. It does not rule it out on the CI kernel (Ubuntu 26.04 runner image).
  • User-visible CLI/MCP output (if applicable): a retained-document cleanup_incomplete now also carries, for example, "shutdown_request": {"method": "shutdown_document", "status": "failed", "error_tag": "HopperProcessError", "provider_state": "unreachable"}, "application_exit": "present".
  • Remaining proof gaps: root cause not established; the flake was not reproduced. The next CI failure's log will show which of the three cases above happened.

Lifecycle regressions: this changes diagnostics only. Cleanup ordering, retention, and retry are unchanged and still covered by the existing Hopper cleanup, cleanupRetry, externalExit, and handshakeRecovery suites.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/hopper/HopperCleanup.test.ts src/process/ProcessStartIdentity.test.ts: 2 files, 29 tests passed
  • npm run test:focused -- <all 35 tests/boundary/providers/hopper/*.test.ts> tests/boundary/cli/hopperLaunchFailureCli.test.ts src/hopper/HopperCleanup.test.ts src/process/ProcessStartIdentity.test.ts: 36 files passed, 1 failed. The failure is hopperLaunchFailureCli.test.ts > "exits after a retained-cleanup failure and releases the target to a retry" (recovered.acquired false). It fails identically on the base revision on this macOS host and is darwin-only, so it is unrelated to this change.
  • npm run test:focused -- tests/boundary/providers/hopper/hopperClient.handshakeRecovery.test.ts ...cleanup/cleanupRetry/externalExit...: 6 files, 55 tests passed
  • npx oxfmt --check on changed files: passed
  • npm run check:fast: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The diagnostics fields are additive.
  • Real Hopper/Ghidra, browser, or OS coverage: no real Hopper. macOS local runs and Linux Docker runs only, as above.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the new fields carry only error tags, provider states, and fixed reason codes. No cause text, paths, or tokens.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

When close_binary retains a Hopper document, the cleanup error lists the
retained resources but not why shutdown went unconfirmed. On Linux CI,
hopperClient.handshakeRecovery "recovers an application exit after the
first valid handshake occurs during cleanup" fails intermittently. The
vitest blob reports show only hopper-document and the runtime root
retained with authenticated_application "readable". From those facts we
cannot tell whether the shutdown request was not sent, failed, or was
sent while the application was still observed as present.

Record the shutdown request outcome (method, status, error tag and
provider state, or why it was not sent) and the final exit observation
of the authenticated application in the retained-document diagnostics.
Exit observation now reports a positively observed Linux exit in
progress (PF_EXITING before state Z) as "exiting", separate from
"present". Neither confirms exit. The flaky test asserts the projected
error, so a later failure prints these diagnostics in the CI log.

Refs #10556
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T18:40:13.128596Z e1db5b7 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.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Adds shutdown-request and application-exit facts to retained Hopper cleanup errors.

  • Retained Hopper cleanup errors show which shutdown step was not confirmed.

Reviews (4) · Last reviewed commit: "test(hopper): retry cleanup after confir..." · Reviewed by Greptile

Comment thread src/hopper/HopperCleanup.ts Resolved
Comment thread src/hopper/HopperCleanup.test.ts Resolved
@morluto
morluto merged commit e939cd0 into main Nov 14, 2026
52 checks passed
@morluto
morluto deleted the fix/hopper-cleanup-names-unconfirmed-exit branch November 14, 2026 19:34
Davmunrey added a commit to Davmunrey/rea that referenced this pull request Nov 14, 2026
morluto#10594 added an "exiting" result to observeProcessStartIdentityExit.
This branch now waits through the shared exit settlement first, so
"exiting" names an exit in progress that outlasted the cleanup grace.
The never-settling test now expects "exiting" after more than one read.
@morluto morluto added bug Something isn't working provider: hopper Analysis provider / engine: hopper labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: hopper Analysis provider / engine: hopper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant