fix(cron): keep current/session-bound jobs out of direct channel sessions#57831
fix(cron): keep current/session-bound jobs out of direct channel sessions#57831lttcnly wants to merge 5 commits into
Conversation
Greptile SummaryThis PR fixes a security isolation gap where cron jobs could accidentally bind to human direct-message sessions when Key changes:
Confidence Score: 5/5Safe to merge — the guard is correct, well-tested across three layers, backward-compatible, and removes a genuine session-isolation gap. No P0 or P1 issues found. The core guard logic handles mixed-case prefixes correctly. The removed duplicate block was dead code. Moving the guard outside applyDefaults is intentional and correct for the patch path. All test layers pass per the author. No files require special attention. The session-target-guard.ts core logic and server-cron.ts runtime fallback are the two places worth a close read, and both are correct.
|
| Filename | Overview |
|---|---|
| src/cron/session-target-guard.ts | New file introducing the direct-session guard. Logic is correct — direct-chat keys are detected via parseAgentSessionKey + deriveSessionChatType, and mixed-case 'SESSION:' prefixes are handled correctly since parseAgentSessionKey lowercases internally and both casings are 8 chars. |
| src/cron/normalize.ts | Replaces old applyDefaults-gated 'current' resolution blocks (one dead code) with a single unconditional call to normalizeCronSessionTargetForPersistence. Moving outside applyDefaults is intentional and correct for the patch path. |
| src/agents/tools/cron-tool.ts | Adds sessionContext passing to normalizeCronJobPatch in the update action. Normalized patch sent to gateway is idempotent on second normalization pass. |
| src/gateway/server-methods/cron.ts | cron.update now extracts sessionKey, passes to normalizeCronJobPatch for context-aware resolution, and explicitly strips sessionKey before schema validation. |
| src/gateway/server-cron.ts | Runtime safety net added: legacy persisted direct-session jobs fall back to cron: with a warning. Default sessionKey set at top of block ensures safe fallback. |
| src/gateway/server.cron.test.ts | New integration test covers add/update direct→isolated, legacy dirty job runtime fallback, and safe group session reuse preservation. |
| src/cron/normalize.test.ts | Four new unit tests cover current+direct→isolated, named session with 'direct' in name preserved, explicit direct target→isolated, and patch current+direct→isolated. |
| src/agents/tools/cron-tool.test.ts | Two new unit tests verify the tool layer sends isolated to the gateway for both add and update actions from a direct chat session. |
Reviews (1): Last reviewed commit: "fix(cron): keep current/session-bound jo..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8bc677f75b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
92b17c7 to
27dbd59
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27dbd59d70
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ebaf2ab91
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep this PR open: current main still has the direct cron session-reuse problem at source level, but the submitted patch is not merge-ready because it is dirty against main, has a stale import, uses an unsafe session classifier, and still lacks contributor real behavior proof. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main still resolves direct Is this the best way to solve the issue? No, not as written. The layered guard is a plausible direction, but the branch needs a clean rebase, a canonical classifier, custom-session compatibility protection, maintainer policy approval, and real behavior proof before merge. Security review: Security review needs attention: Needs attention because this PR changes a security-sensitive cron/session boundary with an incomplete and over-broad classifier.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against e9671ed60327. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
sessionTarget="current"orsession:<id>pointed at a real DM session.cron:<jobId>at runtime for legacy dirty direct targets.Maintainer context: CODEOWNERS should route this through
@openclaw/secops;@tyler6204may also want a look for cron behavior.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
sessionTarget="current"as “persist the current session key” without checking whether that session key belonged to a human direct-message chat, and runtime execution later trusted any persistedsession:<id>target unconditionally.git blame, prior PR, issue, or refactor if known): current/session-bound cron persistence already existed insrc/cron/normalize.ts; this change adds the missing direct-session boundary without changing the public schema.currentand persistentsession:<id>bindings for agent turns, direct chat sessions became eligible by accident.Regression Test Plan (if applicable)
src/cron/normalize.test.ts,src/agents/tools/cron-tool.test.ts,src/gateway/server.cron.test.tscurrentbindings degrade toisolatedon add/update, explicit dirty directsession:<id>jobs fall back tocron:<jobId>at runtime, and safe group/named session reuse stays intact.User-visible / Behavior Changes
sessionTarget="current"now only persists safe reusable sessions; human direct-message sessions fall back toisolated.session:agent:...:direct:...targets are downgraded on create/update and ignored at runtime for legacy dirty jobs.Diagram (if applicable)
Security Impact (required)
Yes/No): NoYes/No): NoYes/No): NoYes/No): NoYes/No): YesYes, explain risk + mitigation: this reduces cron's data-access scope by preventing reuse of human direct-message sessions. Risk is limited to stricter isolation; mitigation is a runtime warn-and-fallback path plus tests preserving safe group/named-session reuse.Repro + Verification
Environment
Steps
sessionTarget="current".sessionTarget="current"again.sessionTarget="session:agent:...:direct:...".Expected
isolatedinstead of the human DM session.cron:<jobId>instead of the human DM session.Actual
Evidence
Attach at least one:
Human Verification (required)
pnpm buildpassed;pnpm checkpassed.session:<id>downgrade,currentdowngrade from direct chats, safe group reuse, named-session preservation when the name merely containsdirect.pnpm testis not green locally on this machine because unrelated existing failures remain intest/extension-test-boundary.test.tsandsrc/media-understanding/media-understanding-misc.test.ts, and one large unit batch hit a worker/OOM infrastructure failure.Review Conversations
Compatibility / Migration
Yes/No): YesYes/No): NoYes/No): NoRisks and Mitigations
cron:<jobId>session instead of a human DM.