Skip to content

🐛 fix(session): linearize close and invocation admission - #331

Merged
zrr1999 merged 1 commit into
mainfrom
codex/fix-compact-authority
Aug 13, 2026
Merged

🐛 fix(session): linearize close and invocation admission#331
zrr1999 merged 1 commit into
mainfrom
codex/fix-compact-authority

Conversation

@zrr1999

@zrr1999 zrr1999 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

动机

Session close、Invocation admission 与 Loop materialization 原先跨越独立的 registry、SQLite 与 scheduler 边界。close 可能在迟到的 Invocation 或仍存活的 executor 持有 Session 时完成 archive/redaction,也可能让 Loop 或 Hub delivery 清理永久阻塞。

解决方案

  • 将 Session lifecycle mutation 与 Invocation/Loop admission 串行化,并用 open lifecycle 与 incarnation 约束 transcript mutation。
  • 让 close 可合并、可重试;跨 executor 尾部保留 semantic completion receipt,并把子 Session 清理继续传播到 closing parent。
  • 停止 Session 所拥有的 Loop,在 admission 开放前修复历史 closing/closed 内容,并保留和清理全部 synthetic execution route。
  • 将 Hub delivery retention 限定到当前可达 uplink 与 active workspace route;terminal ACK 后重试清理,并在 shutdown 时有界排空 worker。
  • 保持 expand-only 与 N-1 数据库兼容;现有 legacy delivery index 不变。

说明

本 PR 是 Native Stack #313 的顶层,基于 #340 合入后的最新 main,包含剩余的 lifecycle/admission 正确性修复。没有破坏性数据库迁移;唯一 schema 增量是 additive Loop-owner expression index。

@zrr1999
zrr1999 marked this pull request as ready for review August 12, 2026 11:39
@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks


Comparing codex/fix-compact-authority (64724c9) with main (a78783e)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8ac6e7e) during the generation of this report, so a78783e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from 1a9a0c2 to 5257372 Compare August 12, 2026 12:09
@zrr1999
zrr1999 changed the base branch from main to codex/role-session-lifecycle August 12, 2026 12:09
@zrr1999 zrr1999 closed this Aug 12, 2026
@zrr1999 zrr1999 reopened this Aug 12, 2026
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from 05ea09e to 40fcb52 Compare August 12, 2026 13:07
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from fb416f3 to 1a71aa6 Compare August 12, 2026 13:44
Base automatically changed from codex/role-session-lifecycle to main August 12, 2026 13:50
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch 6 times, most recently from 1a18a25 to a260a41 Compare August 12, 2026 14:32
@zrr1999 zrr1999 closed this Aug 12, 2026
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 zrr1999 reopened this Aug 12, 2026
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from a260a41 to ccd863d Compare August 13, 2026 04:42
@zrr1999 zrr1999 changed the title 🐛 fix(session): make overflow compaction canonical and durable 🐛 fix(session): refresh transcript before close Aug 13, 2026
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from ccd863d to 1aace84 Compare August 13, 2026 05:13
@zrr1999 zrr1999 changed the title 🐛 fix(session): refresh transcript before close 🐛 fix(session): linearize close and invocation admission Aug 13, 2026
@zrr1999
zrr1999 force-pushed the codex/fix-compact-authority branch from 1aace84 to 64724c9 Compare August 13, 2026 09:10
@zrr1999
zrr1999 merged commit 0275407 into main Aug 13, 2026
19 checks passed
@zrr1999
zrr1999 deleted the codex/fix-compact-authority branch August 13, 2026 10:18
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