Repository navigation
fix(agents): suppress heartbeat section for cron/subagent CLI-backend sessions - #43291
NayukiChiba wants to merge 11 commits into
Conversation
… sessions For CLI-backend runs (claude-code, gemini-cli, codex), the buildSystemPrompt helper in cli-runner/helpers.ts did not accept a sessionKey and always passed promptMode='full' to buildAgentSystemPrompt. This caused the '## Heartbeats' section (including the HEARTBEAT_OK instruction) to be injected even for cron isolated sessions, making the model reply with HEARTBEAT_OK instead of executing the scheduled task. The embedded Pi runner (attempt.ts) already handled this correctly by calling resolvePromptModeForSession, which returns 'minimal' for cron/subagent keys. This commit applies the same logic to the CLI-backend path. Changes: - cli-runner/helpers.ts: add sessionKey param; derive promptMode as 'minimal' when the key is a cron or subagent session, 'full' otherwise - cli-runner.ts: forward params.sessionKey to buildSystemPrompt - cli-runner/helpers.test.ts: 5 new tests covering full vs minimal prompt mode based on session key type close #43274
Greptile SummaryThis PR fixes a bug where CLI-backend sessions (claude-code, gemini-cli, codex) incorrectly received the Key changes:
Confidence Score: 4/5
Last reviewed commit: 7f21f9d |
| // cron and subagent sessions use minimal mode — suppress heartbeat instructions | ||
| const promptMode: PromptMode = | ||
| isCronSessionKey(params.sessionKey) || isSubagentSessionKey(params.sessionKey) | ||
| ? "minimal" | ||
| : "full"; |
There was a problem hiding this comment.
Duplicated logic already extracted in resolvePromptModeForSession
src/agents/pi-embedded-runner/run/attempt.ts already exports an identical helper:
export function resolvePromptModeForSession(sessionKey?: string): "minimal" | "full" {
if (!sessionKey) return "full";
return isSubagentSessionKey(sessionKey) || isCronSessionKey(sessionKey) ? "minimal" : "full";
}Rather than inlining the same two-condition check here, consider moving resolvePromptModeForSession to a shared location (e.g., src/routing/session-key.ts alongside isCronSessionKey/isSubagentSessionKey, or a small agents/prompt-mode.ts utility) and importing it from both callers. As written, if a third session-key type ever needs "minimal" mode the fix will need to be applied in two places instead of one.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/cli-runner/helpers.ts
Line: 79-83
Comment:
**Duplicated logic already extracted in `resolvePromptModeForSession`**
`src/agents/pi-embedded-runner/run/attempt.ts` already exports an identical helper:
```ts
export function resolvePromptModeForSession(sessionKey?: string): "minimal" | "full" {
if (!sessionKey) return "full";
return isSubagentSessionKey(sessionKey) || isCronSessionKey(sessionKey) ? "minimal" : "full";
}
```
Rather than inlining the same two-condition check here, consider moving `resolvePromptModeForSession` to a shared location (e.g., `src/routing/session-key.ts` alongside `isCronSessionKey`/`isSubagentSessionKey`, or a small `agents/prompt-mode.ts` utility) and importing it from both callers. As written, if a third session-key type ever needs `"minimal"` mode the fix will need to be applied in two places instead of one.
How can I resolve this? If you propose a fix, please make it concise.…session-key The same two-condition check (isCronSessionKey || isSubagentSessionKey → "minimal") was inlined in cli-runner/helpers.ts and already existed as resolvePromptModeForSession in pi-embedded-runner/run/attempt.ts. Move the function to src/routing/session-key.ts alongside the helpers it depends on, so all callers share one definition. If a third session-key type ever needs "minimal" mode the fix only needs to happen in one place. - src/routing/session-key.ts: export resolvePromptModeForSession - src/agents/pi-embedded-runner/run/attempt.ts: import from routing/session-key and re-export to keep existing callers working - src/agents/cli-runner/helpers.ts: replace inline check with the shared helper
…-export in session-key
|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: needs real behavior proof before merge. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. by source inspection. Cron CLI execution passes a cron Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Retarget heartbeat suppression into Do we have a high-confidence way to reproduce the issue? Yes by source inspection. Cron CLI execution passes a cron Is this the best way to solve the issue? No. The intended policy is right, but the patch should thread prompt mode through Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against c93d6d8daa37. |
Summary
Fixes #43274.
For CLI-backend runs (claude-code, gemini-cli, codex), the
buildSystemPrompthelper insrc/agents/cli-runner/helpers.tsdid not accept asessionKeyand always passedpromptMode='full'tobuildAgentSystemPrompt. This caused the## Heartbeatssection (including theHEARTBEAT_OKinstruction) to be injected even for cron isolated sessions, making the model reply withHEARTBEAT_OKinstead of executing the scheduled task.The embedded Pi runner (
attempt.ts) already handled this correctly viaresolvePromptModeForSession, which returns'minimal'for cron/subagent keys. This PR applies the same logic to the CLI-backend path.Root cause
cli-runner/helpers.ts:buildSystemPrompthad nosessionKeyparameter, sopromptModewas never derived from the session key and always defaulted to'full'insidebuildAgentSystemPrompt.Changes
src/agents/cli-runner/helpers.ts: addsessionKey?param; derivepromptModeas'minimal'when the key belongs to a cron or subagent session,'full'otherwisesrc/agents/cli-runner.ts: forwardparams.sessionKeytobuildSystemPromptsrc/agents/cli-runner/helpers.test.ts: 5 new tests covering full vs minimal prompt mode selection based on session key typeTesting