Skip to content

refactor(agent-core-v2): compose the llm recovery chain outside the turn machine - #3724

Merged
7Sageer merged 2 commits into
mainfrom
refactor/turn-recovery-chain
Sep 11, 2026
Merged

refactor(agent-core-v2): compose the llm recovery chain outside the turn machine#3724
7Sageer merged 2 commits into
mainfrom
refactor/turn-recovery-chain

Conversation

@7Sageer

@7Sageer 7Sageer commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — internal refactor spun out of a design review of #3682.

Problem

The turn machine was coupled to the credentials domain in two places: it imported credentialsRecovery and hardcoded it as the head of the recovery chain, and it interpreted a credential-named refreshCredentials flag on recovery proposals by calling credentials.invalidate() itself. Recovery orchestration belongs to the turn; credential knowledge does not.

What changed

  • LlmRecovery.propose now returns a self-describing record (strategy/action, optional replacement messages, optional opaque prepare effect). The credential-specific refreshCredentials flag is gone, and the now-unused LlmRecovery.id goes with it.
  • credentialsRecovery encapsulates the refresh in a prepare closure; createMediaDegradeRecovery stamps its own strategy id.
  • The turn no longer imports anything credential-related: on a triaged failure it runs proposal.prepare?.() and/or swaps messages. turn.failure.triaged semantics are unchanged.
  • New chainRecoveries(...) combinator; the engine composes chainRecoveries(credentialsRecovery, options.recovery), keeping the "refresh credentials before degrading media" priority at the composition root.
  • Design docs (docs/en\|zh/llm.md) updated to match.

recovery chain before/after

Behavior is identical: same event sequence, same llm.recovering records, same per-turn strategy dedup. Verified with typecheck, the full package vitest run (6562 tests), oxlint, and the repo no-comments / import-boundary checks. No changeset: internal refactor, not user-perceivable.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (internal refactor, no issue).
  • 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.

…urn machine

The turn machine hardcoded credentialsRecovery as the head of its
recovery chain and interpreted a refreshCredentials flag on proposals,
coupling the turn to the credentials domain. Strategies now return
self-describing records (strategy/action, optional messages, optional
opaque prepare effect), the turn only runs prepare and/or swaps
messages, and the engine composes the chain via chainRecoveries.
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4fad83c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@7Hanrui

7Hanrui commented Sep 11, 2026

Copy link
Copy Markdown

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@4fad83c
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4fad83c

commit: 4fad83c

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 28421430f2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

With self-describing proposals the chain is a one-liner at each call
site; the named chainRecoveries combinator had only two call sites and
no third strategy to justify it.
@7Hanrui

7Hanrui commented Sep 11, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 4fad83c414

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Sageer
7Sageer merged commit 72dbb9b into main Sep 11, 2026
15 checks passed
@7Sageer
7Sageer deleted the refactor/turn-recovery-chain branch September 11, 2026 06:37
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.

2 participants