[PR #6369] [CLOSED] fix(gdb): reject queued commands once their session is closing #7316

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6369
Author: @Adolanium
Created: 10/22/2026
Status: ❌ Closed

Base: main ← Head: fix/gdb-closing-queued-commands


📝 Commits (1)

  • 3addc11 fix(gdb): reject queued commands once their session is closing

📊 Changes

2 files changed (+123 additions, -11 deletions)

View changed files

📝 src/gdb/GdbSessionManager.ts (+20 -11)
📝 tests/boundary/providers/GdbSessionManagerCoverage.test.ts (+103 -0)

📄 Description

Summary

Fixes #6370.

GdbSessionManager only checked that a session was open when a gdb_console command or a close_gdb_session call arrived, not when its turn came up in the session queue. So a command queued behind an active command could run after closeAll() or close() had started. A second close queued behind the first also ran the exit and stop sequence again. Queued work now rechecks the session when its turn starts, and is rejected as unavailable once the session is closing or gone.

Problem and expected behavior

execute() rejects a command up front when the manager is closing or the session is missing, exited, or broken. It then waits in #serialize for its turn, and once its turn starts it rechecked only session.exited and session.protocolError. close() and closeAll() remove the session or set #closing first. But the GDB child's exit event can arrive after the stop result, so exited is still false when the queued command's turn comes. In that window the queued command was sent to the closing debugger. A queued run, for example, could start the inferior during shutdown. A duplicate close() queued behind the first one sent -gdb-exit and stopped the process a second time.

Expected: once a close has started, queued commands fail with the same AnalysisInputError ("GDB session is unavailable or closed.") that a new command gets. A queued duplicate close fails as a close_gdb_session input error without repeating cleanup.

Change and scope

  • When its queued turn starts, execute() repeats the conditions it checked on entry: #closing, the session still being the registered one, exited, and protocolError. Both checks return the same unavailable() error.
  • When its queued turn starts, close() checks that the session is still registered, so a close queued behind another close returns an input error.
  • No change to the tool contracts, GDB protocol handling, or cleanup ownership.

Contribution scope: not applicable. This is a fix inside the existing GDB session lifecycle.

Contract and boundary impact

  • Semantic owner and earliest changed stage: GdbSessionManager admission of queued execute and close calls.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. A gdb_console call queued behind a close now returns the existing unavailable-session input error instead of running.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): a queued command can no longer reach a debugger that is closing, and a duplicate close no longer repeats -gdb-exit and the process stop.
  • 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 in tests/boundary/providers/GdbSessionManagerCoverage.test.ts, using the fake GDB spawner:
    • "rejects GDB commands queued before closeAll when their turn arrives" holds one command, queues run, starts closeAll(), and then releases the held command. The queued command must fail as a gdb_console input error, and run must never be sent.
    • "rejects GDB commands queued behind a session close" does the same with close(), where the stop result is reported before the exit event.
    • "rejects a duplicate GDB close queued behind a session close" checks that the second close fails as a close_gdb_session input error, with one -gdb-exit and one process stop.
  • Base reproduction: with the queued execute check reduced to exited and protocolError as before, the first two tests fail. Without the queued close check, the third fails.
  • User-visible CLI/MCP output (if applicable): unchanged apart from the error above.
  • Remaining proof gaps: no run against a real GDB. The timing window is reproduced only with the fake spawner.

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

On Linux (WSL Ubuntu, Node 24.18.0) at upstream/main 86655eac6 plus this commit, after npm run build:cached:

  • npx tsc -p . --noEmit reported 7 errors, all in files this PR does not touch (src/application/ReconstructionObligationCandidates.ts, src/application/LinuxHopper.test.ts, src/application/LinuxHopperPackageRuntime.test.ts). The same 7 errors occur on upstream/main 86655eac6.
  • npx oxfmt --check on the two changed files: clean.
  • npx oxlint on the two changed files: 19 warnings, the same count as GdbSessionManager.ts has on the parent commit.
  • npx vitest run on GdbSessionManagerCoverage, src/gdb and the other GDB provider tests: 4 files and 193 tests passed, in two runs.
  • Each negative check above failed the tests it names.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none; fake GDB spawner only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: commands can no longer reach a debugger that is shutting down, and the same session is no longer cleaned up twice.

Author readiness

Human owner: @Adolanium

  • 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/6369 **Author:** [@Adolanium](https://github.com/Adolanium) **Created:** 10/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/gdb-closing-queued-commands` --- ### 📝 Commits (1) - [`3addc11`](https://github.com/morluto/rea/commit/3addc11788f9950c7f094e5b1bfd4f27b44b1f69) fix(gdb): reject queued commands once their session is closing ### 📊 Changes **2 files changed** (+123 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src/gdb/GdbSessionManager.ts` (+20 -11) 📝 `tests/boundary/providers/GdbSessionManagerCoverage.test.ts` (+103 -0) </details> ### 📄 Description ## Summary Fixes #6370. `GdbSessionManager` only checked that a session was open when a `gdb_console` command or a `close_gdb_session` call arrived, not when its turn came up in the session queue. So a command queued behind an active command could run after `closeAll()` or `close()` had started. A second close queued behind the first also ran the exit and stop sequence again. Queued work now rechecks the session when its turn starts, and is rejected as unavailable once the session is closing or gone. ## Problem and expected behavior `execute()` rejects a command up front when the manager is closing or the session is missing, exited, or broken. It then waits in `#serialize` for its turn, and once its turn starts it rechecked only `session.exited` and `session.protocolError`. `close()` and `closeAll()` remove the session or set `#closing` first. But the GDB child's exit event can arrive after the stop result, so `exited` is still false when the queued command's turn comes. In that window the queued command was sent to the closing debugger. A queued `run`, for example, could start the inferior during shutdown. A duplicate `close()` queued behind the first one sent `-gdb-exit` and stopped the process a second time. Expected: once a close has started, queued commands fail with the same `AnalysisInputError` ("GDB session is unavailable or closed.") that a new command gets. A queued duplicate close fails as a `close_gdb_session` input error without repeating cleanup. ## Change and scope - When its queued turn starts, `execute()` repeats the conditions it checked on entry: `#closing`, the session still being the registered one, `exited`, and `protocolError`. Both checks return the same `unavailable()` error. - When its queued turn starts, `close()` checks that the session is still registered, so a close queued behind another close returns an input error. - No change to the tool contracts, GDB protocol handling, or cleanup ownership. Contribution scope: not applicable. This is a fix inside the existing GDB session lifecycle. ## Contract and boundary impact - Semantic owner and earliest changed stage: `GdbSessionManager` admission of queued `execute` and `close` calls. - Contribution scope fit and linked maintainer decision: not applicable. - CLI and MCP/tool-catalog contract: no schema change. A `gdb_console` call queued behind a close now returns the existing unavailable-session input error instead of running. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): a queued command can no longer reach a debugger that is closing, and a duplicate close no longer repeats `-gdb-exit` and the process stop. - 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. - [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 in `tests/boundary/providers/GdbSessionManagerCoverage.test.ts`, using the fake GDB spawner: - "rejects GDB commands queued before closeAll when their turn arrives" holds one command, queues `run`, starts `closeAll()`, and then releases the held command. The queued command must fail as a `gdb_console` input error, and `run` must never be sent. - "rejects GDB commands queued behind a session close" does the same with `close()`, where the stop result is reported before the exit event. - "rejects a duplicate GDB close queued behind a session close" checks that the second close fails as a `close_gdb_session` input error, with one `-gdb-exit` and one process stop. - Base reproduction: with the queued `execute` check reduced to `exited` and `protocolError` as before, the first two tests fail. Without the queued `close` check, the third fails. - User-visible CLI/MCP output (if applicable): unchanged apart from the error above. - Remaining proof gaps: no run against a real GDB. The timing window is reproduced only with the fake spawner. 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 On Linux (WSL Ubuntu, Node 24.18.0) at upstream/main 86655eac6 plus this commit, after `npm run build:cached`: - `npx tsc -p . --noEmit` reported 7 errors, all in files this PR does not touch (`src/application/ReconstructionObligationCandidates.ts`, `src/application/LinuxHopper.test.ts`, `src/application/LinuxHopperPackageRuntime.test.ts`). The same 7 errors occur on upstream/main 86655eac6. - `npx oxfmt --check` on the two changed files: clean. - `npx oxlint` on the two changed files: 19 warnings, the same count as `GdbSessionManager.ts` has on the parent commit. - `npx vitest run` on `GdbSessionManagerCoverage`, `src/gdb` and the other GDB provider tests: 4 files and 193 tests passed, in two runs. - Each negative check above failed the tests it names. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: none; fake GDB spawner only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: commands can no longer reach a debugger that is shutting down, and the same session is no longer cleaned up twice. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: @Adolanium - [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 <!-- Draft PRs may leave pending items unchecked. Resolve material scope and authority questions before integration. --> - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:46:59 +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#7316
No description provided.