Skip to content

feat(offload): add cache epoch task snapshots#447

Open
quan020406 wants to merge 2 commits into
TencentCloud:mainfrom
quan020406:feat/cache-epoch-task-snapshots
Open

feat(offload): add cache epoch task snapshots#447
quan020406 wants to merge 2 commits into
TencentCloud:mainfrom
quan020406:feat/cache-epoch-task-snapshots

Conversation

@quan020406

@quan020406 quan020406 commented Jul 9, 2026

Copy link
Copy Markdown

Description | 描述

本 PR 从 #410 中拆分,仅聚焦 cache epoch / task snapshot 辅助逻辑。

主要改动:

  • 新增纯函数 Cache Epoch 合约:初始化、阈值判断和 epoch 转换。
  • 新增 Task Snapshot/Delta helper,首次记录 compact snapshot,后续变化追加 delta。
  • MMD 更新改为 append-only,不再覆写历史 _mmdContextMessage
  • 完整 Mermaid 内容写入现有 ref 存储,prompt 中保留 hash、文件信息和 ref。
  • 使用完整内容 SHA-256 指纹检测 MMD 变化,并维持累计 MMD token 统计。

不包含以下内容:

  • tdai_offload_read
  • 工具结果卸载/恢复
  • recall mode
  • recall injection placement / injected history cleanup

Related Issue | 关联 Issue

Related to #120

#410 拆分,按评审意见收敛为独立的 cache epoch / task snapshot PR。

Change Type | 修改类型

  • Bug fix | Bug 修复
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过
  • No existing features affected | 无影响现有功能

验证命令:

  • npm.cmd test
  • npm.cmd run build:plugin
  • node --check dist\index.mjs
  • git diff --check

验证结果:

  • 6 个测试文件、70 个测试通过。
  • 插件构建通过。
  • dist/index.mjs 语法检查通过。
  • diff whitespace 检查通过。

Additional Notes | 其他说明

该 PR 与 #375 独立,评审范围限定在 cache epoch 与 task snapshot 辅助逻辑本身,不包含工具结果卸载/读取或 recall mode 相关改动。

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

@YOMXXX YOMXXX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I cannot approve this as-is.

The append-only MMD change removes the existing cleanup/replacement guarantees without adding a bounded stale-context policy:

  • injectMmdIntoMessages() no longer removes _mmdContextMessage entries when MMD injection is not ready, or when the active MMD cannot be read. The current main branch clears those messages and resets lastMmdInjectedTokens in that path, which prevents stale task context from remaining in the prompt after the active task boundary is gone or not settled.
  • The active MMD path now appends another marked user message instead of replacing the previous active message. after_tool_call previously updated the single active message in place; this PR can accumulate multiple task snapshot/delta messages in event.messages/historyMessages while those messages are intentionally skipped by compression. That creates an unbounded prompt-growth path and can keep obsolete task context visible to the model.
  • The new tests only cover pure helpers. They do not cover the regression cases above: injection-ready false after a previous MMD message exists, active file disappears/read returns null, repeated MMD changes across tool-loop updates, or the token count staying bounded.

Please keep the old cleanup/replacement invariant, or add an explicit bounded append-only policy with tests proving stale MMD messages are removed and prompt-visible MMD context cannot grow without limit.

@quan020406

Copy link
Copy Markdown
Author

Addressed in 4e2734f.

The MMD path now restores the existing bounded lifecycle invariant:

  • stale marked MMD messages are removed and lastMmdInjectedTokens is reset when injection is not ready;
  • missing or unreadable active MMD files also clear stale prompt-visible context;
  • active MMD updates replace the single marked message rather than append additional messages.

Added regression coverage for injection becoming unavailable, unreadable active MMD content, and repeated MMD updates retaining exactly one active prompt message.

Validation:

  • npm.cmd exec vitest -- run src/offload/mmd-injector.test.ts src/offload/epoch-manager.test.ts src/offload/task-snapshot.test.ts
  • npm.cmd run build:plugin

@quan020406 quan020406 requested a review from YOMXXX July 11, 2026 08:18

@YOMXXX YOMXXX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1

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.

3 participants