Repository navigation
fix(agent-core-v2): stop rebuilding mismatched session indexes - #4980
Conversation
🦋 Changeset detectedLatest commit: 0b4ccec 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 |
|
@codex review |
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: 0b4ccec321
ℹ️ 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".
| if (slot !== undefined && (!slot.settled || Date.now() < slot.reusableUntil)) { | ||
| return slot.promise; |
There was a problem hiding this comment.
Avoid caching a rejected fallback scan
When an authoritative scan fails quickly—for example, an unguarded workspace mtime call rejects—this condition returns the already-rejected promise for every list or count request until the 30-second reuse deadline. Previously, a settled fallback scan was never reused, so a later request could recover immediately; clear the slot on rejection or reuse only successfully fulfilled scans.
Useful? React with 👍 / 👎.
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Keep session lists available when an older session index is present instead of rebuilding it. |
There was a problem hiding this comment.
Disclose the loss of immediate fallback freshness
This entry only says mismatched indexes stop rebuilding, but the same change also makes degraded or preparing list/count reads reuse a settled scan for 30 seconds, so sessions written by another process are no longer immediately visible and there is no escape hatch. Name that lost behavior in the user-facing changeset as required for removed existing behavior.
AGENTS.md reference: AGENTS.md:L114-L116
Useful? React with 👍 / 👎.
| manifest !== undefined && | ||
| manifest.schemaVersion !== SESSION_INDEX_SCHEMA_VERSION | ||
| ) { | ||
| this.markSchemaMismatch(); |
There was a problem hiding this comment.
Recheck the checkpoint schema after startup
When this process becomes ready before an older concurrent process publishes its checkpoint, doPrepare is not called again: both withReadModel and tick fetch the replacement manifest and use or reconcile its generation without checking schemaVersion. The targeted 2.5/2.6 startup order can therefore still make the fixed process query and mutate an incompatible index instead of switching to authoritative files; apply the mismatch transition whenever a checkpoint is fetched, not only during initial preparation.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
| manifest !== undefined && | ||
| manifest.schemaVersion !== SESSION_INDEX_SCHEMA_VERSION | ||
| ) { | ||
| this.markSchemaMismatch(); |
There was a problem hiding this comment.
Stop mirror flushes while the index schema is mismatched
After this branch permanently degrades the read model, ordinary local metadata writes still enter SessionIndexMirror; its flushChunk reads the mismatched manifest, writes current-version rows and counters into sessionCollection(manifest.seq), and then clears the pending entries. In the mixed-version scenario this process therefore mutates the index it is meant to leave untouched and can expose incompatible records to the version that owns it; gate mirror flushes on the manifest schema while preserving pending updates.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b4ccec321
ℹ️ 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".
| if (slot !== undefined && (!slot.settled || Date.now() < slot.reusableUntil)) { | ||
| return slot.promise; |
There was a problem hiding this comment.
Keep local writes overlaid for the cache lifetime
When a compatible read model is temporarily degraded and a local session create/update occurs after a fallback scan, the mirror initially keeps that change in pending(), but its 100 ms flush removes the pending entry; this branch then reuses the pre-write summaries for up to 30 seconds. Desktop, Web, and TUI session-list clients can therefore see their own new or updated session briefly and then see it disappear until the scan expires, whereas settled fallback scans were not reused before this change. Invalidate the cached scan when local mutations flush, or retain an equivalent overlay for the entire reuse window.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
* fix: resume sessions with removed default models (#4982) * fix(node-sdk): resume sessions with missing default model * fix(cli): check auth for the resumed session model * chore: add changeset for unavailable model recovery * fix(agent-core-v2): stop rebuilding mismatched session indexes (#4980) * fix(agent-core-v2): reject repeated model responses (#4977) * fix(agent-core-v2): reject repeated model responses * chore: add changeset for repeated model responses --------- Co-authored-by: 7Sageer <[email protected]> * fix(agent-core-v2): inline deferred tools without dynamic loading (#4971) * fix(agent-core-v2): record restored task notifications without model requests (#4949) (#4989) * fix(agent-core-v2): record restored task notifications without model requests - queue restored task notifications as prompt-only turns after loop initialization - preserve interrupted and queued turns during resume and fork - complete reconciliation before initialization and reset return to keep Wire reads ordered - run loop and container cleanup when reconciliation fails - surface restored notification persistence failures * chore: add changeset for restored task notifications * fix(agent-core-v2): restore overflow recovery after LLM retries (#4950) (#4990) * fix(agent-core-v2): restore step state after LLM retries * test(agent-core-v2): scope retry event to overflow regression * fix(config): allow sessions with invalid user config (#4951) (#4991) * fix(agent-core-v2): tolerate config read failures for permission rules * chore: add changeset for permission config recovery * docs: document permission config recovery * docs: qualify permission config recovery scope * fix(config): surface read error diagnostics * fix(config): allow sessions with invalid user config * fix(config): preserve valid values and replay diagnostics * fix(config): remove startup diagnostic replay * fix(agent-core-v2): ignore non-user prompts during Tower wake (#4952) (#4992) * fix(agent-core-v2): ignore non-user prompts during Tower wake * chore: add Tower notification fix changeset * fix(agent-core-v2): preserve slash prompts during Tower wake * fix(agent-core-v2): route foreground shell events by origin (#4954) (#4994) * fix(agent-core-v2): route foreground shell events by origin * test(agent-core-v2): expect tool event origins in snapshots * fix(klient): accept tool events from pre-origin hosts * fix(agent-core-v2): run external Stop hooks after turn completion (#4956) (#4995) * fix(agent-core-v2): run external Stop hooks after turn completion * chore: add changeset for external Stop hooks * docs: clarify post-turn Stop hook timing * fix(agent-core-v2): wait for subagent quiescence (#4953) (#4993) * fix(agent-core-v2): reject incomplete model streams (#5006) * fix(agent-core-v2): preserve choice-level OpenAI token usage (#5017) * fix(capability): confirm stopping WebBridge before Windows updates (#4999) * fix(capability): confirm stopping WebBridge before Windows updates * fix(capability): harden WebBridge update recovery * fix(capability): restore WebBridge after startup failure * fix(capability): wait for WebBridge process exit * fix(capability): handle WebBridge confirmation edge cases --------- Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> * chore: sync release 2.6.3 back to main * chore: finish release 2.6.3 backsync * chore: sync node-sdk lockfile importer * fix(sdk): preserve main core type dependencies * fix: complete release 2.6.3 backsync --------- Co-authored-by: Haozhe <[email protected]> Co-authored-by: 7Sageer <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]>
Requirement or Bug
会话很多、并且 2.5 与 2.6 进程同时运行时,共享会话索引的 schema 版本不一致会让进程反复全量重建。重建把 16 个 shard 的索引装进 V8 堆,约 8000 个会话可在一分钟内触及约 4GB 堆上限。这个 PR 让版本不一致的进程直接提供文件索引,停止重建循环。
Bug Reproduction Steps
Root Cause
prepare看到 checkpoint 的schemaVersion与当前版本不一致时,直接执行全量投影。新旧进程共享同一套索引,于是 v2 与 v3 来回重建。这是止血,不是最终修复。版本不一致时不再重建;后续会移除 Minidb 会话读模型。
Code Changes
schema 不匹配时,进程标记为稳定降级,不再调用投影:
降级后的列表、计数和按 ID 查询继续走文件路径,并在 30 秒内复用同一次目录扫描:
Behavior Changes and Affected Users
受影响模块是
agent-core-v2的会话索引。测试覆盖:Performance Benchmark
在 Linux 压测环境中使用真实
FileSessionIndex、JsonAtomicDocumentStore、FileStorageService和 16 分片 MiniDb,构造 8,000 个会话、80 个工作区,对比 base5af9942与本 PR0b4ccec。每个进程使用独立数据目录和异版本 checkpoint,关键场景运行 3 轮取中位数;模拟 Desktop 的 2 页分组读取,以及重连时按每页 100 条拉取全部 8,000 个会话。prepareprepare扫描 / 索引写入PR 的首次分组读取承担了一次真实文件扫描;连同
prepare计算,首轮总耗时约 820 ms,base 的重建与首次分组约 1,407 ms。之后 30 秒复用窗口内,80 页重连拉取没有再次访问会话文件。缓存过期且
scan.json全部命中时,2 页分组读取约 326–348 ms,检查 16,000 次文件状态,未重新读取或解析state.json;随后 80 页重连拉取约 65 ms。正常 schema 匹配时,80 页 MiniDb 查询仍约 500 ms,这条路径不在本 PR 改动范围内。已存在完整 MiniDb 时,PR 进程仍约 250–264 MB RSS,说明它停止继续重建,但不会消除打开已有索引的成本。这是核心存储路径基准,未运行完整 Electron 双版本进程,也未模拟旧代际残留、锁冲突、长会话恢复和 WebSocket 重连风暴;结果验证 MiniDb 会话索引链路的性能改善,不将其等同于完整故障现场的 4 GB 堆峰值验证。
Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.