Skip to content

fix(cron): bind a caller-less job to its session target's agent - #190156

Closed
Yuaneen wants to merge 1 commit into
openclaw:mainfrom
Yuaneen:fix/cron-session-target-agent-190123
Closed

Yuaneen wants to merge 1 commit into
openclaw:mainfrom
Yuaneen:fix/cron-session-target-agent-190123

Conversation

@Yuaneen

@Yuaneen Yuaneen commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #190123

What Problem This Solves

An agent that scheduled a cron job for another agent's conversation ended up with a job that could never run: it was bound to the calling agent, failed at the due time with "SQLite session store path belongs to agent …", and a one-shot job was then disabled as a permanent error.

  • Problem: cron.add without agentId filled the job's agent with the caller (applyCronCreateCallerScopeDefault), and the effective-owner resolver (tryResolveCronJobEffectiveAgentId) only consulted the explicit id, the job's own session key, then the configured default — never the agent named by sessionTarget: "session:agent:<other>:…". The run itself resolves its session from sessionTarget first, so the stored owner and the run target disagreed.
  • Solution: resolve the agent from the job's own sessionTarget (via the existing resolveCronSessionTargetSessionKey + parseAgentSessionKey) and put it ahead of the caller/default in both places; the caller remains the job's owner.
  • What changed: src/cron/agent-id.ts (new resolveCronSessionTargetAgentId, resolver order), src/cron/types-shared.ts (CronAgentScope gains the job's sessionTarget), src/gateway/server-methods/cron-caller-scope.ts (create default), plus regressions in src/cron/agent-id.test.ts and src/gateway/server-methods/cron-caller-scope.test.ts.
  • What did NOT change: explicit agentId still wins, detached targets (isolated / current / main) still fall back to the caller, the owner fields (owner.agentId, owner.sessionKey) are untouched, and no delivery/schedule semantics moved.

Why This Change Was Made

The job's own target is the most specific statement about where it runs, so it must rank above an ambient caller default; the caller still owns what it created. Both call sites already exist and the session-target parser is shared, so this is one resolution rule, not a new contract.

  • Best fix: yes — one helper reused by the create default and the runtime resolver keeps them consistent.
  • Alternative: teaching cron.add only — rejected; the resolver would still mis-answer for jobs created through other paths (Doctor, internal probes).
  • Risk / non-goals: cron.update that changes sessionTarget on an existing job keeps its stored explicit agentId; that is unchanged here and noted as a follow-up.

User Impact

A job scheduled for another agent's conversation now runs there instead of failing at its first tick, and one-shot jobs are no longer auto-disabled. Jobs that target the caller still bind to the caller.

Evidence

Red on the base, green with the fix — both regressions fail on the current main (18516599b) and pass here:

$ node node_modules/vitest/vitest.mjs run src/cron/agent-id.test.ts src/gateway/server-methods/cron-caller-scope.test.ts
# before the fix
AssertionError: expected 'default-agent' to be 'other'      # resolver ignored sessionTarget
AssertionError: expected 'caller' to be 'other'             # create default bound the caller
 Test Files  2 failed (2)
      Tests  2 failed | 10 passed (12)

# with the fix
 Test Files  2 passed (2)
      Tests  12 passed (12)

Resolution order exercised by the new cases: explicit agentId → agent named by sessionTarget → job sessionKey → configured default; detached targets keep the caller, and owner.agentId stays the caller.

Focused cron coverage on the same head (the full src/cron sweep exceeds the local runner budget):

$ node node_modules/vitest/vitest.mjs run src/gateway/server-methods/cron-add.test.ts \
    src/gateway/server-methods/cron-caller-scope.test.ts src/cron/agent-id.test.ts \
    src/cron/session-target.test.ts
 Test Files  3 passed (3)
      Tests  18 passed (18)

oxlint (0 warnings / 0 errors) and run-format --check pass on the changed files.

What was not tested: a live Gateway run of the failing one-shot (the regression drives the create default and the resolver directly), and cron.update changing sessionTarget (documented non-goal above).

AI Assistance

This PR is AI-assisted. Used source tracing across the cron create path, the effective-owner resolver, and the session-target parser, plus red/green regressions on the real helpers. The implementer understands the code: the job's own target is more specific than the ambient caller, while ownership stays with the caller. All evidence above is from real local runtime execution.

A create without agentId stored the calling agent even when sessionTarget
named another agent's session, so the run later failed with 'SQLite session
store path belongs to agent ...' and a one-shot was auto-disabled. Resolve
the agent from the job's own session target before the caller/default, in
both the create default and the effective-owner resolver.
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@Yuaneen
Yuaneen marked this pull request as ready for review November 1, 2026 07:40
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 1, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Derive a cron job's execution agent from its qualified session target before falling back to the caller or configured default.

Example: A main-agent caller schedules a job targeting session:agent:worker:dashboard:probe without agentId.

  • Before: Creation stamps main as the execution agent while retaining the worker session target.
  • After: The patched default selects worker, but the subsequent caller-scope check rejects creation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused but leaves two production selection boundaries inconsistent and supplies no shipped-entry-point proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A scheduled job can target another agent's conversation while retaining a conflicting execution agent, causing the intended work to fail.
Reason: The scheduling defect merits repair, but replacing established caller/default selection with target-derived selection needs an owner decision and a complete cutover.

Merge readiness

⛔ Blocked before merge - 8 items remain

Keep open: this PR addresses a concrete scheduling bug, but target-agent inference does not reach the admission and execution boundaries consistently.

Priority: P2
Reviewed head: 2cba4015080f03589d2892f41983c294b5c6cf51
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should an omitted agentId infer the qualified target's agent, or should creation reject a target that conflicts with the existing caller/default selection?
  • Recommendation: Reject inconsistent targets before saving: Preserve existing agent selection and return an actionable error naming the selected agent, target agent, and corrective --agent value.
  • Why: Existing history deliberately separates management authority from creation restrictions, and no maintainer approval establishes this PR's changed defaulting contract.

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied output exercises resolver and defaulting helpers only, and the body explicitly excludes a live Gateway one-shot run; provide allowed and nearest-forbidden caller traces through final session execution, revocation rejection before I/O, and an upgrade showing existing agent-less jobs retain intended ownership, with credentials and private endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Carry target-agent selection through creation authorization (P2) - For callerScope.agentId='main', including a scope with manageAll, and sessionTarget='session:agent:worker:dashboard:probe', this hunk changes the job agent to worker. cronAddHandler immediately passes that result to cronCreateMatchesCallerScope, which rejects worker !== main before the management-aware session-reference check. The stated agent-created workflow therefore returns 'job agentId outside caller scope' instead of scheduling the job. Resolve the intended policy at the real creation boundary and cover that handler rather than only this helper.
  • Use one execution agent for caller-less occurrence admission (P2) - For an operator create with no caller scope, omitted agentId, default agent main, and sessionTarget='session:agent:worker:dashboard:probe', the new resolver returns worker, but applyCronCreateCallerScopeDefault returns the input unchanged and createJob persists agentId as undefined. At the due tick, admitGatewayCronOccurrence still calls resolveAgent(job.agentId), selecting main. The shared resolver and the actual occurrence owner therefore disagree, so adding sessionTarget here does not deliver the claimed caller-less execution fix. Bind or resolve the same approved agent at the occurrence owner and affected inference-capture boundary.
  • Align the CLI warning with target-derived agent selection (P3) - With the new precedence, an operator running cron add with --session session:agent:worker:dashboard:probe and no --agent is resolved to worker, yet this unchanged warning still promises execution with the configured default agent. Update or suppress that warning for a qualified target so users are not told that a different agent will run their job.
  • Resolve security concern: Execution and authority owners can diverge - Target inference changes the selected agent while caller-less occurrence admission and scoped creator capture retain independent selections; prove that neither another agent's saved authority nor revoked creator authority reaches the final effect.
  • Resolve merge risk - Before merge, the contributor must establish that target-agent inference cannot lend one agent another agent's creator or inference authority, including after creator revocation.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Carry target-agent selection through creation authorization — src/gateway/server-methods/cron-caller-scope.ts:525-527
  • [P2] Use one execution agent for caller-less occurrence admission — src/cron/agent-id.ts:34
  • [P3] Align the CLI warning with target-derived agent selection — src/cli/cron-cli/register.cron-add.ts:361-362
  • [medium] Execution and authority owners can diverge — src/cron/agent-id.ts:34

Tests

  • Missing end-to-end proof: Supply a redacted real Gateway creation-and-due-run trace for a two-agent target, ordinary-caller rejection, revoked authority, and latest-stable upgrade with existing jobs intact.
Agent review details

How this fits together

Gateway cron creation validates requests and records creator ownership; the cron service later admits scheduled occurrences and dispatches work into agent-owned sessions.

flowchart TD
  A[Cron creation request] --> B[Caller scope and execution agent]
  B --> C[Creation authorization]
  C --> D[Stored cron job]
  D --> E[Scheduled occurrence admission]
  E --> F[Agent session execution]
Loading

Technical review

Best possible solution:

Choose one execution-agent policy at creation, preserve creator ownership separately, and use the resulting agent consistently through authorization, inference capture, persistence, and occurrence admission.

Do we have a high-confidence way to reproduce the issue?

Source establishes contradictory creation and execution identities, and the linked report supplies an affected release and failure trace; no target code was executed during this read-only review.

Is this the best way to solve the issue?

A shared parser is appropriate, but changing the resolver alone leaves competing agent-selection paths; early consistency validation is the smaller repair unless an owner approves broader inference.

Full review comments:

  • [P2] Carry target-agent selection through creation authorization — src/gateway/server-methods/cron-caller-scope.ts:525-527
    For callerScope.agentId='main', including a scope with manageAll, and sessionTarget='session:agent:worker:dashboard:probe', this hunk changes the job agent to worker. cronAddHandler immediately passes that result to cronCreateMatchesCallerScope, which rejects worker !== main before the management-aware session-reference check. The stated agent-created workflow therefore returns 'job agentId outside caller scope' instead of scheduling the job. Resolve the intended policy at the real creation boundary and cover that handler rather than only this helper.
    Confidence: 0.99
  • [P2] Use one execution agent for caller-less occurrence admission — src/cron/agent-id.ts:34
    For an operator create with no caller scope, omitted agentId, default agent main, and sessionTarget='session:agent:worker:dashboard:probe', the new resolver returns worker, but applyCronCreateCallerScopeDefault returns the input unchanged and createJob persists agentId as undefined. At the due tick, admitGatewayCronOccurrence still calls resolveAgent(job.agentId), selecting main. The shared resolver and the actual occurrence owner therefore disagree, so adding sessionTarget here does not deliver the claimed caller-less execution fix. Bind or resolve the same approved agent at the occurrence owner and affected inference-capture boundary.
    Confidence: 0.97
  • [P3] Align the CLI warning with target-derived agent selection — src/cli/cron-cli/register.cron-add.ts:361-362
    With the new precedence, an operator running cron add with --session session:agent:worker:dashboard:probe and no --agent is resolved to worker, yet this unchanged warning still promises execution with the configured default agent. Update or suppress that warning for a qualified target so users are not told that a different agent will run their job.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3e253689582b.

Merge-risk options

Maintainer options:

  1. Preserve selection and validate consistency (recommended)
    The contributor can replace runtime reinterpretation with early mismatch validation under the existing creation policy.
  2. Approve a complete inference change
    The area owner can approve target-derived selection, followed by contributor repairs that align admission and prove the authority boundary.

Provenance checked

  • Execution-agent fallback changes intended behavior with a stated reason (82d1a03: Centralize roster ownership and preserve explicit-agent and scoped-session precedence ahead of ambient defaults.)
  • Creator attribution and creation scope changes intended behavior with a stated reason (fdc9aa8: Declarative jobs retain separate creator attribution while creation stays caller-scoped; later management work preserved creation restrictions.)

Testing

Proof path: unit tests only.

Security

Needs attention: No authorization bypass is established, but inferred execution ownership must remain consistent with creator and inference authority.

Evidence

Security concerns:

  • [medium] Execution and authority owners can diverge — src/cron/agent-id.ts:34
    Target inference changes the selected agent while caller-less occurrence admission and scoped creator capture retain independent selections; prove that neither another agent's saved authority nor revoked creator authority reaches the final effect.
    Confidence: 0.88

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit fdc9aa8 adds src/gateway/server-methods/cron-caller-scope.ts:141 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fdc9aa82d785; files: src/gateway/server-methods/cron-caller-scope.ts)
  • joshavant: Raw commit 5d21ba0 adds src/gateway/server-methods/cron-caller-scope.ts:169 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5d21ba0a2a85; files: src/gateway/server-methods/cron-caller-scope.ts)

PR surface

Source +17, Tests +38. Total +55 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 19 2 +17
Tests 2 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 57 2 +55

Root-cause cluster

Relationship: same_root_cause
Canonical: #190123
Summary: This PR attempts to repair the canonical report's mismatch between cron execution agent and qualified session target.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: The affected workflow is cross-agent scheduling on multi-agent Gateways, with limited scope but real failed scheduled work.
  • add merge-risk: 🚨 compatibility: The resolver changes the interpretation of existing agent-less jobs without demonstrated upgrade compatibility.
  • add merge-risk: 🚨 session-state: The shared resolver and Gateway occurrence admission can select different agents for the same stored session-targeted job.
  • add merge-risk: 🚨 security-boundary: Execution-agent selection affects access to agent-owned sessions and captured authority, whose consistency is not established by the supplied helper tests.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The affected workflow is cross-agent scheduling on multi-agent Gateways, with limited scope but real failed scheduled work.
  • merge-risk: 🚨 compatibility: The resolver changes the interpretation of existing agent-less jobs without demonstrated upgrade compatibility.
  • merge-risk: 🚨 session-state: The shared resolver and Gateway occurrence admission can select different agents for the same stored session-targeted job.
  • merge-risk: 🚨 security-boundary: Execution-agent selection affects access to agent-owned sessions and captured authority, whose consistency is not established by the supplied helper tests.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 1, 2026, 2:56 AM ET / 07:56 UTC.

@Yuaneen

Yuaneen commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing this PR: the review shows the change needs a maintainer decision and a complete cutover, not a helper-level patch.

What the review established (verified in source):

  • Creation authorization mismatch (P2): cronAddHandler feeds the target-derived agentId into cronCreateMatchesCallerScope, which rejects worker !== main before the management-aware session-reference check — so an agent-authored job for another agent's session is now refused at creation instead of scheduled.
  • Caller-less execution is not reached (P2): when no caller scope exists, applyCronCreateCallerScopeDefault returns the job unchanged, and admitGatewayCronOccurrence still resolves job.agentId (default agent), so the target-derived resolver never owns the due run.
  • Authority divergence (security): target inference changes the execution agent while creator/inference capture keeps its own selection; proving that one agent's authority cannot reach another agent's effect needs an owner-level decision.
  • Plus the CLI warning and upgrade-compatibility expectations.

The right fix is a single cutover across the creation-authorization owner, the occurrence-admission owner, and the CLI surface, and it requires a maintainer call on whether a session:agent:<other> target may outrank the caller default at all. I would rather withdraw this than push a partial, authorization-adjacent change.

Closing — not abandoning the report. If maintainers confirm the intended policy (cross-agent sessionTarget allowed, and who owns creator authority in that case), I am happy to reopen this with the full cutover and the requested Gateway creation-and-due-run traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

1 participant