fix(runtime): retain persistent ACP client across turns#265
Merged
steipete merged 2 commits intoApr 25, 2026
Conversation
Contributor
|
Thanks for digging into this. We confirmed the lifecycle bug affects our I ported the same fix into our active runtime branches, with two extra regression cases:
Updated branches/PRs:
Both branch-specific runtime-manager suites pass, and the full So yes, this was a real bug and the core fix direction in this PR is correct. The only practical difference is that our current branches needed the fix applied to their refactored turn lifecycle path rather than cherry-picking this patch directly. |
ensureSession places persistent clients into pendingPersistentClients (keepClientOpen=true), but runTurn's finally unconditionally closes the client, breaking lifecycle symmetry and causing per-send cold-start for persistent sessions. - runTurn finally: mirror the persistent branch symmetrically by returning the client to the pool when the record is persistent (recordId does not contain ":oneshot:"), the record is still open, and the backend reports a reusable session. - close(): when invoked without discardPersistentState (e.g. via AcpxManager.evictIdleRuntimeHandles with reason="idle-evicted"), clean the pool so we do not leak pooled CLI processes. Validated locally by applying equivalent edits to dist/register.runtime-*.js, restarting the gateway, then running two turns against the same persistent gemini-acp label: PID and agent_started_at remained stable across turns, and the pooled process was reaped on the next unrelated spawn which triggered evictIdleRuntimeHandles.
62717ea to
715141a
Compare
Contributor
|
Landed via maintainer fixup and rebase onto main.
Thanks @Sway-Chan! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #264.
Two edits to
src/runtime/engine/manager.ts:runTurnfinally now returns the client topendingPersistentClientswhen the record is persistent (recordId does not contain":oneshot:") and the backend reports a reusable session, restoring lifecycle symmetry withensureSession.close()now cleans the pool on the non-discardPersistentStatepath, soAcpxManager.evictIdleRuntimeHandles(reason="idle-evicted") does not leak pooled CLI processes.Test plan
register.runtime-*.js, then restarting the gateway: two turns against the same persistentgemini-acplabel;pidandagent_started_atstable across turns; pooled process reaped on next unrelated spawn (see issue for details).Related