Skip to content

fix(#739): restore compression across restarts and within a frozen watermark - #1003

Closed
asuan-dev wants to merge 1 commit into
ranxianglei:masterfrom
asuan-dev:fix/739-restore-compression-across-restarts
Closed

asuan-dev wants to merge 1 commit into
ranxianglei:masterfrom
asuan-dev:fix/739-restore-compression-across-restarts

Conversation

@asuan-dev

Copy link
Copy Markdown

问题

omp(经 bili plugin install omp 接入)在模型切换或恢复会话后,压缩状态三连败:压缩 block 丢失、nudge 每轮重发、上下文只涨不降。#739。

根因(3 处,均已先复现再修复)

  1. 主/子代理身份隔离失效 — isRegisteredPluginConversation() 只检查 conversations.has(id),任何带 prompt_cache_key 的请求都会写入该表,导致 omp 主会话与 guardian 子代理共享同一份压缩状态。
  2. 映射会话状态未恢复 — 持久化映射可能是 conversationId -> conversationId|sub:oldFingerprint,原实现只检查映射存在、忽略存储的 sessionId,恢复时选中空的裸 id 会话(复现:旧 namespace 3 个 block,恢复后 0 个)。
  3. preflight 冻结 range 列表,失败后无法恢复 — preflightPin 冻结整个 range 列表,部分成功后重试 stale ranges,永远到不了 soft-protected-zone 释放。

修复

  • registeredPluginSessionId():只有真正的 omp 注册或持久化的 session.metadata.pluginAgent 才绕过子代理分区,返回映射后的 sessionId;裸 prompt_cache_key 不行(src/plugin.ts)。
  • server.ts:conversation/identity 选择采用 codexTurn?.value ?? registeredSessionId ?? protocol chain(bodyIdentity = responsesIdentity ?? openaiIdentity ?? anthropicIdentity)。
  • 映射会话恢复原始 session(含 |sub: namespace 和已持久化 blocks),而非新建空 session。
  • preflightPin 改存 endRef 水位(^m\d+$),每轮 fold 后重算 viableRanges、clamp endRef;非 abort 失败存 { endRef: watermark },payload 放得下时删除 pin。失败窗口内追加的 turns 不被吞。

验证

  • e2e tests/subagent-namespace.test.ts:注册 omp 跨 instructions 漂移恢复映射 blocks(3 block 持久化 → 恢复后 3 active,upstream payload < baseline 一半,resumed id = LEGACY_ID)。
  • e2e tests/preflight-fail-fast.test.ts:失败 preflight 在水位内恢复,soft-protected history(Message 7)可达,无消息被摘要两次,失败窗口 turn(FAILURE_WINDOW_NOISE)不进压缩输入。
  • typecheck clean;runtime 冒烟:compress + 切模型 + 代理进程重启,62,025B → 36,970B,originals 消失、summary 保留、1 active block。

4 个 stack PR 之一(此 PR 是 stack 底座)。#739 原始 issue 见 tracker。

…a frozen watermark

Three root causes behind "session hangs / context keeps growing after a
restart or model switch":

1. A plain prompt_cache_key is not plugin ownership. Only a real omp
   registration or a persisted pluginAgent may unwrap the |sub: namespace;
   otherwise instructions drift (model switch, async tool registration)
   forked the main conversation into an empty namespace whose compression
   state was gone, so every existing block was invalidated.
2. Existing conversation mappings now restore their original session and
   compression blocks instead of minting a fresh bare-id session.
3. A failed preflight freezes the original history BOUNDARY rather than
   the range worklist it happened to select: every successful fold changes
   which ranges stay viable, so replaying a stale worklist compressed
   nothing and the retry looked bigger. The walk now recomputes remaining
   viable ranges against that boundary after each fold, including the
   soft-protected recent zone under overflow, while turns appended during
   the failure window stay out of the compression input.

# Conflicts:
#	CHANGELOG.md
#	src/plugin.ts
#	src/preflight.ts
#	src/server.ts
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始 review PR #1003(fix/739-restore-compression-across-restarts)。初步观察:GitHub 报告该分支与 master 存在合并冲突(mergeable_state=dirty),且 head commit 尚无 CI 运行记录。正在本地拉取分支核对 diff、跑 typecheck/test/build,稍后给出完整结论。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

Review complete — code verified green on CURRENT master.

What I did:

  1. Fetched & reviewed the full diff (head eeaf10c from your fork). Base was stale: built on cc53ca0 (v0.1.123), while master had moved 5 commits (fix: single-writer plugin guard — never overwrite host-managed copies (#991) #995 single-writer plugin guard, release v0.1.124). The mergeable_state: dirty flag is caused by exactly ONE textual conflict — AGENTS.md: fix: single-writer plugin guard — never overwrite host-managed copies (#991) #995 inserted design-decision item 6, shifting your numbering. No code conflicts; zero file overlap between fix: single-writer plugin guard — never overwrite host-managed copies (#991) #995 and this PR.
  2. Rebased onto master@108c1fc and resolved the AGENTS.md conflict: kept fix: single-writer plugin guard — never overwrite host-managed copies (#991) #995's item 6, renumbered "Two compression modes" to 7, added your item as 8 — translated it to English to match the file's language (minor nit, fixed directly per house rules). Pushed as a ready-to-merge mirror branch: 2026-09-19_pr1003-rebased (commit cd08ba2). You can merge that branch directly, or rebase your own branch onto it.
  3. Full gate on the rebased head:
    • npm run typecheck — clean
    • npm test — 1963 tests, 1961 pass / 0 fail / 2 skipped (default e2e gates)
    • npm run build — success
    • Both new regression tests run explicitly and pass: "failed preflight resumes within its watermark without repeating completed chunks" and "registered omp restores mapped blocks from disk across instructions drift".
  4. Spot-checked the pin logic (src/preflight.ts:1032-1037): fits-window → pin deleted; non-abort failure → { endRef: watermark }; abort → prior pin retained (conservative). The watermark is fixed on the first round (max live ref), so turns appended during the failure window are never folded — matches the claim.
  5. CI note: the head commit has zero check-runs and zero commit statuses — Actions never ran on this fork PR, so the local gate above is the evidence of green.

Code-review verdict:

  • Root-cause analysis holds up; each of the three fixes maps cleanly to its repro.
  • registeredPluginSessionId() correctly narrows identity to a real omp registration or persisted session.metadata.pluginAgent, returns the mapped id (so subagent |sub: partitioning stays intact), and lets bare cache keys fall through to the protocol chain. Strictly narrower than the old conversations.has() check.
  • Server identity selection (codexTurn ?? registeredSessionId ?? protocol chain) keeps codex precedence; register consumption now keys off the identity conversation instead of the raw value. Reasoned in both compression modes: proxy-mode traffic is unaffected except when a client-provided key legitimately belongs to a registered omp conversation — same semantics as before, smaller set.
  • Diff is clean: 7 files, every line in scope, no lockfile/generated churn, CHANGELOG entry well-placed.

Per §7.4 this is not auto-merge eligible (identity/session-binding logic + preflight wire behavior) — human merge decision. Since this is the base of your 4-PR stack, recommend merging the rebased branch; #1004 will need its own rebase on top once this lands.

修复了 omp 在切换模型/恢复会话后压缩状态丢失的三连败(主/子代理身份隔离失效、映射会话恢复为空会话、preflight 冻结 range 导致失败后无法恢复);已 rebase 到最新 master 并本地全量验证通过(typecheck/test/build 全绿、两个新回归测试均通过),可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner

Closing as stacked — this is the base layer of @asuan-dev's chain: #1003 ⊂ #1004 ⊂ #1006 ⊂ #1008. All of this PR's commits are carried verbatim inside #1008 (e4a4700), which is the single tip PR that will be updated and merged. Closing here to keep the queue one-PR-per-change; nothing is lost. (Queue triage per #1020.)

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