Repository navigation
fix(agent): retire unreadable Bot worker watches and store only what a wake needs - #6627
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
I reviewed all four changed files at 17fa84a564c8a5ea2593c3396f6cce56fbd9a39c. I found one P2 upgrade regression: the new persisted Watch shape rejects watches that were valid immediately before this change, and active workers are skipped until another send replaces their record. The upgrade case is detailed inline.
The improvements to damaged-record handling are real: all records retain their revisions, missing/archived/non-child workers reach retirement before decoding, refreshing a damaged record no longer depends on decoding it, and decode/model-resolution failures are collected without stopping healthy workers. I checked the model reselection and notification path, including workspace/binding checks and notification identity handling. The per-worker in-memory error set is removed; the existing whole-pass error suppression now reports changes in the combined error.
I read the actual native logs for CI 41808555131: gone-worker retirement passed in 12.267 seconds, repair by a later send in 11.811 seconds, ordinary wake in 16.110 seconds and the busy-Bot case in 15.919 seconds. Those tests start with the new format or deliberately send again; they do not establish upgrade recovery for a live worker that finishes without another send. A small Rust decoding check using the exact new Watch declaration and opaque adapters for nested field types also rejects the old top-level route key. That check is limited to the storage shape, not a native Host integration run.
The actual Git merge against rust-preview at a08d327f19a0afd17dbe4c941123c06b4a46d871 succeeds. The exact-head CI's two composer failures are already present on that base after #6617, rather than evidence against these wake tests. I did not execute the full Rust native service, a desktop or a live provider. The AI declaration and required trailer are present.
Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.
| #[serde(deny_unknown_fields)] | ||
| struct Watch { | ||
| route: crate::owner::notifications::ReturnRoute, | ||
| model: ModelSelection, |
There was a problem hiding this comment.
P2: Migrate valid pre-upgrade watches before requiring the new shape.
The preceding build stores {"route": {...}, "notified": ...} in this same namespace/key. This deny_unknown_fields decoder now rejects route and requires the new top-level model/workspace/binding fields, even when the old record was fully readable before upgrading. For a still-live child, wake_bot_pass collects that error and continues before looking at its completed invocation. If the Bot delegated work and is waiting for its result, there may be no later SessionSend to repair the watch, so the completion never wakes the Bot, across subsequent polls and restarts.
This affects valid existing watches, not just the already-damaged records from #6624. The new repair test explicitly sends again after corrupting a watch and therefore misses this upgrade path. Add a legacy decoder or migration that preserves the model selection, workspace/binding and notified marker, plus a regression that writes a valid old-format watch, upgrades/reopens, completes the worker without another send and observes exactly one wake.
Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.
There was a problem hiding this comment.
English
Thanks for following up on #6624! Retiring gone workers' watches before decoding, healing unreadable watches on refresh, removing Bot.unreadable, and decoupling Watch from ReturnRoute / AcceptedModel without adding legacy runtime compatibility branches (please disregard the earlier automated comment suggesting a legacy route decoder) all look clean and well-tested.
One small hot-path adjustment:
- Check Bot readiness before calling
Source::selectinwake_bot_pass(plugins/agent/native/src/owner/bot/wake.rs:318):
start_bot_wakeruns onstore.subscribe_changes()(coalesced at 250ms) as well as the 2s poll. Previously,wake_bot_passenteredprepare_notificationdirectly and hitruns.busy(&source.session_id) || self.has_parked_invocation(&source.session_id)at the top (notifications.rs:83-85), returningOk(None)without touching provider state. WithSource::selectplaced ahead ofprepare_notification, whenever a worker finishes while the Bot is in the middle of a Turn (or after an earlier worker in the same scan wakes the Bot), every 250ms commit pass runs a fullSource::select(cloning the catalog snapshot, reading/decrypting credentials fromConfigurationStore, and preparing provider/inventory material) only forprepare_notificationto immediately discard it because the Bot is busy.
Adding a quickif self.runs.lock().await.busy(&bot) || self.has_parked_invocation(&bot).await? { continue; }right beforeSource::select(after the gone-workerforgetandwatch.notifiedchecks) avoids that repeated work while keeping GC intact.
I'll push a small follow-up commit for this guard and merge directly.
简体中文
感谢跟进 #6624!先判活走 forget 回收、写入路径覆盖修复坏记录、移除 Bot.unreadable,以及在不引入旧格式兼容分支的前提下将 Watch 与 ReturnRoute / AcceptedModel 解耦(无需理会前面自动化评论关于添加旧 route 兼容解码器的建议),整体实现和测试都很干净。
只需顺手调整一处热路径顺序:
- 在
wake_bot_pass调用Source::select前先检查 Bot 是否空闲可唤醒(plugins/agent/native/src/owner/bot/wake.rs:318):
start_bot_wake除了 2s 轮询外还订阅了store.subscribe_changes()(250ms 合并)。改动前直接进入prepare_notification,在顶部(notifications.rs:83-85)命中runs.busy(&source.session_id) || self.has_parked_invocation(&source.session_id)就会零开销返回Ok(None);现在把Source::select提到了prepare_notification之前,只要有子会话在 Bot 正在执行一轮对话期间结束(或同轮扫描中前一个 worker 刚唤醒了 Bot),后续每次 250ms 事件提交都会对每个待汇报 worker 空跑一遍完整的Source::select(克隆目录快照、从ConfigurationStore读取解密凭据、准备 provider/inventory),紧接着又因 Bot 处于busy被prepare_notification丢弃。
在forget清理与watch.notified判断之后、Source::select之前先加一行if self.runs.lock().await.busy(&bot) || self.has_parked_invocation(&bot).await? { continue; }即可在保留 GC 的同时避免重复解析。
我直接补一个精简提交处理掉这里并合入。
Automated review generated by Antigravity.
…h, store only what a wake needs Follow-up to #6624, following the review there. - watches() returns each record's decode result. wake_bot_pass checks that the worker is alive first, so a watch of an archived or missing worker is retired without being decoded; for a live worker it collects the error, keeps waking the healthy ones and returns the combined error, which start_bot_wake already de-duplicates. The in-memory set of reported workers is removed. - Bot::watch reads the record itself, so a value that no longer decodes is replaced by the refresh with notified unset instead of failing every send. - A watch no longer embeds ReturnRoute and AcceptedModel. It keeps the model selection, thinking level, workspace, binding and notified, and the model is resolved with Source::select when the Bot is woken, so a later change to an accepted model cannot make stored watches unreadable. Generated-by: Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
Avoid running Source::select on every store-change pass for finished workers while the Bot Session is busy or parked on an interaction; dead-worker watch retirement above remains unaffected. Generated-by: Antigravity
17fa84a to
111a8b8
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
I checked the update at 111a8b8d24a831395786f4d59f242631fad3e63f. The original patch is equivalent to the previously reviewed 17fa84a5 after rebasing; the additional four lines defer model reselection while the Bot is busy or has a parked interaction. Retirement of missing/archived workers still occurs before that guard, and the existing notification admission checks remain in place. The wake loop retains both store-change and periodic retries. I found no additional confirmed P0–P2 in this increment.
The P2 upgrade issue in my earlier review remains: the persisted Watch declaration is byte-for-byte unchanged from that reviewed version and still rejects the preceding build's valid route-based records. A live worker's completion is skipped until another send replaces its watch. The new busy-Bot guard runs after decoding and does not repair or migrate those records. The PR description now explicitly acknowledges this case; deleting watches is not evidence that pending completion notifications are preserved.
I read the complete four-file patch and compared the authored revisions with git range-diff, separating the incoming branch changes. Actual merge into ed79386f826ab0c2d4267dafa361240487d2f30e succeeded. The current head's CI is queued. I did not rerun the earlier Rust decoding probe, native wake tests, or a desktop/provider session; this update is a source and integration comparison, not a new runtime validation.
Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.
Summary
Follow-up to #6624, following M4n5ter's review there. #6624 skipped an unreadable worker watch inside
watches(), kept the bad record and added an in-memory set to report it once. That left three problems, all addressed here:wake_bot_passcould retire it, so it stayed forever.watches()now returns each record's decode result, andwake_bot_passchecks that the worker is alive first: a gone worker's watch is retired without being decoded. For a live worker the decode error is collected, the healthy workers keep waking, and the combined error is returned, sostart_bot_wake's existingprevious_errorreports it once. Theunreadableset onBotis removed.Bot::watchread the old value throughread::<Watch>, which failed on an unreadable record, so every laterSessionSendto that worker failed to refresh its watch. It now reads the record itself and, when the old value does not decode, writes the new one withnotifiedunset.Watchheld aReturnRoute, which held anAcceptedModel; a change to that type made stored watches unreadable. A watch now keeps only the model selection, thinking level, workspace, binding andnotified, and the model is resolved withSource::selectwhen the Bot is woken (the way scheduled tasks do). A model that cannot be resolved at that moment is reported like an unreadable watch and retried on the next pass.ReturnRouteitself is unchanged for WorkHub; it only gained a constructor and a thinking-level accessor.There is no compatibility branch for the old record format, as requested in the review.
Migration
A watch written by the build before this one (
{"route": ..., "notified": ...}) does not decode with the new shape, even if it was readable before. It is retired when its worker is gone and replaced by the nextSessionSendto a live worker. The one case this does not cover: a Bot that delegated work before the upgrade and sends nothing more to that worker is not woken when the worker finishes. Existing development data can be cleaned with a one-off script that deleteswatch/*records in themaka.botnamespace; the runtime keeps a single current format.Verification
an_unreadable_watch_of_a_gone_worker_is_retired_and_does_not_stop_other_wakes: an unreadable watch for a worker that does not exist is stored; another worker finishes and wakes the Bot, and afterwards the unreadable watch is gone.the_next_send_to_a_worker_replaces_its_unreadable_watch_so_it_wakes_the_bot: a live worker's watch is overwritten with an unreadable value; the Bot's nextSessionSendreplaces it and the finished worker wakes the Bot. Without the write-path change this test fails (the Bot is never woken), checked by reverting it.LANG=en_US.UTF-8). Nightlyrustfmtis clean. Clippy-D warningsreports three existing findings in files this PR does not touch (executor.rs,executor/oar/worker.rs,owner/tests/session_parent_authority.rs) and none in the changed files.AI use
Tool(s) and scope: Claude Code (Claude Opus 5.5) wrote the code, the tests and this description; the changes were run and reviewed by the contributor. The commit carries
Generated-by: Claude Code.Checklist
Does this PR entail a change in behavior?