[PR #5376] [CLOSED] fix(gdb): keep a failed startup's retained owner closed #6908

Closed
opened 2026-11-01 21:43:58 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5376
Author: @XiaoBinGan
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: fix/gdb-retained-startup-readiness


📝 Commits (2)

  • 0814c9d fix(gdb): keep a failed startup's retained owner closed
  • 5702f60 fix(gdb): publish readiness only with a successfully published session

📊 Changes

2 files changed (+41 additions, -1 deletions)

View changed files

📝 src/gdb/GdbSessionManager.ts (+5 -1)
📝 tests/boundary/providers/GdbSessionManagerCoverage.test.ts (+36 -0)

📄 Description

Summary

A start_gdb_session that fails after the MI prompt and whose owned GDB process cannot be confirmed stopped keeps its ID in the session map so the owner stays available for cleanup. Because the MI prompt had already been received, that retained entry still reported state: "ready" and gdb_console dispatched new commands to a debugger whose required startup configuration had just failed.

Fixes #5331

Problem and expected behavior

  • Smallest trigger: start_gdb_session where -gdb-set auto-load off is rejected (or the inferior_tty readback mismatches) and the owned process survives the stop attempt, so #stopDebuggerOnly reports incomplete.
  • Violated invariant: readiness must follow the current startup's completion, and ownership retention must not imply readiness (lifecycle rules). The retained entry kept session.ready = true, set before configuration, so status projected ready and execute accepted the ID.
  • Expected: the retained ID reports state: "closed" (without implying confirmed process exit), and gdb_console refuses it with the existing "GDB session is unavailable or closed." input error without writing any command to GDB.

Change and scope

  • src/gdb/GdbSessionManager.ts: when cleanup is incomplete and the owner is retained for release, clear session.ready before publishing it into the session map. Status then projects closed and the existing execute guard refuses the ID; the retained entry, its supervisor and its ownership record are otherwise untouched, so close_gdb_session still releases it.
  • tests/boundary/providers/GdbSessionManagerCoverage.test.ts: a regression that drives the auto-load rejection with an incomplete stop, then asserts the retained ID reports closed, that gdb_console returns AnalysisInputError, and that the only command ever written to GDB is the startup auto-load command.
  • Not included: no change to the status enum, the ownership and cleanup contract, or the timeout path, which already reports closed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: GdbSessionManager startup readiness projection in src/gdb/GdbSessionManager.ts.
  • Contribution scope fit and linked maintainer decision: not applicable — an ordinary fix inside an existing boundary, no new provider or capability.
  • CLI and MCP/tool-catalog contract: no schema or tool-catalog change. gdb_session_status returns the existing closed state and gdb_console returns its existing unavailable-or-closed input error.
  • Provider, bridge, target-format, or platform compatibility: GDB session manager only, Linux-gated as before.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; the startup failure still projects its captured output and partial startup observation.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged. The retained owner is still released through the same stop/close path; this change only stops advertising it as usable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).

  • 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: GdbSessionManagerCoverage.test.ts gains "reports a retained failed-startup owner as closed and refuses console dispatch".
  • Base reproduction or other evidence: with the one-line readiness change reverted, the new test fails as AssertionError: expected 'ready' to be 'closed' (1 failed | 149 skipped). With the fix it passes. The reported behaviour is reached through the production startup, stop and projection path with the injected fake spawner, not by asserting on a hand-built session.
  • User-visible CLI/MCP output (if applicable): gdb_session_status returns state: "closed" instead of ready; gdb_console returns the existing AnalysisInputError with message "GDB session is unavailable or closed."
  • Remaining proof gaps: no real GNU GDB, inferior, or terminal was run; Linux/x64 is injected the way the report does it. The reproduction in the issue also covers the inferior_tty readback failure, which shares this retained path but is not separately re-driven here.

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

  • npx vitest run tests/boundary/providers/GdbSessionManagerCoverage.test.ts — 150 tests passed.
  • npx vitest run tests/boundary/providers/GdbSessionManagerCoverage.test.ts -t "retained failed-startup owner" with the readiness change reverted — 1 failed | 149 skipped, expected 'ready' to be 'closed'.
  • npx vitest run tests/boundary/cli/gdbStartupCleanupCli.test.ts tests/boundary/mcp/gdbCancellationMcp.test.ts tests/boundary/mcp/gdbCloseDisposition.test.ts tests/boundary/providers/GdbCommandQueue.test.ts tests/boundary/providers/GdbSessionManagerCoverage.test.ts tests/boundary/providers/GdbSessionManagers.test.ts tests/boundary/providers/GdbSessionReviewRegressions.test.ts — all passed; one timing-sensitive signal-file assertion in GdbSessionReviewRegressions failed once under parallel load and passed alone and on rerun.
  • npm run format:check — all matched files use the correct format.
  • npm run verify:test-discovery — all 1718 test files discovered exactly once.
  • npm run typecheck — no diagnostic in the changed files; this checkout's install predates the @bufbuild/protobuf dependency on current main, which is the only error source.
  • npm run lint — 0 errors, module boundaries resolved in 2262 files.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; callers that ignored the startup error now receive the documented refusal instead of dispatching into a misconfigured debugger.
  • Real Hopper/Ghidra, browser, or OS coverage: none claimed; no real debugger or target.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; ownership retention and the stop path are unchanged.

Note: an independent PR (#5375) targets the same report. This one keeps the diff to the readiness flag and asserts that no console command reaches GDB.

Author readiness

Human owner: @XiaoBinGan

  • 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/5376 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/gdb-retained-startup-readiness` --- ### 📝 Commits (2) - [`0814c9d`](https://github.com/morluto/rea/commit/0814c9d8bb857fe1e7c8d7fc64954a0d4639721e) fix(gdb): keep a failed startup's retained owner closed - [`5702f60`](https://github.com/morluto/rea/commit/5702f60fba5465cf06a59f8b7f697ca8b97c7869) fix(gdb): publish readiness only with a successfully published session ### 📊 Changes **2 files changed** (+41 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/gdb/GdbSessionManager.ts` (+5 -1) 📝 `tests/boundary/providers/GdbSessionManagerCoverage.test.ts` (+36 -0) </details> ### 📄 Description ## Summary A `start_gdb_session` that fails after the MI prompt and whose owned GDB process cannot be confirmed stopped keeps its ID in the session map so the owner stays available for cleanup. Because the MI prompt had already been received, that retained entry still reported `state: "ready"` and `gdb_console` dispatched new commands to a debugger whose required startup configuration had just failed. Fixes #5331 ## Problem and expected behavior - Smallest trigger: `start_gdb_session` where `-gdb-set auto-load off` is rejected (or the `inferior_tty` readback mismatches) and the owned process survives the stop attempt, so `#stopDebuggerOnly` reports `incomplete`. - Violated invariant: readiness must follow the current startup's completion, and ownership retention must not imply readiness ([lifecycle rules](https://github.com/morluto/rea/blob/main/docs/tool-design.md)). The retained entry kept `session.ready = true`, set before configuration, so `status` projected `ready` and `execute` accepted the ID. - Expected: the retained ID reports `state: "closed"` (without implying confirmed process exit), and `gdb_console` refuses it with the existing "GDB session is unavailable or closed." input error without writing any command to GDB. ## Change and scope - `src/gdb/GdbSessionManager.ts`: when cleanup is incomplete and the owner is retained for release, clear `session.ready` before publishing it into the session map. Status then projects `closed` and the existing `execute` guard refuses the ID; the retained entry, its supervisor and its ownership record are otherwise untouched, so `close_gdb_session` still releases it. - `tests/boundary/providers/GdbSessionManagerCoverage.test.ts`: a regression that drives the auto-load rejection with an incomplete stop, then asserts the retained ID reports `closed`, that `gdb_console` returns `AnalysisInputError`, and that the only command ever written to GDB is the startup auto-load command. - Not included: no change to the status enum, the ownership and cleanup contract, or the timeout path, which already reports `closed`. ## Contract and boundary impact - Semantic owner and earliest changed stage: `GdbSessionManager` startup readiness projection in `src/gdb/GdbSessionManager.ts`. - Contribution scope fit and linked maintainer decision: not applicable — an ordinary fix inside an existing boundary, no new provider or capability. - CLI and MCP/tool-catalog contract: no schema or tool-catalog change. `gdb_session_status` returns the existing `closed` state and `gdb_console` returns its existing unavailable-or-closed input error. - Provider, bridge, target-format, or platform compatibility: GDB session manager only, Linux-gated as before. - Evidence, artifact, provenance, or reconstruction contract: unchanged; the startup failure still projects its captured output and partial startup observation. - Target selection, authority, upstream behavior, and cleanup details: unchanged. The retained owner is still released through the same stop/close path; this change only stops advertising it as usable. - Generated metadata, package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). - [ ] Read existing files or captured data. - [x] 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: `GdbSessionManagerCoverage.test.ts` gains "reports a retained failed-startup owner as closed and refuses console dispatch". - Base reproduction or other evidence: with the one-line readiness change reverted, the new test fails as `AssertionError: expected 'ready' to be 'closed'` (1 failed | 149 skipped). With the fix it passes. The reported behaviour is reached through the production startup, stop and projection path with the injected fake spawner, not by asserting on a hand-built session. - User-visible CLI/MCP output (if applicable): `gdb_session_status` returns `state: "closed"` instead of `ready`; `gdb_console` returns the existing `AnalysisInputError` with message "GDB session is unavailable or closed." - Remaining proof gaps: no real GNU GDB, inferior, or terminal was run; Linux/x64 is injected the way the report does it. The reproduction in the issue also covers the `inferior_tty` readback failure, which shares this retained path but is not separately re-driven here. 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 - `npx vitest run tests/boundary/providers/GdbSessionManagerCoverage.test.ts` — 150 tests passed. - `npx vitest run tests/boundary/providers/GdbSessionManagerCoverage.test.ts -t "retained failed-startup owner"` with the readiness change reverted — 1 failed | 149 skipped, `expected 'ready' to be 'closed'`. - `npx vitest run tests/boundary/cli/gdbStartupCleanupCli.test.ts tests/boundary/mcp/gdbCancellationMcp.test.ts tests/boundary/mcp/gdbCloseDisposition.test.ts tests/boundary/providers/GdbCommandQueue.test.ts tests/boundary/providers/GdbSessionManagerCoverage.test.ts tests/boundary/providers/GdbSessionManagers.test.ts tests/boundary/providers/GdbSessionReviewRegressions.test.ts` — all passed; one timing-sensitive signal-file assertion in `GdbSessionReviewRegressions` failed once under parallel load and passed alone and on rerun. - `npm run format:check` — all matched files use the correct format. - `npm run verify:test-discovery` — all 1718 test files discovered exactly once. - `npm run typecheck` — no diagnostic in the changed files; this checkout's install predates the `@bufbuild/protobuf` dependency on current main, which is the only error source. - `npm run lint` — 0 errors, module boundaries resolved in 2262 files. ## Compatibility, safety, and release - Breaking changes or migration steps: none; callers that ignored the startup error now receive the documented refusal instead of dispatching into a misconfigured debugger. - Real Hopper/Ghidra, browser, or OS coverage: none claimed; no real debugger or target. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none; ownership retention and the stop path are unchanged. Note: an independent PR (#5375) targets the same report. This one keeps the diff to the readiness flag and asserts that no console command reaches GDB. ## Author readiness Human owner: @XiaoBinGan - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] 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-11-01 21:43:58 +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#6908
No description provided.