Repository navigation
refactor(kap-server): merge WebSocket session subscriptions into subscribe_v2 - #4470
Conversation
…cribe_v2
Drop the raw `subscribe` / `unsubscribe` path together with its seq/epoch
journal, cursor replay, `resync_required`, agent filters and legacy-event
suppression. `subscribe_v2` is now the only session subscription and carries
transcript streams plus interactions; reconnecting clients resubscribe and
receive a fresh `transcript.reset`.
`event.session.work_changed` becomes an App-level push to every connection,
tracked for every live session instead of only subscribed ones.
Remove `GET /sessions/{id}/snapshot`, the session `last_seq` field and
`server_hello.max_event_buffer_size`. The legacy journal directory on disk is
left untouched.
klient e2e: the harness subscribes with `subscribe_v2` and waits on
`work_changed`; drop the replay suite and the suites that depended on the
removed debug prompt endpoints.
Codex Review SummaryThis 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. |
🦋 Changeset detectedLatest commit: d64b440 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 |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e696c9abc1
ℹ️ 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".
code-app: 7ac243c1a817e0cf329c6b0dc25016006d5f5286
|
@codex review Changes since the last review:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddde2fd2e5
ℹ️ 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".
|
@codex review Changes since the last review:
|
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
…cribe_v2 Port of upstream MoonshotAI/kimi-code 8535bd7 (MoonshotAI#4470). The raw `subscribe` / `unsubscribe` path is gone together with its seq/epoch journal, cursor replay, `resync_required`, agent filters and legacy-event suppression. `subscribe_v2` is now the only session subscription and carries transcript streams plus interactions; a reconnecting client resubscribes and receives a fresh `transcript.reset` instead of replaying from a cursor. Global push events such as `event.session.work_changed` reach every open connection without a session subscription first. Removed with it: `sessionEventJournal`, `inFlightTurnTracker`, `subagentRosterTracker`, `GET /sessions/{id}/snapshot` and its `rest-snapshot` protocol, the `seq`/`epoch`/`offset` envelope fields, `server_hello.max_event_buffer_size`, the session `last_seq` field, and the `at_seq` field of the abort ack. Local shape notes: this tree's `sessionEventBroadcaster` also serves the agent/usage/goal/todo frames, the task frames and the interaction frames added after upstream wrote this commit, so its own feeds stay and only the journal-backed event pipeline is dismantled. The broadcaster keeps a local `EventEnvelope` without the sequence fields, and `agentEventSchema` stays as the internal stream union for the turn/roster bookkeeping the broadcaster no longer does but the v1 event types still describe. Verified: kap-server 1305 pass / 9 skip / 0 fail across 64 files, transcript 154 pass, klient and apps/kimi-code typechecks clean, oxlint --type-aware 0 errors, check:no-comments / check:deep-imports / check:no-hardcoded-prose green. The apiSurface snapshot is regenerated.
Requirement or Bug
把 WebSocket 的两套会话订阅合并成一套:删除原始
subscribe路径及其 seq / 回放机制,subscribe_v2成为唯一的会话订阅。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
服务端以前同时维护两套会话订阅:
subscribe:推送原始 agent 事件,带 seq / epoch 事件日志、游标回放、resync_required、agent_filter,以及"被转录流覆盖的事件要抑制"的表。subscribe_v2:推送转录流。客户端已经全部改用转录流和
work_changed(code-app 侧见 kimi-code-app#1002),原始路径只剩维护成本,这次整条删掉。文件树:
广播器在每个连接上的状态:
连接上的订阅表从
{ agentFilter, transcriptGrades }收窄为每个会话一个TranscriptGradeSpec。unsubscribe_v2按 agent 退订后如果一个 agent 都不剩,就整个取消该会话的订阅。session_id: '__global__'的外层,payload 里仍带{ agentId: 'main', sessionId: '__global__' }。event.session.archived/deleted的外层session_id仍是__global__,与改动前一致。client_hello的 schema 仍是非严格的 zod,旧客户端多带的字段会被忽略。~/.kimi-code/server/events/不再读写,也不删,启动和删除会话时都不碰。subscribe_v2;新增runUntilIdle,靠work_changed先忙后闲来判断 prompt 和 compaction 完成。refresh-replay。send-and-cancel和prompt-queue-steer:它们依赖的/debug/prompts/*已在 feat(server): default to kap-server and remove the v1 server package #1617 删除,一直处于跳过状态,而且只靠原始事件判断。server-api.md同步更新。apps/kimi-code/dist-web用上述 code-app 构建替换,只更新产物,不附 web 汇总 changeset。Behavior Changes and Affected Users
subscribe/unsubscribe帧subscribe_v2turn.*、assistant.delta、tool.*、prompt.*、compaction.*、error/warning等)transcript.*与event.session.work_changedcursors回放缺口,否则收到resync_requiredsubscribe_v2,可带transcript_since续传转录,不带则收到新的transcript.resetGET /sessions/{id}/snapshotGET .../transcript与GET /sessions/{id}last_seq0server_hello.max_event_buffer_size1000client_hellosubscriptions/cursors直接订阅,确认后补发待处理交互subscribe_v2,确认后补发交互event.session.work_changedsession.created/session.meta.updatedevents/<id>.jsonlsubscribe_v2/unsubscribe_v2、interaction帧、转录协议受影响的客户端:
apps/kimi-code/dist-web提供。本 PR 一并替换了 dist:从 code-app7ac243c1a(code-app main 加上 Need multi repo support real bad #1002,即 Need multi repo support real bad #1002 rebase 后的 HEAD)构建,注入的 CLI 版本对应本分支。新 bundle 只用subscribe_v2,不含原始subscribe。client_hello和全局事件,不需要改。测试覆盖:
test/sessionEventBroadcaster.test.ts:work_changed(未订阅的会话、推给所有连接、启动时已存在的会话、关闭后重建、归档、last_turn_reason、后台任务、subagent);turn.started。test/wsConnectionV1.test.ts:client_hello的 ack 与忽略旧字段、忽略旧subscribe/unsubscribe、subscribe_v2/unsubscribe_v2的 ack 与状态、关闭连接时全部退订、server_hello不带缓冲大小。test/sessions.test.ts:会话对象没有last_seq。test/connections.test.ts:订阅关系的展示。test/workspaceLayout.test.ts:改用会话读取接口。test/__snapshots__/apiSurface.snapshot.test.ts.snap:路由表少了/snapshot。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.