Skip to content

fix(agent-core-v2): seed the activity view's lastTurn from the persisted turn.ended record - #2648

Merged
wbxl2000 merged 6 commits into
mainfrom
fix/activity-view-seed-last-turn
Aug 5, 2026
Merged

fix(agent-core-v2): seed the activity view's lastTurn from the persisted turn.ended record#2648
wbxl2000 merged 6 commits into
mainfrom
fix/activity-view-seed-last-turn

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

A cold-resumed agent seeds its AgentActivityView only from live loop/task state (seedFromLoop / seedFromTasks / seedFromFullCompaction). The lastTurn outcome survives only as in-memory fold state, so a server restart wipes it: a session whose last turn failed (e.g. sustained provider 429 exhausting step retries) comes back from resume with lastTurnReason: undefined, and clients cannot surface the failure — the desktop/web conversation sits silently idle exactly like the original dead session did.

Fix

Two small pieces on top of the existing persisted turn.ended wire record:

  • TurnModel folds the latest turn.ended op into a new lastEnded state field (turnId / reason / durationMs). The op was already persisted for the transcript cold fold; the model just didn't retain it.
  • AgentActivityView.seedFromLoop adopts lastEnded as lastTurn when no turn is active, so the session work aggregate (ISessionActivityViewlast_turn_reason on the wire) reflects the last turn's outcome again after a cold start.

Live behavior is untouched: a running turn still seeds the active slice and returns early; live turn.ended events keep overwriting lastTurn as before.

Tests

  • New cases in test/agent/activityView/activityView.test.ts: seeds lastTurn from the wire model on cold resume; stays empty when the wire has no ended turn.
  • Full agent-core-v2 suite: 4714 passed; repo lint 0 errors; kap-server typecheck clean.

Downstream

The desktop app (kimi-code-app) renders a persistent failed-turn card off lastTurnReason — this restores it across server restarts. A submodule bump there will follow once this lands.

…ted turn.ended record

A cold-resumed agent seeded its activity view only from live loop/task
state, so the last turn's outcome was lost on a server restart: sessions
came back with no lastTurnReason, and clients could not surface a
previously failed turn (e.g. a provider 429 that killed the turn before
the restart).

The loop already persists the terminal turn.ended record (reason, error,
durationMs); fold the latest one into the TurnModel as lastEnded and have
AgentActivityView.seedFromLoop adopt it when no turn is active, so the
session work aggregate (and everything built on it) reflects the last
turn's outcome again after a cold start.
@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 64fbcea

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026

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

commit: 64fbcea

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 301e1b6f4e

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/activityView/activityViewService.ts Outdated
Review follow-up: the agent scope (and with it this view) is constructed
before wire.restore() replays the journal, so a constructor-time read of
TurnModel.lastEnded always saw the initial state on a cold resume. Move
the wire-backed seed behind the onDidRestore hook (constructor seed kept
for views built after a restore), and drop the inline comments in favor
of the file header per the package comment convention.
@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Both review findings addressed in 2e2a69f:

  • P1 (seed after wire restore): confirmed — the agent scope is constructed before wire.restore() replays the journal, so the constructor-time read always saw the initial model on a cold resume. The lastTurn seed now runs on the onDidRestore hook (the constructor seed is kept, guarded, for views built after a restore), with a regression test covering the construction→restore ordering and one covering that a live turn.ended is never overwritten by the restore fold.
  • P2 (comment convention): inline comments removed; the rationale now lives in the file header, and the collaborator list mentions the IWireService restore hook.

Also added the missing changeset (@moonshot-ai/kimi-code patch). Full agent-core-v2 suite: 4716 passed.

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e2a69f207

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/activityView/activityViewService.ts Outdated
…rators

Review follow-up: the previous revision narrated the restore-hook
mechanics in the header; the package convention keeps headers at the
module's external role plus collaborators, so drop the implementation
narrative.
@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Header trimmed in 2f2b64f — now states only the module's role and the collaborator (IWireService / wire TurnModel), with the restore mechanics left to the code. activityView tests (11) and typecheck pass.

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f2b64f472

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/loop/turnOps.ts
Review follow-up: advanceTurnClock built a fresh state object without
spreading, so a new prompt or a queued cancel silently dropped the stored
last-ended outcome even though no new turn had ended — after a restart the
activity view would again find nothing to seed. Spread the prior state and
cover the prompt/queued-cancel/replace cycle with a model-level test.
@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Queued-cancel finding addressed in 4df2882: advanceTurnClock now spreads the prior state, so turn.prompt / queued turn.cancel no longer erase lastEnded — the stored outcome is only replaced by the next turn.ended. Covered by a model-level test (prompt → failed → prompt → queued cancel → completed). Full suite: 4717 passed; the single failure is the known-flaky fs-watch workspaceResources case (passes in isolation, untouched by this change).

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4df2882475

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/loop/turnOps.ts
…tarts

Review follow-up: with the clock advances preserving lastEnded, a prompt
persisted without its turn ever starting would leave the previous turn's
outcome to be seeded after a restart, reporting a stale result for a turn
that never ended. The loop-event fold now drops lastEnded as soon as a
newer turn's events land, while prompts and queued cancels keep it.
@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Stale-outcome finding addressed in 27eceb1: prompts and queued cancels still preserve lastEnded, but the loop-event fold now clears it as soon as a newer turn's events land — so after a restart the seeded outcome always names the most recently ended turn, never a stale result for a turn that never started. Model-level tests cover the prompt/queued-cancel preservation and the clear-on-newer-turn cases.

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27eceb1436

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/loop/turnOps.ts Outdated
Review follow-up: the lastEnded keep/clear mechanics read as
implementation narrative in the header; the convention there is role and
collaborators only.
@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 64fbcea446

ℹ️ 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".

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 64fbcea446

ℹ️ 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".

@wbxl2000

wbxl2000 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 64fbcea446

ℹ️ 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".

@wbxl2000
wbxl2000 merged commit d1ded01 into main Aug 5, 2026
14 checks passed
@wbxl2000
wbxl2000 deleted the fix/activity-view-seed-last-turn branch August 5, 2026 17:07
@github-actions github-actions Bot mentioned this pull request Aug 5, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
…ted turn.ended record (MoonshotAI#2648)

* fix(agent-core-v2): seed the activity view's lastTurn from the persisted turn.ended record

A cold-resumed agent seeded its activity view only from live loop/task
state, so the last turn's outcome was lost on a server restart: sessions
came back with no lastTurnReason, and clients could not surface a
previously failed turn (e.g. a provider 429 that killed the turn before
the restart).

The loop already persists the terminal turn.ended record (reason, error,
durationMs); fold the latest one into the TurnModel as lastEnded and have
AgentActivityView.seedFromLoop adopt it when no turn is active, so the
session work aggregate (and everything built on it) reflects the last
turn's outcome again after a cold start.

* fix(agent-core-v2): seed lastTurn on wire restore and add a changeset

Review follow-up: the agent scope (and with it this view) is constructed
before wire.restore() replays the journal, so a constructor-time read of
TurnModel.lastEnded always saw the initial state on a cold resume. Move
the wire-backed seed behind the onDidRestore hook (constructor seed kept
for views built after a restore), and drop the inline comments in favor
of the file header per the package comment convention.

* docs(agent-core-v2): trim the activityView header to role and collaborators

Review follow-up: the previous revision narrated the restore-hook
mechanics in the header; the package convention keeps headers at the
module's external role plus collaborators, so drop the implementation
narrative.

* fix(agent-core-v2): keep TurnModel.lastEnded across clock advances

Review follow-up: advanceTurnClock built a fresh state object without
spreading, so a new prompt or a queued cancel silently dropped the stored
last-ended outcome even though no new turn had ended — after a restart the
activity view would again find nothing to seed. Spread the prior state and
cover the prompt/queued-cancel/replace cycle with a model-level test.

* fix(agent-core-v2): clear the stored turn outcome once a newer turn starts

Review follow-up: with the clock advances preserving lastEnded, a prompt
persisted without its turn ever starting would leave the previous turn's
outcome to be seeded after a restart, reporting a stale result for a turn
that never ended. The loop-event fold now drops lastEnded as soon as a
newer turn's events land, while prompts and queued cancels keep it.

* docs(agent-core-v2): keep the turnOps header at the domain role

Review follow-up: the lastEnded keep/clear mechanics read as
implementation narrative in the header; the convention there is role and
collaborators only.
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.

1 participant