Repository navigation
fix(agent-core-v2): align fork slicing with restored turn ids - #5165
Conversation
🦋 Changeset detectedLatest commit: 70f10d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70f10d90fb
ℹ️ 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".
| : normalizeLegacyTurnSteerRecords( | ||
| flattenChain(await this.readSourceWireRecords(sourceHandle, sourceId, MAIN_AGENT_ID)), | ||
| ); |
There was a problem hiding this comment.
Translate active turn IDs before slicing normalized records
When a live, unrestored session has an earlier turn.steer and a later turn is currently running, activeTurnIds still contains the runtime ID, but this normalization renumbers the steer and every following prompt. sliceRecordsBeforePendingWork and sliceMainRecordsForRunningFork then match that ID to the earlier synthetic steer prompt, so a no-index fork silently captures the steer as the active turn and drops subsequent completed context; an indexed fork can similarly reject an otherwise completed turn. Preserve raw records for running forks or map the captured active ID into the normalized ID space before slicing.
AGENTS.md reference: AGENTS.md:L112-L115
Useful? React with 👍 / 👎.
* fix(core): add Claude 5 output token ceilings (#5096) * fix(core): add Claude 5 output token ceilings * chore: add Claude 5 output ceiling changeset * fix(markdown): keep table actions inside clipped containers (#5098) * fix(markdown): keep table actions inside clipped containers * fix(markdown): observe table action clipping ancestors --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(hosts): keep project lists usable with SSH hosts (#5102) * ci: release packages (#5094) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: preserve first prompt through project creation (#5161) Co-authored-by: kimi-agent-bot <[email protected]> * fix(agent-core-v2): align fork slicing with restored turn ids (#5165) * fix(agent-core-v2): align fork slicing with restored turn ids * chore: add restored fork fix changeset * fix(core): prevent AJV diagnostics from polluting TUI input (#5168) * refactor(core): route AJV logs through utils logger * chore(core): add AJV logger changeset * chore(core): clarify AJV logger changeset * fix: support UUID generation in insecure browser contexts (#5173) * fix: support UUID generation in insecure browser contexts * chore: update pnpm deps hash * fix: resolve crypto bindings in UUID lint rule --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(client): keep draft thinking effort after sending (#5170) * fix(client): keep draft thinking effort after sending * chore: add cli changeset for draft thinking fix * test(client): use function stub for websocket in thinking test * fix(client): preserve thinking effort during model normalization * fix(client): reconcile profile updates and model fallbacks * fix(client): scope draft thinking preservation * fix(tui): defer queued prompts until the loop drains (#5166) * fix(tui): defer queued prompts until the loop drains - add core and v2 drained/idle lifecycle events - consume reminder-only queues without starting a model turn - gate TUI queue dispatch and completion notifications on lifecycle state - document notification-handoff queue behavior and add a CLI patch changeset * fix(tui): close loop lifecycle races - emit idle only after the current macro is revalidated - keep queued input pending through compaction and delayed dispatch - reject stale idle after new work starts * fix(loop): correlate lifecycle events by generation - track macro generations in the core and v2 loop state - replace TUI macro inference with event-generation correlation - preserve compaction guards for queued dispatch * fix(desktop): simplify multi-select folder picker actions (#5174) * fix(kap-server): report :wait settled only after the session is on disk (#5176) :wait settled as soon as the turn left the in-memory activity view, but the engine writes wire records through a batched log that flushes in a later task. A server killed right after :wait reported idle could lose the end of the finished turn. Before it replies with a settled session, :wait now flushes the wire of every agent in the session and drains pending metadata writes. A failed write surfaces as an error instead of a settled reply. The KAP guide states the guarantee. A new test in sessions.test.ts slows down the disk write of the turn end and checks that the record is on disk when :wait returns. (cherry picked from commit fc33c6d) Co-authored-by: kai <[email protected]> * ci: release packages (#5163) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(client): keep config-derived draft thinking effort after sending (#5191) Co-authored-by: liruifengv <[email protected]> * ci: release packages (#5192) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(kap-server): resume sessions with unavailable models (#5212) * fix(kap-server): resume sessions with unavailable models * fix: let users replace unavailable session models * fix: scope unavailable model recovery state --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(plugins): detect MCP OAuth with targeted probes (#5197) * fix(plugins): detect MCP OAuth with targeted probes * fix(plugins): use the MCP inspect route * fix(plugins): preserve OAuth requirements across inspection and disconnect * fix(chat): show pending MCP browser authorization (#5246) * fix(chat): show pending MCP browser authorization * fix(chat): resolve MCP authorization lint findings * fix(chat): preserve MCP authorization failure details * fix(mcp): preserve cancellation during OAuth reconnect * fix(desktop): cache feedback form per host and let reply reasons wrap (#5303) * ci: release packages (#5232) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * test: port removed-model recovery coverage to testkit * test: dedupe anthropic output ceiling cases --------- Co-authored-by: Haozhe <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: 7Sageer <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: liruifengv <[email protected]> Co-authored-by: qer <[email protected]> Co-authored-by: kai <[email protected]> Co-authored-by: Luyu Cheng <[email protected]> Co-authored-by: grapedge <[email protected]>
Requirement or Bug
Web, desktop, and KAP clients can receive
Turn <n> was not foundwhen forking a restored session at a specific turn if its history contains in-turn steering. This PR letsturn_indexconsistently use the liveturn_numberreturned by the turns API.No external issue was provided; the reproduction and root cause are included below.
Bug Reproduction Steps
skill_activationsteer withorigin.inTurn: truein the first turn.turn_number3.:forkwith{ "turn_index": 3 }.Before this change, fork returned 40001 because it searched the raw append log, which only contained turn IDs 0 and 1. After this change, fork succeeds and the forked session restores with the same final live turn number 3.
Root Cause
The restore path normalizes persisted
turn.steerrecords intoturn.endedplus a newturn.prompt, which is the intended steering migration. Historical and running fork instead read unnormalized append-log records before slicing, so they looked up a live turn number in a different numbering space.This is a fundamental fix at the fork input boundary: fork now applies the same normalization as restore before pending-work trimming and turn slicing. Restore semantics and the source session's append log are unchanged.
Code Changes
packages/agent-core-v2/src/workspace/sessionLifecycle/sessionLifecycleService.ts: normalize the main agent's restorable wire records for turn-indexed and running forks before using the existing slicing functions. Full forks keep their existing copy path, and only the forked copy contains the normalized slice.packages/kap-server/test/sessions.test.ts: extend an existing fork test without increasing the test declaration count. Cover both user andskill_activationin-turn steers, close/resume, the live turn number, fork, and restoration of the new session while retaining the existing incompatible-source assertions..changeset/fix-fork-restored-steers.md: add patch changesets for@moonshot-ai/kimi-codeandkimi-code-app.Behavior Changes and Affected Users
turn_numberand creates the fork at the same restored turn/fork,/btw, and full-session KAP fork callersCoverage for the turn-indexed behavior is the KAP regression described above, including restoration of the forked session. The running-fork path shares the same normalized input and existing slicing functions; no new dedicated active-steer case was added. Existing full-fork assertions in
sessions.test.tscontinue to pass.Validation on the final
release/2026-11-20tree:packages/kap-server/test/sessions.test.ts: 114/114 passed. The new regression returned 40001 before the implementation change and passed afterward.agent-core-v2andkap-serverTypeScript checks passed.pnpm lintpassed, including comment checks, type-aware oxlint, import boundaries, guards, ratchet, and instruction checks.pnpm changeset statuspassed and selected patch bumps for CLI and desktop.git diff --checkpassed.vitestwas unavailable). Windows-specific verification was not applicable to this platform-independent change.Checklist
pnpm changeset status.