fix(agent-core-v2): clear inherited cron tasks at the fork record - #4083
Merged
Merged
Conversation
Fork copies the wire journal, so cron tasks persisted as cron.add records were inherited by the fork and fired from both sessions. Fold the forked marker record into the cron actor: the task table is cleared at the fork point and a one-time cron_fork_cleared reminder is delivered (tracked by a durable forkNotice flag confirmed via ContextAppendMessage), mirroring the goal feature's fork handling. The forked event class moves from features/goal to session/agentLifecycle so both features share it.
🦋 Changeset detectedLatest commit: 2e58b9a 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: |
liruifengv
approved these changes
Sep 29, 2026
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.
Requirement or Bug
fork 后的会话会继承源会话的定时任务(cron):源会话与 fork 两侧各跑一个调度器,同一定时任务触发两次(线上双触发反馈;无 issue,内部反馈已登记)。
Bug Reproduction Steps
Root Cause
根本修复,非绕过。v2 的 cron 任务以
cron.add/delete/cursordurable 记录存在于 wire.jsonl,而 fork 的定义就是拷贝 wire——任务表因此被 fork 原样继承。goal 早已处理同类问题:fork 时往 fork 侧 wire 追加forked标记记录,goal fold 到它即清零并投递一次性提醒;cron 从未做过这个决策,属于设计盲区(v1 时代 cron 就明确否决了跨 session 持久化,持久化目标仅为同一 session resume 恢复)。修复与 goal 同构:cron 的 fold 事件加入forked标记,fold 到即在 fork 点清空任务表并投递一次性提醒;调度器表空即空转,无需任何特判。Code Changes
fold 逻辑(伪代码 diff):
GoalForked更名Forked并上移至 session 域(Event2 registry 中同 type 只能注册一个类,必须共享);apps/vis/server引用同步;index.ts增加导出。forked/cron.*记录的 type 与 payload 不变(wire-manifest 仅 owner 路径随行),旧会话状态连续。Behavior Changes and Affected Users
cron_fork_clearedreminder(三句)GoalForkedForked,改从 session/agentLifecycle 导出受影响模块与测试覆盖:
packages/agent-core-v2/test/features/cron/sessionCron.test.ts:fork 边界四分支(fork 点有任务→清除+reminder、无任务→不提醒、fork 点之后新建任务→存活、已交付→不重投)+ 既有 wire replay 覆盖(两个用例合并,it数不变)packages/kap-server/test/sessions.test.ts:fork clears inherited cron tasks while the source keeps them——真实:forkAPI + resume 的 e2e,由钉住旧行为的用例改写(it数不变),同时钉住源会话不受影响goal.test.tsfork boundaries 用例随全量通过;本次仅改其事件类引用)sessionIndex周期 tick 计数(计时敏感),本地 3/3 复跑通过,与本改动无代码交集,判定环境抖动Checklist
/approve).(内部 PR,无 issue,线上反馈已登记)gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.(工具描述未声称 fork 继承任务,无文档失真)