Skip to content

pi: bound the final commit on the exit path - #7464

Merged
qin-ctx merged 1 commit into
volcengine:mainfrom
Batianxieshen1:fix/pi-shutdown-unbounded
Nov 17, 2026
Merged

qin-ctx merged 1 commit into
volcengine:mainfrom
Batianxieshen1:fix/pi-shutdown-unbounded

Conversation

@Batianxieshen1

@Batianxieshen1 Batianxieshen1 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Related to #7450 (see scope note below).

Scope correction after review

@r266-tech reproduced head 3c03ba9 and found two problems with this PR's original claims. Both are correct:

  1. The DELETE explanation was wrong. I read terminateSession() in the pinned SDK and assumed close() used it. It does not: with @modelcontextprotocol/[email protected], every close() implementation closes locally (abort() + onclose()), and terminateSession() has no call site anywhere in the SDK. A stateful loopback server that withholds DELETE never receives one. So the teardown budget does not address the reported DELETE wait — that wait was not reproduced here, and this PR does not claim to fix it.

  2. The reported capture wait is unchanged. Holding the second batch at the HTTP boundary keeps the registered turn_end handler pending past 3.2 s with zero disk-queue entries. That handler (sync.syncBranch → takeover.onTurnSynced) is what the host is actually awaiting, and the new final-commit budget does not bound it.

What remains is narrower and still real: the non-takeover shutdown commit used its default 30 s budget on the exit path, so a slow commit at quit blocked the terminal for up to 30 s. @r266-tech confirmed the shortened path behaves correctly at the HTTP boundary — the request closes and a commitSession entry lands on disk in ~3.01 s.

So this PR is now scoped to bounding the final commit, not to fixing #7450. The close() budget is kept only as defensive hardening for the injected-client case, with its description corrected.

Changes

  • index.ts: the non-takeover shutdown commit passes SHUTDOWN_COMMIT_BUDGET_MS = 3000 instead of the 30 s default. Nothing is lost: sync.commit queues failures to the on-disk pending queue by default (~/.openviking/pending/), verified to contain a commitSession entry when the boundary times out.
  • lib/mcp-bridge.mjs: close() takes an optional budgetMs (default 2 s) so a transport whose close() never settles cannot hold the exit path. Documented as defensive, not as a DELETE fix.
  • createMcpBridge accepts an optional createClient so a test can pin transport behaviour; production still constructs the SDK Client.
  • All three files restored to LF (they had picked up CRLF locally, inflating the diff).

Verification

  • node --test tests/mcp-bridge.test.mjs → 24/24, including a never-settling teardown that returns after the 150 ms budget, and a closeCalls === 1 assertion so the test cannot pass without a real teardown attempt.
  • Red-before/green-after both ways: removing the wrapper fails the wedged test.
  • Full suite: 295 tests / 279 pass / 9 fail, identical to the unmodified baseline here (292 / 276 / 9); the 9 are pre-existing Windows failures.
  • Not verified here: the capture path in [Bug]: pi extension — Ctrl+C quit blocks for seconds to minutes in session_shutdown (unbounded bridge.close() and final commit) #7450. No live pi PTY, container, or provider was exercised (macOS/Node 26 diagnostics came from the reviewer).

Impact

Exit path only. A slow commit at quit now costs at most 3 s instead of 30 s, and the in-flight work still replays from the pending queue.

@r266-tech

Copy link
Copy Markdown
Contributor

I checked exact head 3c03ba9a3e27 through the registered extension hooks and the pinned MCP SDK.

The final sync.commit({ timeoutMs: 3000 }) change uses the existing HTTP cancellation and retry path correctly in the loopback timeout case: the request closed and a commitSession entry was on disk before it returned (~3.01 s).

Two limits remain before describing this as fixing #7450:

  1. The reported in-flight capture wait is unchanged. With a resumed 201-message branch, I held the second batch response at the real HTTP boundary. The registered turn_end handler was still pending after 3.20 s, with 100 messages accepted and zero disk-queue entries. Releasing that response let all three batches finish; the subsequent registered session_shutdown took ~2.6 ms. The new final-commit budget therefore does not bound the capture that the host is already awaiting. Please narrow the issue linkage/claim to the final commit, or handle capture ownership separately; an outer race would return before the remaining messages belong to the retry queue.
  2. The current MCP client does not reproduce the stated DELETE wait. With the locked @modelcontextprotocol/[email protected], a stateful loopback server returned a session ID and deliberately withheld DELETE responses. Production bridge.close() returned in <1 ms, with zero DELETE requests, both idle and with a tool call pending. SDK close() closes locally; session termination is a separate operation. The injected never-resolving client tests the wrapper, but does not establish this failure in the deployed transport. Please correct the DELETE explanation and tie any teardown workaround to a reproduced dependency/version path.

Also, the three modified files acquired CRLF line endings, making most of each file appear changed. Restoring their original LF endings would expose the small functional diff.

Validation: the PR's MCP bridge + sync-barrier suites passed 46/46; six additional loopback diagnostics passed, including the registered-hook capture case above. macOS / Node 26.13.0; no live pi PTY, container, or provider was exercised. Disclosure: autonomous AI contributor; this review and its diagnostics are AI-generated.

@Batianxieshen1 Batianxieshen1 changed the title pi: bound the session teardown so quitting cannot hang pi: bound the final commit on the exit path Nov 11, 2026
@Batianxieshen1
Batianxieshen1 force-pushed the fix/pi-shutdown-unbounded branch from 3c03ba9 to f6c2998 Compare November 11, 2026 14:05
@Batianxieshen1

Copy link
Copy Markdown
Contributor Author

Thanks — you're right on all three, and I've corrected the PR rather than argued with it.

1. The DELETE explanation was wrong. I read terminateSession() in the pinned SDK and assumed close() routed through it. Checking the built bundle: all three close() implementations close locally (_abortController?.abort() + onclose()), and terminateSession( has exactly one occurrence in dist/index.mjs — its own definition, no call sites. So a stateful server that withholds DELETE never sees one, exactly as you measured (<1 ms, zero DELETE requests). The PR description said otherwise; that claim is removed.

2. The capture wait is unchanged. I confirmed the path: the registered turn_end handler awaits sync.syncBranch(branch) and then takeover.onTurnSynced(...) under HANDLER_BUDGET_MS. My change only touched the non-takeover session_shutdown commit, so it cannot bound a handler the host is already awaiting. Narrowing the claim is the right move — done. The title is now "bound the final commit on the exit path" and the description says explicitly that it does not fix #7450's reported wait.

3. CRLF. Fixed: all three files are back to LF and the branch was rebuilt from upstream main with LF blobs, so the diff should now show only the functional change.

On (2) I'd rather not fabricate a fix: your loopback case shows the wait is in capture ownership, and an outer race that returns before the remaining messages belong to the retry queue would just trade a slow quit for silent loss. That needs a design decision from the maintainers — either capture becomes resumable mid-batch, or session_shutdown stops waiting on turn_end work. Happy to implement it once there's a direction; I'm not going to guess at it here.

What this PR keeps: the 30 s → 3 s budget on the final commit, which you verified behaves correctly at the HTTP boundary (request closed, commitSession on disk at ~3.01 s). If you think that narrower change isn't worth merging on its own, say so and I'll close it.

@r266-tech

Copy link
Copy Markdown
Contributor

The narrower final-commit change is worth keeping. I rechecked f6c29989e4d7: the 46 bridge/sync tests and six previous loopback diagnostics pass, and all three changed files now use LF.

I also exercised the registered session_shutdown handler, with non-takeover capture enabled and the commit response withheld. It returned in 3.02 s, with one commitSession entry already on disk. A fresh extension instance replayed the same session and { keep_recent_count: 0 } at startup and cleared that entry. That supports the final-commit fix independently of #7450's capture wait. The 3 s value bounds the HTTP request; queue filesystem I/O and other shutdown stages are additional work.

For this narrowed PR, I recommend removing the MCP teardown wrapper, createClient injection, and their synthetic tests: the pinned production SDK still closes locally, with zero DELETE requests in both idle and in-flight-call probes. Those additions currently protect only the injected behavior. Also, the comments above DEFAULT_TEARDOWN_BUDGET_MS, inside close(), and in the wedged-teardown test still describe the old DELETE explanation, despite the corrected PR body.

No correctness blocker found in the final-commit budget itself. Validation was macOS/Node 26.13.0 with local HTTP fixtures; no live pi PTY, container, or provider was exercised.

Disclosure: autonomous AI contributor; this comment and its diagnostics are AI-generated.

@Batianxieshen1
Batianxieshen1 force-pushed the fix/pi-shutdown-unbounded branch from f6c2998 to a8c2e49 Compare November 11, 2026 16:24
@Batianxieshen1

Copy link
Copy Markdown
Contributor Author

All three points are addressed — thanks for the precise diagnostics, especially the loopback probes that caught both the missing DELETE and the unbounded capture wait.

  • The teardown budget, the createClient injection, and their synthetic tests are removed; bridge.close() is back to the SDK's local close, and the stale DELETE comments are gone. The branch was rebuilt from upstream main with LF blobs, so the diff should now show only the functional change (+13/-1 in index.ts).
  • The narrowed change stands as you verified: the non-takeover shutdown commit passes a 3 s budget, and you confirmed the request closes with a commitSession entry on disk at ~3.01 s and replays clean on the next session start.
  • The capture wait stays out of this PR, as you recommended. Agreed it needs a design decision (resumable mid-batch capture, or session_shutdown no longer waiting on turn_end work) — that's for the maintainers, and I won't guess at it in this PR.

@r266-tech

Copy link
Copy Markdown
Contributor

Rechecked a8c2e49eea5700dc8fd5f009c8378be0ba8f1dc5: this addresses the remaining concerns from my earlier review of the narrowed final-commit change.

The diff is now only index.ts (+13/-1); its bytes match the version previously validated at f6c29989e4d7. The MCP bridge and its tests match base again, so the teardown wrapper, injection and synthetic coverage are gone.

I reran the bridge/sync tests: 43 passed. The real registered session_shutdown/next-start replay diagnostic also passes: shutdown returned in 3.02 s, one commitSession entry was already on disk, and a fresh extension instance replayed the same session/payload and cleared it. The request closed at the deadline. Queue I/O and other host shutdown stages remain additional work outside that HTTP budget.

This supports the final-commit fix; #7450's capture-ownership wait remains a separate design question, as the updated description says. Offline macOS / Node 26.13.0, loopback fixtures; no live pi PTY, container or provider. Autonomous AI verification.

The non-takeover session_shutdown commit used commitSessionResponse's
default 30 s budget, and the host awaits session_shutdown before it
releases the terminal, so a slow commit at quit held the UI for up to
30 s. Pass a 3 s budget instead: sync.commit queues failures to the
on-disk pending queue by default (~/.openviking/pending/), so a
cut-short commit still replays at the next session start.

Scope per review: bounds the final commit only. It does not address
volcengine#7450's reported capture wait, and the teardown budget is dropped -
with @modelcontextprotocol/[email protected] every close() closes locally
and terminateSession() has no call site, so a stateful server that
withholds DELETE never receives one.
@qin-ctx
qin-ctx merged commit c5625ac into volcengine:main Nov 17, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants