Skip to content

fix(server): admit investigation tools into session lifecycle (#4002) - #4174

Closed
Swatantra-66 wants to merge 1 commit into
morluto:mainfrom
Swatantra-66:fix/close-binary-investigation-lifecycle
Closed

Swatantra-66 wants to merge 1 commit into
morluto:mainfrom
Swatantra-66:fix/close-binary-investigation-lifecycle

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Admit differential investigation workflows into the session analysis lifecycle so that close_binary waits for in-flight requests before clearing retained records, and re-validates source evidence closure prior to publishing derived records.

Fixes #4002

Problem and expected behavior

When differential investigation workflows (build_call_path, find_changed_behavior, correlate_static_and_runtime, verify_reconstruction) were registered directly on the MCP server without session admission (runAdmittedToolOperation / withAdmittedAnalysis), session.#calls was unaware of in-flight work.

If a caller invoked close_binary while an investigation workflow was computing, close_binary immediately proceeded through #drainCalls(), closed the underlying engine, and cleared retained session records (clearSessionRecords()). When the investigation workflow subsequently finished, it minted new derived Evidence referencing previously retained source Evidence IDs and recorded it into the emptied session ledger, resulting in dangling evidence_links.

Expected behavior:

  1. close_binary must wait for in-flight investigation workflows to settle before draining records and closing session engines.
  2. If session records are cleared or drained while an async derivation is in flight, the workflow must fail closed with an EvidenceIntegrityError rather than publishing orphaned records to the ledger.

Change and scope

  • In src/server/registerInvestigationTools.ts:
    • Wrapped find_changed_behavior, build_call_path, correlate_static_and_runtime, and verify_reconstruction with runAdmittedToolOperation(server, admission, contract.name, context.mcpReq.signal, ...).
    • Added post-derivation evidenceClosure(session, links) checks in build_call_path and correlate_static_and_runtime before committing derived evidence via recordWorkflowEvidence.
    • Retained single, non-redundant post-derivation checks in find_changed_behavior and verify_reconstruction.
  • In tests/boundary/mcp/investigationAnalysisMcp.test.ts:
    • Added regression test awaits in-flight call-path derivation before close drains records (#4002) tracking settlement order (build_call_path then close_binary) and validating inline evidence retention before session draining.
    • Added regression test rejects call-path recording when source Evidence is cleared before publishing (#4002) validating that clearing source records before publishing triggers fail-closed EvidenceIntegrityError ("dangling Evidence link") and leaves the ledger clean.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/server/registerInvestigationTools.ts (MCP tool registration boundary).
  • Contribution scope fit and linked maintainer decision: ordinary lifecycle bugfix within existing session boundaries; maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: Unchanged.
  • Provider, bridge, target-format, or platform compatibility: Cross-platform; preserves in-flight concurrency semantics on all supported platforms.
  • Evidence, artifact, provenance, or reconstruction contract: Preserves closure invariants; guarantees all referenced evidence_links exist in the active session ledger when recording.
  • Target selection, authority, upstream behavior, and cleanup details: None.
  • Generated metadata impact: None.

Expected effects:

  • 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:
    • tests/boundary/mcp/investigationAnalysisMcp.test.ts
  • Base reproduction or other evidence:
    • Simulated concurrent close_binary during paused build_call_path and simulated clear before publishing.
  • User-visible CLI/MCP output: MCP tools return valid Evidence before close settles, or return EvidenceIntegrityError if source closure is broken.
  • Remaining proof gaps: None.

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:focused -- tests/boundary/mcp/investigationAnalysisMcp.test.ts — 14/14 tests passed
  • npm run typecheck (tsc --noEmit) — passed (0 errors)
  • npm run lint — passed (0 errors)
  • npm run docs:check — 6/6 build tasks passed; readmeConsistency passed (5/5)

Compatibility, safety, and release

  • Breaking changes or migration steps: None.
  • Real Hopper/Ghidra, browser, or OS coverage: Validated on Windows local environment.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Preserves fail-closed boundary integrity and prevents leaking dangling references.

Author readiness

Human owner: @Swatantra-66

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

…ent dangling records on close

Admit differential investigation workflows (build_call_path, find_changed_behavior, correlate_static_and_runtime, verify_reconstruction) into session analysis via runAdmittedToolOperation. This ensures close_binary drains in-flight workflows before clearing retained records, and re-validates source evidence closure before publishing results.

Fixes morluto#4002
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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 ⚠️ Failed 2026-10-15T16:35:04.482500Z b9ad56d PR opened
ℹ️ 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 Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

The PR brings four investigation tools into the existing session lifecycle.

  • Investigation requests finish before the session clears their evidence.

No actionable issues were found. Supersession could not be checked because GitHub access required authentication. Tests were inspected, not run.

Diagram

sequenceDiagram
  participant Client
  participant Tool as Investigation tool
  participant Session
  participant Ledger
  Client->>Tool: Start investigation
  Tool->>Session: Register admitted work
  Tool->>Tool: Compute derived result
  Client->>Session: close_binary
  Session->>Session: Wait for admitted work
  Tool->>Ledger: Recheck source links
  alt Sources still exist
    Tool->>Ledger: Save derived evidence
    Tool-->>Client: Return evidence
  else Source is missing
    Tool-->>Client: Return EvidenceIntegrityError
  end
  Session->>Ledger: Clear retained records
  Session-->>Client: Close completes
Loading

Reviews (1) · Last reviewed commit: "fix(server): admit investigation tools i..." · Reviewed by Greptile

morluto added a commit that referenced this pull request Oct 15, 2026
Admit all four derived investigation workflows until Evidence recording settles, so close drains earlier work before clearing the ledger. Honor cancellation after awaited terminal progress before publishing a result.

Refs #4002, #4174

Co-authored-by: Swatantra Yadav <[email protected]>
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Integrated the session-ownership fix on main in 663d07f. All four investigation handlers hold existing session admission through derivation and Evidence recording, so close_binary drains earlier operations before clearing records. Redundant post-derivation closure repairs and private-state clearing tests were not retained. A related publication guard now honors cancellation arriving during awaited terminal progress.

The public MCP race failed on the original registration with close settling first; fixed ordering and an empty post-close ledger pass. The terminal-cancellation regression also failed before its guard and passes afterward. Main CI passed all36 jobs: https://github.com/morluto/rea/actions/runs/38792163880. Closing as addressed.

@morluto morluto closed this Oct 15, 2026
@morluto morluto added area: server Server layer and tool wiring bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: server Server layer and tool wiring bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] close_binary overtakes an earlier call-path request and leaves dangling Evidence

2 participants