[错误] v0.5.x 中的 Cron/定时任务会话丢失实时流 (ACP 运行时回退)
Phenomenon
In v0.5.2, when cron jobs are executed, users cannot see the agent's thinking process and streaming output in real time, as they could in v0.4.x. This is manifested as follows:
- After the cron job is triggered, there is no real-time content update in the corresponding session.
- After the task is completed, the result content appears all at once (instead of being presented in a streamed manner).
- It is not possible to continue the conversation or observe the intermediate state during the execution.
Expected behavior
Consistent with v0.4.x: When a cron job is running, switching to the corresponding cron session allows users to see the agent's thinking and tool calls in real time.
Root cause analysis
v0.4.x (legacy runtime)
The runtime event handler in src/stores/chat.ts uses sessionKeysAreEquivalent() to bridge the run-scoped cron key (agent::cron::run:) to the base cron key (agent::cron:) tracked by the UI. This enables all streaming events during cron execution to be rendered in real time in the session that the user is viewing.
Related code:
src/stores/chat.ts:4617— "Cron runtime/chat events arrive under the run-scoped key... treat those as the same session via equivalence"src/stores/chat.ts:5066— "Cron runs stream under the run-scoped session key while the UI tracks the base cron key; equivalence binds those run-scoped events to the session the user is viewing so the live graph/Thinking state renders in realtime"
v0.5.x (ACP-native runtime)
src/stores/acp-chat-session.ts completely lacks the equivalence logic for bridging cron events. It only pulls completed historical messages from the cron session via fetchCronSessionHistory() once, converting them to ACP notifications and injecting them into the timeline (only when timeline.itemOrder.length === 0).
Running cron events are ignored by the ACP store because the session key does not match (run-scoped key ≠ base key).
Steps to reproduce
- Create a cron job, set it to run every minute or trigger it manually.
- Open the cron session in the UI.
- Trigger the cron job to run.
- Observe: there is no real-time content update in the session until the task is completed and refreshed.
Suggested fix direction
Add a similar sessionKeysAreEquivalent() bridging logic to the ACP session notification handler in acp-chat-session.ts: when notifications with run-scoped cron session keys are received, if the base key matches the current activeSessionKey, apply these notifications in real time to the current timeline.
内容来源: ValueCell-ai/ClawX