Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0340eb7f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (form.payloadKind === "acpTurn") { | ||
| const acpPayload: { | ||
| kind: "acpTurn"; |
There was a problem hiding this comment.
Accept acpTurn in gateway cron payload validators
This path now builds and submits payload.kind="acpTurn", but the gateway validator still only accepts systemEvent/agentTurn in src/gateway/protocol/schema/cron.ts (CronPayloadSchema/CronPayloadPatchSchema). In the gateway context I inspected (src/gateway/server-methods/cron.ts), cron.add/cron.update validate before calling CronService, so any UI/tool request using acpTurn is rejected as invalid cron.* params and the new feature cannot be created/updated through the API.
Useful? React with 👍 / 👎.
| const resolvedAcpAgentId = (payload.acpAgentId?.trim() || "").toLowerCase() || undefined; | ||
| if (resolvedAcpAgentId) { | ||
| const agentPolicyError = resolveAcpAgentPolicyError(params.cfg, resolvedAcpAgentId); |
There was a problem hiding this comment.
Enforce ACP allowlist for implicit acpTurn agent
The allowlist check only runs when payload.acpAgentId is explicitly set, but this function later falls back to agent: resolvedAcpAgentId ?? "claude" during session init. That means jobs omitting acpAgentId skip acp.allowedAgents enforcement and can execute an unintended harness (or fail with a confusing init error) instead of honoring policy/default-agent constraints.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR adds a first-class Key changes:
Issues found:
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 114-121
Comment:
**Misleading "fail early" comment**
The comment says "Resolve delivery target before execution so a bad target fails early", but `resolvedDelivery.ok` is never checked here. The ACP session is initialized and `runTurn` is called even when the delivery target resolution failed — the `ok: false` case is only caught inside `dispatchCronDelivery` well after the turn completes.
This is consistent with how `run.ts` behaves (the check also happens in `dispatchCronDelivery` there), but the comment creates a false expectation of an early-exit guard. Consider either:
- Removing the "fail early" qualifier so the comment simply describes intent, or
- Adding an explicit check: `if (!resolvedDelivery.ok) { return { status: "error", error: ..., errorKind: "delivery-target" }; }` before `getAcpSessionManager()` to match the comment's promise.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 17-26
Comment:
**`lane` parameter accepted but never used**
`RunCronAcpTurnParams` declares `lane?: string` and `server-cron.ts` passes `lane: "cron"`, but `runCronAcpTurn` never reads or forwards it. For `runCronIsolatedAgentTurn` the `lane` is used for sub-agent concurrency tracking and nested agent lane resolution — functionality that doesn't apply to ACP runs.
If ACP runs are intentionally exempt from lane tracking, a brief comment explaining why would prevent future confusion. Otherwise, if the lane is meant to be forwarded to `initializeSession` for backend routing, it's currently silently dropped.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 188-195
Comment:
**ACP session not closed on `runTurn` error**
When `acpManager.runTurn` throws (setting `turnError`), the function returns an error without calling `acpManager.closeSession`. In contrast, the abort-check path above explicitly calls `closeSession` with a best-effort catch before returning.
For a `mode: "oneshot"` session the manager *may* auto-close after a failed turn, but if `runTurn` throws before the backend triggers its own cleanup, the session process may linger. This asymmetry compared to the abort path looks unintentional and could leak ACP backend processes across repeated cron job failures.
Consider adding a best-effort `closeSession` call here to mirror the abort path, passing `reason: "cron-turn-error"`. This is a low-cost defensive guard.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: e0340eb |
| // Resolve delivery target before execution so a bad target fails early. | ||
| const deliveryPlan = resolveCronDeliveryPlan(params.job); | ||
| const resolvedDelivery = await resolveDeliveryTarget(params.cfg, agentId, { | ||
| channel: deliveryPlan.channel ?? "last", | ||
| to: deliveryPlan.to, | ||
| accountId: deliveryPlan.accountId, | ||
| sessionKey: params.job.sessionKey, | ||
| }); |
There was a problem hiding this comment.
Misleading "fail early" comment
The comment says "Resolve delivery target before execution so a bad target fails early", but resolvedDelivery.ok is never checked here. The ACP session is initialized and runTurn is called even when the delivery target resolution failed — the ok: false case is only caught inside dispatchCronDelivery well after the turn completes.
This is consistent with how run.ts behaves (the check also happens in dispatchCronDelivery there), but the comment creates a false expectation of an early-exit guard. Consider either:
- Removing the "fail early" qualifier so the comment simply describes intent, or
- Adding an explicit check:
if (!resolvedDelivery.ok) { return { status: "error", error: ..., errorKind: "delivery-target" }; }beforegetAcpSessionManager()to match the comment's promise.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 114-121
Comment:
**Misleading "fail early" comment**
The comment says "Resolve delivery target before execution so a bad target fails early", but `resolvedDelivery.ok` is never checked here. The ACP session is initialized and `runTurn` is called even when the delivery target resolution failed — the `ok: false` case is only caught inside `dispatchCronDelivery` well after the turn completes.
This is consistent with how `run.ts` behaves (the check also happens in `dispatchCronDelivery` there), but the comment creates a false expectation of an early-exit guard. Consider either:
- Removing the "fail early" qualifier so the comment simply describes intent, or
- Adding an explicit check: `if (!resolvedDelivery.ok) { return { status: "error", error: ..., errorKind: "delivery-target" }; }` before `getAcpSessionManager()` to match the comment's promise.
How can I resolve this? If you propose a fix, please make it concise.| export type RunCronAcpTurnParams = { | ||
| cfg: OpenClawConfig; | ||
| deps: CliDeps; | ||
| job: CronJob; // payload.kind must be "acpTurn" | ||
| message: string; | ||
| abortSignal?: AbortSignal; | ||
| agentId?: string; | ||
| sessionKey: string; | ||
| lane?: string; | ||
| }; |
There was a problem hiding this comment.
lane parameter accepted but never used
RunCronAcpTurnParams declares lane?: string and server-cron.ts passes lane: "cron", but runCronAcpTurn never reads or forwards it. For runCronIsolatedAgentTurn the lane is used for sub-agent concurrency tracking and nested agent lane resolution — functionality that doesn't apply to ACP runs.
If ACP runs are intentionally exempt from lane tracking, a brief comment explaining why would prevent future confusion. Otherwise, if the lane is meant to be forwarded to initializeSession for backend routing, it's currently silently dropped.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 17-26
Comment:
**`lane` parameter accepted but never used**
`RunCronAcpTurnParams` declares `lane?: string` and `server-cron.ts` passes `lane: "cron"`, but `runCronAcpTurn` never reads or forwards it. For `runCronIsolatedAgentTurn` the `lane` is used for sub-agent concurrency tracking and nested agent lane resolution — functionality that doesn't apply to ACP runs.
If ACP runs are intentionally exempt from lane tracking, a brief comment explaining why would prevent future confusion. Otherwise, if the lane is meant to be forwarded to `initializeSession` for backend routing, it's currently silently dropped.
How can I resolve this? If you propose a fix, please make it concise.| if (turnError) { | ||
| return { | ||
| status: "error", | ||
| error: `ACP turn failed (${turnError.code}): ${turnError.message}`, | ||
| summary: outputText, | ||
| sessionKey: agentSessionKey, | ||
| }; | ||
| } |
There was a problem hiding this comment.
ACP session not closed on runTurn error
When acpManager.runTurn throws (setting turnError), the function returns an error without calling acpManager.closeSession. In contrast, the abort-check path above explicitly calls closeSession with a best-effort catch before returning.
For a mode: "oneshot" session the manager may auto-close after a failed turn, but if runTurn throws before the backend triggers its own cleanup, the session process may linger. This asymmetry compared to the abort path looks unintentional and could leak ACP backend processes across repeated cron job failures.
Consider adding a best-effort closeSession call here to mirror the abort path, passing reason: "cron-turn-error". This is a low-cost defensive guard.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cron/isolated-agent/run-acp.ts
Line: 188-195
Comment:
**ACP session not closed on `runTurn` error**
When `acpManager.runTurn` throws (setting `turnError`), the function returns an error without calling `acpManager.closeSession`. In contrast, the abort-check path above explicitly calls `closeSession` with a best-effort catch before returning.
For a `mode: "oneshot"` session the manager *may* auto-close after a failed turn, but if `runTurn` throws before the backend triggers its own cleanup, the session process may linger. This asymmetry compared to the abort path looks unintentional and could leak ACP backend processes across repeated cron job failures.
Consider adding a best-effort `closeSession` call here to mirror the abort path, passing `reason: "cron-turn-error"`. This is a low-cost defensive guard.
How can I resolve this? If you propose a fix, please make it concise.
Summary
acpTurncron payload kind for directly triggering one-shot ACP runs (Claude Code, Codex, Gemini CLI, etc.) without going throughsystemEventor a genericagentTurnworkaround.acpTurnis restricted tosessionTarget: "isolated", uses the real ACP session manager control plane (initializeSession({ mode: "oneshot" })+runTurn()), and enforces ACP policy / agent allowlist before execution.none/announce/webhook) unchanged.acpTurnpayload selector, ACP agent ID field, i18n (en + zh-CN).Known MVP limitations
payload.modelnot yet forwarded to ACP session init.Test plan
pnpm test src/cron/cron-acp-turn.test.ts- 20/20 passingpnpm test src/cron/ ui/src/ui/- 567/567 passingpnpm tsgo- typecheck cleanpnpm check- lint + format cleanCo-authored-by: shiwenwen [email protected]