Skip to content

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
MoonshotAI:mainfrom
mike-lmctl:upstream-pr/acp-runtime-fix
Open

fix(agent-core-v2): rebind stale agent runtime to local on first use after restore#3563
mike-lmctl wants to merge 2 commits into
MoonshotAI:mainfrom
mike-lmctl:upstream-pr/acp-runtime-fix

Conversation

@mike-lmctl

Copy link
Copy Markdown

Related Issue

Resolve #3562

(External-PR rule noted: this PR waits for a maintainer's /approve on 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 previous kimi acp lifetime, resumed via the TUI, kap-server, or headless -p) is permanently wedged: runtime-gated tools stay deactivated and every subagent spawn fails with runtime <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 catch RuntimeError with code runtime.not_found, rebind the agent to the always-present local runtime through IAgentRuntimeBindingService.set() (persisting the durable RuntimeSetBinding event and firing onDidChange, 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 bindSessionRuntime registers 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 report runtime.unavailable and never heal, so temporarily dropped runtimes keep their bindings. If the agent is already on local or the fallback is missing, the original error is rethrown with the fallback failure attached as cause.

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 local on disk) and new unit tests covering heal-via-acquire/inspect/availability, persistence of the healed binding, and the missing-fallback error path.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85bf291

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restored session permanently loses tool/subagent access when its persisted runtime binding is stale (acp-runtime-after-reap)

1 participant