fix(agent-core-v2): rebind stale agent runtime to local on first use after restore - #3563
Open
mike-lmctl wants to merge 2 commits into
Open
fix(agent-core-v2): rebind stale agent runtime to local on first use after restore#3563mike-lmctl wants to merge 2 commits into
mike-lmctl wants to merge 2 commits into
Conversation
…after restore A runtime binding replayed from persisted state on restore can point at a runtime the current process never registers (e.g. an acp:<sessionId> binding from a previous ACP-driven lifetime, resumed in a TUI/kap-server/ headless host). Every tool call and subagent spawn then failed permanently with 'runtime <id> does not exist in workspace <id>' until a full CLI restart, and runtime-gated tools stayed deactivated because availability probes never recovered. AgentRuntimeService.inspect()/acquire()/isAvailable() now catch 'runtime.not_found', rebind the agent to the always-present local runtime via IAgentRuntimeBindingService.set() (persisting the durable RuntimeSetBinding event), and retry once. Registered-but-unavailable runtimes (disconnected/draining) never heal; when the local fallback is also missing the original error is rethrown with the fallback failure attached as cause.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
🦋 Changeset detectedLatest commit: 85bf291 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
Resolve #3562
(External-PR rule noted: this PR waits for a maintainer's
/approveon the linked issue.)Problem
After a process restart, a restored session whose persisted agent runtime binding points at a runtime the new process never registers (e.g. an
acp:<sessionId>binding from a previouskimi acplifetime, resumed via the TUI, kap-server, or headless-p) is permanently wedged: runtime-gated tools stay deactivated and every subagent spawn fails withruntime <id> does not exist in workspace <id>. Only creating a new session recovers. Full root-cause chain and a deterministic reproduction are in the linked issue.What changed
AgentRuntimeService.inspect()/acquire()/isAvailable()now catchRuntimeErrorwith coderuntime.not_found, rebind the agent to the always-presentlocalruntime throughIAgentRuntimeBindingService.set()(persisting the durableRuntimeSetBindingevent and firingonDidChange, so tool activation refreshes), and retry once.Why lazy healing at the point of use fits: in the healthy ACP flow, agent scope restore runs before
bindSessionRuntimeregisters the session's ACP runtime, so restore-time validation would break normal resume; healing on first use only fires when the runtime genuinely never appears. Runtimes that are registered but disconnected/draining reportruntime.unavailableand never heal, so temporarily dropped runtimes keep their bindings. If the agent is already onlocalor the fallback is missing, the original error is rethrown with the fallback failure attached ascause.Verified with a deterministic end-to-end reproduction (ACP-created session resumed headless: spawn fails with the exact reported error on the unpatched build, succeeds on the patched build, binding healed to
localon disk) and new unit tests covering heal-via-acquire/inspect/availability, persistence of the healed binding, and the missing-fallback error path.Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.