Repository navigation
fix(session): herdr 等后端的 persistent_backend_target 不再被会话契约拒绝或延后 - #3308
Merged
Merged
Conversation
worker 在 spawn 前发出 persistent_backend_target,让 daemon 先记下所选 agent/pane, 用来关闭「agent 已建但 daemon 只知道 bmx-*」的崩溃窗口。该消息没进会话契约的 worker 级事件白名单: - 新话题带首条消息时,信封里带着尚未绑定 runtime 的 execution,replay 阶段被网关以 execution_scope_unproven 拒掉(只打 debug),会话库 row 永远没有 persistentBackendTarget, daemon 重启后探不到 bmx-*,只记 lazy cold-resume、不挂 worker,窗格里的 CLI 不会被空闲回收; - 即使不带首条消息,也会被推迟到 runtime_binding(spawn 之后)才落地,违背「spawn 前落地」。 把它当作 worker 范围事件:加入网关 workerEvents,并在 ingest 里和 ready 等一样不推迟。
nengqi
requested review from
47seek,
LucasIcarus,
deepcoldy,
xiaoxueSunn and
xiongz-c
as code owners
November 10, 2026 10:38
Owner
|
感谢贡献,PR 已 squash 合入 master。 排查和修复都很扎实:现象、根因(控制器 defer + 网关 execution_scope_unproven 两道关卡)、两处白名单缺一不可的关系写得清楚,新增的契约测试覆盖了「无首条消息 / 带已 admit 首条消息」两个场景,且在 spawn 前落地的时序上有专门断言。 两个不阻断的后续改进建议,供参考:
欢迎继续贡献。 |
deepcoldy
pushed a commit
that referenced
this pull request
Nov 11, 2026
同步 master(含 #3308)后,persistent_backend_target 用例的精确事件序列 与本 PR 在 reservation 后、spawnCliBody 前强制广播的 capture_identity 共存:新序列为 runtime_binding_started → capture_identity → persistent_backend_target → runtime_binding,放宽断言并注释顺序意图。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@nengqi @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 c100770…8ec203230(5 个提交),同批合入的还有 #3299 #3324 #3306 #3301,失败不一定由本 PR 引起。
|
This was referenced Nov 11, 2026
|
🚀 Released in v3.59.2 |
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.
Fixes #3261
现象
3.59.0 起,Herdr 后端新开的会话在会话库 row 里一直没有
persistentBackendTarget(3.58.0 开的都有{"backendType":"herdr","sessionName":…,"agentName":"botmux-…"})。本机升级后新开的 20 多个会话全空;对一个新会话每 100ms 轮询 row,从建会话到关闭都没出现过,deferred_events表也是空的。后果:daemon 重启后按
bmx-<sid8>去探,找不到,只记herdr backing session "bmx-…" is missing — keeping active for lazy cold-resume,不挂 worker;可共享 host 里那个 agent 窗格的 CLI 还开着。空闲回收只扫有 worker 的会话,这些窗格不会被回收,botmux suspend也会跳过;再来消息时冷恢复出第二个 CLI。原因
worker 在
spawnCli里先beginRuntime开一个绑定,再在 spawn 前发persistent_backend_target,信封带bindingId、没有scope.runtime(新话题带首条消息时还带着scope.execution)。SessionController.ingest:绑定还没有 identity,这个类型不在不推迟的名单里,于是deferEvent,等runtime_binding(spawn 之后)再重放。这已经违背 worker.ts 那段注释的本意:要在 spawn 前落地,关掉「agent 已建好、daemon 只知道 bmx-*」的崩溃窗口。SessionEventGateway.admit只对workerEvents放行,于是返回execution_scope_unproven,只打 debug,case 'persistent_backend_target'没执行。不带首条消息的启动不会被拒,但要等 spawn 之后才落地。
改了什么
把
persistent_backend_target当 worker 范围事件,和ready、turn_input_received一样:session-event-gateway.ts:加进workerEvents。session-controller.ts:加进绑定未就绪时不推迟的名单。两处缺一不可:只改网关,第一步仍会推迟;只改控制器,网关会以
runtime_scope_missing拒掉。影响面
!runtime分支要求sameWorker(state.worker, channel),handleLegacyWorkerMessage开头还有ds.worker !== worker);已 abandon 的绑定照旧以runtime_reservation_abandoned拒。ds.session.persistentBackendTarget,没有生命周期副作用;首次启动、重启、resume、reattach、Herdr 换窗格重试都走同一个发送点。测试验证
test/persistent-backend-target-contract.test.ts:用真实的spawnCli/sessionEventMetadata、SessionController、SessionContractStore和 worker-pool 的handleWorkerMessage,CLI 启动打桩。两种启动(不带输入、带首条消息)各断言:消息送到 daemon handler、且在 runtime 绑定前就送到。未修复代码上 3/4 失败(带首条消息那条的 debug 是Scoped event rejected: persistent_backend_target execution_scope_unproven);只还原控制器 2 个失败、只还原网关 4 个失败。bun run typecheck、bun run build:通过。SessionController/SessionEventGateway/persistent_backend_target/persistentBackendTarget的 42 个测试文件:全过(2624 passed)。bun run test(2628 个文件):10 个文件 45 个用例失败。其中 9 个文件、45 个用例在 master(a09bc414f)上单独跑同样失败(tmux / bwrap / Bun SQLite / Riff 相关的环境原因);剩下的workspace-recycle-session-group.test.ts是收尾rmdir撞上 ENOTEMPTY,单独跑 10/10 通过。没有新增失败。