feat(phai): add refresh_session ACP method for sandboxes#1717
Merged
Conversation
- Abort the old AbortController before awaiting interrupt() so stuck HTTP requests can't deadlock the refresh; allocate a fresh controller for the new Query and update session.abortController so closeSession still works. - Reject refresh when session.modelId is on the MCP-exclusion list (e.g. claude-haiku-4-5), matching the guard in handleNewSession. - Reject payloads with no refreshable fields or a non-array mcpServers so caller bugs surface loudly instead of returning a phantom success. - Replace spread + delete sessionId with destructuring. - Expand tests: payload validation, unsupported-model, initialization timeout (fake timers), AbortController identity swap, MCP metadata refetch for the new Query. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Problem
Sandbox agent-servers need a way to refresh a Claude session's MCP server config between turns — for example, to swap in freshly-minted OAuth credentials on a pre-prompt TTL check — without tearing down the whole session and losing conversation history.
Changes
_posthog/refresh_sessioncustom ACP extension method (request/response, not notification) so the caller can await completion before sending the next prompt.ClaudeAcpAgent.extMethod()for the Claude adapter: interrupts the runningQuery, ends the input stream, and builds a newQuerywith updatedmcpServersusingresume(notsessionId) so conversation history is preserved.query.setMcpServers()because the latter can non-deterministically surface plugin-installed MCPs over the CLI-supplied ones; passingmcpServersviaquery()options guarantees overwrite.isNotificationinacp-extensions.tsto share matching logic with a newisMethodhelper, and add aPOSTHOG_METHODSregistry.How did you test this code?
packages/agent/src/acp-extensions.test.tscoverisNotification/isMethodincluding the__posthog/double-prefix case.packages/agent/src/adapters/claude/claude-agent.refresh.test.tsverify thatrefresh_session:methodNotFoundfor unknown ext methods,query/input/queryOptionsand preserves session-level state (accumulated usage, notification history),query()call withresumeinstead ofsessionIdand the new MCP server set.Publish to changelog?
no