🐛 fix(session): linearize close and invocation admission - #331
Merged
Conversation
zrr1999
marked this pull request as ready for review
August 12, 2026 11:39
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 12, 2026 12:09
1a9a0c2 to
5257372
Compare
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 12, 2026 13:07
05ea09e to
40fcb52
Compare
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 12, 2026 13:44
fb416f3 to
1a71aa6
Compare
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
6 times, most recently
from
August 12, 2026 14:32
1a18a25 to
a260a41
Compare
zrr1999
added a commit
that referenced
this pull request
Aug 12, 2026
## 动机 Provider 最终请求包含 system prompt、隐藏运行时消息和完整 tool schema;旧计量只看 transcript 消息,可能在请求已经超过模型 context window 时仍未触发压缩。TUI `/compact` 过去压缩 bounded visible projection,而不是 daemon 拥有的 canonical Session transcript,也会让同一领域形成两套状态路径。 ## 解决方案 - 在 provider stream 前计量完整 input envelope,并识别 `maximum prompt length` 类 overflow,统一进入 compact-and-retry。 - 将 output budget 按 assembled input 与 context window 算出唯一 effective 值;preflight hook 和实际 provider stream 使用同一值,避免检查与请求漂移。 - 新增 daemon-owned、local-only 的 `session.compact` durable operation;冻结 Session incarnation、模型与执行路由,通过 lease、CAS、幂等 operationId 和 durable commit fence 保护 transcript mutation、取消、超时及崩溃恢复。 - 将 canonical transcript 原子替换放进 daemon registry 的串行 mutation fence:archive 先赢则 replacement 不执行,compact 先赢则 atomic rename 完成后 lifecycle mutation 才继续。 - blank/unbound Session 的 compact 是不分配 JSONL 的 no-op;多层 compact 重压旧 summary 并继承 protected-recent 边界。 - 让 TUI `/compact` 只通过同版本 daemon client 提交 invocation,等待终态后从 `session.snapshot` 刷新;缺少该 client 属于装配错误并立即失败,不再提供 capability fallback 或旁路压缩。 - 清理绑定内部 prompt/prose/hash 形状的脆弱断言,改测状态、持久化结果和 provider/RPC 边界。 ## 说明 - 这是 #331 的 compact-only replacement;原分支持续被并发写入 close/discard 修复,导致 exact-head CI 反复失效。 - daemon 与 TUI 采用严格同版本契约;兼容逻辑不落入 daemon、TUI 或 surface。 - 协议变更为 additive local RPC;持久化复用现有 Session JSONL 与 Invocation event store,无数据库迁移。 - Session close/discard 的产品行为与 transcript 刷新修复不属于本 PR;这里只有 compact replacement 服从现有 registry lifecycle fence。 - 本地验证:新增 focused 6 files / 207 tests、`pnpm run typecheck`(Hub 0 diagnostics、1900 files、daemon 124 files / 959 tests)及 `prek run --all-files` 均通过;当前 head 为 `1a18a25c`。 ## 后续工作 本 PR 只完成 canonical compact 路径;其他 lifecycle、跨版本兼容与 surface 工作继续由各自 owner 的独立 PR 推进。
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 13, 2026 04:42
a260a41 to
ccd863d
Compare
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 13, 2026 05:13
ccd863d to
1aace84
Compare
zrr1999
force-pushed
the
codex/fix-compact-authority
branch
from
August 13, 2026 09:10
1aace84 to
64724c9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
Session close、Invocation admission 与 Loop materialization 原先跨越独立的 registry、SQLite 与 scheduler 边界。close 可能在迟到的 Invocation 或仍存活的 executor 持有 Session 时完成 archive/redaction,也可能让 Loop 或 Hub delivery 清理永久阻塞。
解决方案
说明
本 PR 是 Native Stack #313 的顶层,基于 #340 合入后的最新 main,包含剩余的 lifecycle/admission 正确性修复。没有破坏性数据库迁移;唯一 schema 增量是 additive Loop-owner expression index。