[PR #4174] [CLOSED] fix(server): admit investigation tools into session lifecycle (#4002) #6110

Closed
opened 2026-10-31 01:11:56 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4174
Author: @Swatantra-66
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/close-binary-investigation-lifecycle


📝 Commits (1)

  • b9ad56d fix(server): admit investigation tools into session lifecycle to prevent dangling records on close

📊 Changes

2 files changed (+424 additions, -177 deletions)

View changed files

📝 src/server/registerInvestigationTools.ts (+255 -177)
📝 tests/boundary/mcp/investigationAnalysisMcp.test.ts (+169 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4174 **Author:** [@Swatantra-66](https://github.com/Swatantra-66) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/close-binary-investigation-lifecycle` --- ### 📝 Commits (1) - [`b9ad56d`](https://github.com/morluto/rea/commit/b9ad56dc1f5800f330bb7a36ab95e3e76edfba5d) fix(server): admit investigation tools into session lifecycle to prevent dangling records on close ### 📊 Changes **2 files changed** (+424 additions, -177 deletions) <details> <summary>View changed files</summary> 📝 `src/server/registerInvestigationTools.ts` (+255 -177) 📝 `tests/boundary/mcp/investigationAnalysisMcp.test.ts` (+169 -0) </details> ### 📄 Description ## 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. - [x] 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: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] 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 - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:11:56 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6110
No description provided.