Skip to content

[Feature]: cron tool: add per-agent/session isolation for job visibility and mutations #35447

Closed as not planned

Description

@songchenghao

cron tool: add per-agent/session isolation for job visibility and mutations

Summary

The cron tool stores agentId and sessionKey on every job (CronJobBase in types-shared.ts), and the cron-tool.ts already populates these fields automatically when a job is created. However, the service layer (cron/service/ops.ts) and gateway handlers (gateway/server-methods/cron.ts) perform no filtering on these fields, meaning:

  • cron.list returns all jobs from all agents/sessions
  • cron.remove, cron.update, cron.run operate on any job by ID, regardless of which agent or session created it

This makes it impossible to safely expose the cron tool to multiple users in a multi-user deployment where each user has their own isolated session (e.g. session.dmScope: "per-channel-peer").

Expected Behavior

When a cron tool call is made from an agent session:

  1. cron.list should only return jobs whose agentId or sessionKey matches the caller's session context (with an opt-in override for admins to see all).
  2. cron.remove / cron.update / cron.run should verify that the target job's agentId/sessionKey matches the caller before allowing the mutation. Attempts to mutate another agent's job should return an authorization error.

Current Behavior

All cron operations are global. Any user with the cron tool available (i.e. senderIsOwner: true) can:

  • List every job created by every other user
  • Delete or modify jobs they did not create
  • Manually trigger jobs belonging to other agents

Context

  • CronJobBase already has agentId?: string and sessionKey?: string fields
  • cron-tool.ts already auto-populates agentId and sessionKey on cron.add from opts.agentSessionKey
  • The gateway handler in server-methods/cron.ts currently receives no caller identity — the context object would need to carry the requesting agentId/sessionKey for enforcement to be possible
  • The CronListPageOptions type in ops.ts would need agentId?: string and sessionKey?: string filter fields

Suggested Fix

  1. Thread the requesting agent's sessionKey (or agentId) through the gateway method context into the cron service ops.
  2. Add agentId and sessionKey filter parameters to CronListPageOptions and listPage().
  3. In remove(), update(), and run(), look up the job first and compare its agentId/sessionKey against the caller before proceeding.
  4. Provide a bypass flag (e.g. ownerOverride: true) for the primary admin session to retain full visibility and control.

Use Case

Multi-user DingTalk/Telegram/Slack deployments where each user is routed to their own isolated agent session and all users have cron access. Without this fix, enabling cron for all users means every user can see and destroy every other user's scheduled jobs.

Activity

  1. added
    enhancement
    on Mar 5, 2026
  2. sahilsatralkar commented on Mar 5, 2026

    @sahilsatralkar
    Contributor

    HI, I am looking into this feature request, will update here with my findings

  3. songchenghao commented on Mar 6, 2026

    @songchenghao
    Author

    Issue: Cron isolated jobs don't execute in sandbox despite sandbox.mode="all"

    Description

    When a cron job is configured with sessionTarget: "isolated" and the agent has sandbox.mode: "all", the job still executes in the Gateway process instead of the sandbox container.

    Current Behavior

    • Manual trigger (via chat): Executes correctly in sandbox container with all dependencies available
    • Cron trigger (isolated): Executes in Gateway process, missing sandbox environment dependencies

    Expected Behavior

    Cron isolated jobs should respect sandbox.mode="all" configuration and execute in the sandbox container.

    Configuration

    {
      agents: {
        defaults: {
          sandbox: {
            mode: "all",
            workspaceAccess: "rw",
            scope: "agent",
            docker: {
              image: "custom-sandbox-image:latest",
              // ... other docker settings
            }
          }
        }
      }
    }

    Reproduction

    1. Configure agent with sandbox.mode: "all"
    2. Create a cron job with sessionTarget: "isolated"
    3. Job payload requires sandbox dependencies (e.g., Python packages)
    4. Observe: job runs in Gateway process, not sandbox

    Test Case

    Job with message: hostname && whoami && pip3 list

    • Manual trigger: Returns sandbox hostname and has dependencies
    • Cron trigger: Returns Gateway hostname and missing dependencies

    Root Cause (from code review)

    Based on source code analysis:

    • src/cron/isolated-agent/run.ts calls runEmbeddedPiAgent() which should support sandbox
    • However, the sandbox context is not being resolved/applied for cron isolated sessions
    • src/agents/sandbox/runtime-status.ts shouldSandboxSession() should return true for mode="all", but seems bypassed in cron execution path

    Workaround

    Install required dependencies in the Gateway container instead of relying on sandbox isolation.

    Environment

    • OpenClaw version: 2026.3.1-beta.1
    • Deployment: Docker containerized
    • Gateway mode: local

    This impacts workflows where cron jobs need isolated environments with specific dependencies that are only available in sandbox containers.

  4. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

    Close as duplicate/superseded: the remaining cron ownership work is already covered by the older canonical tracker at #26370, with the narrower all-runs name leak tracked at #49175; current main only implements the list-side agent filter, not the requested mutation/session authorization.

    So I’m closing this here and keeping the remaining discussion on the canonical linked item.

    Review details

    Best possible solution:

    Consolidate follow-up under #26370 for the full trusted cron ownership model, while keeping #49175 for the run-history name leak until the shared fix covers it.

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

    Yes, source-level reproduction is high confidence: create jobs with different agentId/sessionKey values, then update/remove/run another job by id or request all-scope run history; current main lacks caller ownership checks on those paths. I did not run a live repro because this read-only review environment has no pnpm available.

    Is this the best way to solve the issue?

    Yes, duplicate closure is the best cleanup path for this item because the remaining work is already tracked by the older, richer production-context issue and a narrower run-history leak issue. A new fix should be designed there rather than splitting the same access-control decision across parallel trackers.

    Security review:

    Security review needs attention: The underlying issue remains security-sensitive because current main still lacks caller ownership checks for cron mutations and all-scope run-history naming.

    • [medium] Cron mutations lack owner authorization — src/cron/service/ops.ts:368
      update, remove, run, and enqueueRun still operate by job id without a trusted caller scope or agentId/sessionKey comparison, so the remaining fix needs access-control review under the canonical tracker.
      Confidence: 0.92
    • [medium] All-scope run history uses global job names — src/gateway/server-methods/cron.ts:506
      The cron.runs all-scope handler builds its job-name map from the unfiltered cron list, so job names can still cross session boundaries until the run-history tracker is fixed.
      Confidence: 0.9

    What I checked:

    Likely related people:

    • steipete: Recent GitHub commit history and prior review context show repeated maintenance of cron service, gateway schema, and cron delivery behavior; also participated in the canonical tracker discussion. (role: recent maintainer and adjacent cron/gateway owner; confidence: high; commits: 7877182b6f59, 43121fb0968a, b6be42230672; files: src/cron/service/ops.ts, src/gateway/server-methods/cron.ts, src/gateway/protocol/schema/cron.ts)
    • Takhoffman: Historical commits added full cron edit parity, all-jobs run history, compact filters, and jobId hardening across the same gateway/protocol/UI cron management surface. (role: historical cron management contributor; confidence: high; commits: 77c3b142a966, 259d86335378, cc5dad81bc70; files: src/gateway/server-methods/cron.ts, src/gateway/protocol/schema/cron.ts, src/cron/service/ops.ts)
    • vincentkoc: Recent work inferred session agentId for cron jobs and added owner-key task access boundaries, both adjacent to the caller/session ownership model needed here. (role: recent adjacent cron identity and task-boundary maintainer; confidence: medium; commits: ae63f76bbd51, 7cd0ff2d888f, 338d31304314; files: src/agents/tools/cron-tool.ts, src/cron/service/ops.ts, src/gateway/server-methods/cron.ts)
    • zhanggttry: The merged replacement PR for agentId list filtering credits this contributor as the source author for the already-landed partial implementation relevant to this cluster. (role: partial list-filter implementation contributor; confidence: medium; commits: cd66854b666e; files: src/cron/service/ops.ts, src/gateway/server-methods/cron.ts, src/agents/tools/cron-tool.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 51dc4a20be70.

  5. locked as resolved and limited conversation to collaborators on May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions