Skip to content

fix(cron): scope all-run job names - #79940

Closed
HemantSudarshan wants to merge 2 commits into
openclaw:mainfrom
HemantSudarshan:codex/49175-cron-runs-scope
Closed

HemantSudarshan wants to merge 2 commits into
openclaw:mainfrom
HemantSudarshan:codex/49175-cron-runs-scope

Conversation

@HemantSudarshan

@HemantSudarshan HemantSudarshan commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #49175.

cron.runs with scope: "all" still returns global run-log rows, but job-name enrichment now uses the same agent-scoped job visibility path as cron.list instead of reading every job through the unfiltered cron.list() shortcut.

Problem summary

cron.runs(scope=all) built jobNameById from context.cron.list({ includeDisabled: true }). That list is not caller/agent filtered, so run-history responses could attach another agent's cron job name to otherwise global run entries.

Root cause

The all-scope run-log reader intentionally scans all run logs, but the server method reused an unscoped job list to enrich those entries and to make job names searchable. The leak was in the enrichment map, not in scheduler execution or run-log storage.

Architectural reasoning

  • Reuses context.cron.listPage() for the job-name lookup because it already applies agentId filtering and effective default-agent handling.
  • Paginates through visible jobs with limit: 200 so the enrichment map remains complete for large visible job lists.
  • Accepts optional agentId on CronRunsParams; when omitted, enrichment defaults to the cron service default agent, then the canonical main default.
  • Leaves run-log scanning, job-specific cron.runs, scheduling, delivery, cleanup, retry, and background-task behavior unchanged.
  • Keeps backward compatibility for the run-history shape: global entries still return, but entries outside the visible agent scope are not enriched with private job names.

Testing performed

  • pnpm test src/gateway/server-methods/cron.runs.test.ts src/gateway/protocol/cron-validators.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/gateway/protocol/schema/cron.ts src/gateway/protocol/cron-validators.test.ts src/gateway/server-methods/cron.ts src/gateway/server-methods/cron.runs.test.ts
  • pnpm tsgo:core
  • pnpm tsgo:core:test
  • pnpm lint:core
  • OPENCLAW_LOCAL_CHECK=1 OPENCLAW_LOCAL_CHECK_MODE=throttled pnpm check:changed
  • pnpm check:changelog-attributions
  • git diff --check upstream/main...HEAD

Real behavior proof

  • Behavior or issue addressed: cron.runs(scope=all) no longer builds its job-name enrichment map from every cron job across all agents.
  • Real environment tested: Local Windows source checkout, Node v22.15.0, pnpm 10.33.2. The repo warns that Node >=22.16.0 is preferred on this machine; the targeted proof below completed.
  • Exact steps or command run after this patch: Ran the patched cron.runs server handler from the source checkout with scope: "all" and agentId: "main"; the command throws if the old unscoped cron.list() path is used and records the actual listing call made by the handler.
  • Evidence after fix: Terminal output copied from the patched checkout:
{
  "unscopedListCalls": 0,
  "listPageCalls": [
    {
      "includeDisabled": true,
      "agentId": "main",
      "limit": 200,
      "offset": 0
    }
  ],
  "response": {
    "ok": true,
    "result": {
      "entries": [],
      "total": 0,
      "offset": 0,
      "limit": 1,
      "hasMore": false,
      "nextOffset": null
    }
  }
}
  • Observed result after fix: The patched handler did not call the old unscoped list path (unscopedListCalls: 0) and used the agent-scoped paginated list path with agentId: "main"; the call returned successfully.
  • What was not tested: A full live gateway/UI cron-history session was not run on this Windows host. The existing src/gateway/server.cron.test.ts -t "writes cron run history" integration test was attempted locally and still fails here because the pre-existing all-scope run-log directory listing path returns no entries under the local fs-safe/root implementation. That failure is independent of this privacy fix; the added regression directly tests the changed handler contract.

Risk analysis

Risk is low-to-medium. The changed runtime path is limited to all-scope cron.runs job-name enrichment. It does not alter run execution, scheduler concurrency, cleanup, delivery, retries, or job-specific run-history reads. The main compatibility change is intentionally privacy-preserving: callers still receive all-scope run entries, but job names are only attached for the requested/default agent scope.

Backward compatibility

Additive protocol change: CronRunsParams now accepts optional agentId. Existing cron.runs callers remain valid.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 9, 2026
@clawsweeper

clawsweeper Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge.

Summary
The PR adds optional agentId support to cron.runs, switches all-scope job-name enrichment from cron.list() to paginated cron.listPage(), adds regression coverage, refreshes Swift protocol models, and records a changelog fix.

Reproducibility: yes. Source inspection reproduces the current-main leak via unfiltered context.cron.list() and the PR's residual issue via a caller-controlled agentId on a read-scoped cron.runs request.

Real behavior proof
Sufficient (terminal): The PR body includes terminal output from a real source checkout showing the patched handler no longer calls the old unscoped list path and uses listPage() for the tested request.

Next step before merge
Access-control-sensitive PR needs contributor or maintainer changes to derive the enrichment scope from trusted caller context before merge.

Security
Needs attention: The diff touches an access-control-sensitive metadata leak and still leaves job-name visibility controlled by an untrusted request field.

Review findings

  • [P1] Derive the cron run-name scope from the caller — src/gateway/server-methods/cron.ts:531
Review details

Best possible solution:

Derive the job-name lookup scope from trusted caller/session context, with an explicit admin override if needed, and add a regression proving one read-scoped caller cannot enrich or search another agent's cron job name.

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

Yes. Source inspection reproduces the current-main leak via unfiltered context.cron.list() and the PR's residual issue via a caller-controlled agentId on a read-scoped cron.runs request.

Is this the best way to solve the issue?

No. listPage() is the right primitive, but using an untrusted request agentId is not the best access-control fix; the scope should come from authenticated/session context or an explicitly authorized admin path.

Full review comments:

  • [P1] Derive the cron run-name scope from the caller — src/gateway/server-methods/cron.ts:531
    The new agentId is trusted directly when building the all-scope jobNameById map. Because cron.runs is readable with operator.read and the schema accepts any non-empty string, a caller can request another known agent id and still get that agent's job names attached and searchable in run history. Derive this scope from the authenticated/session caller, or require an admin-checked override, instead of taking it from the request.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.88

Security concerns:

  • [medium] Request-selected agentId can expose cron job names — src/gateway/server-methods/cron.ts:531
    The patch narrows the enrichment map only to the agentId supplied in the request. Since cron.runs is read-scoped, that does not prove the caller owns or may view that agent, so cross-agent job-name disclosure remains possible for known or guessable agent ids.
    Confidence: 0.88

What I checked:

  • Current main leak path: Current main still builds all-scope jobNameById from context.cron.list({ includeDisabled: true }), which has no agent or caller filter. (src/gateway/server-methods/cron.ts:507, 3f3e94a604c1)
  • Run-log name exposure: readCronRunLogEntriesPageAll() uses the supplied jobNameById for search text and writes entry.jobName into returned rows. (src/cron/run-log.ts:498, 3f3e94a604c1)
  • Read-scoped method: cron.runs is exposed in the read-scope method set, so the name-enrichment scope matters for read-capable gateway clients. (src/gateway/method-scopes.ts:113, 3f3e94a604c1)
  • Patch trusts request agentId: The PR computes the enrichment scope from p.agentId ?? context.cron.getDefaultAgentId() ?? DEFAULT_AGENT_ID before calling listPage(), making the privacy boundary depend on a caller-controlled request field. (src/gateway/server-methods/cron.ts:531, 21de933c03ef)
  • ListPage filters only the supplied value: listPage() normalizes opts.agentId and filters jobs against it; it does not derive or verify that agent from the authenticated/session caller. (src/cron/service/ops.ts:292, 3f3e94a604c1)
  • Related report context: The linked issue and its ClawSweeper review describe the expected fix as caller/session-visible job names, not a caller-selected agent-id filter; prior related PRs were closed unmerged.

Likely related people:

  • Takhoffman: Authored central cron run-history and run-log work, including all-jobs run history and cron.runs hardening, which are the feature surfaces affected here. (role: introduced/adjacent owner; confidence: high; commits: 77c3b142a966, 259d86335378, 9bc265f37956; files: src/gateway/server-methods/cron.ts, src/cron/run-log.ts, ui/src/ui/views/cron.ts)
  • zhanggttry: Co-authored the recent merged cron.list agentId filtering work that this PR reuses as its visibility primitive. (role: recent adjacent contributor; confidence: medium; commits: cd66854b666e; files: src/gateway/server-methods/cron.ts, src/cron/service/ops.ts, src/gateway/protocol/schema/cron.ts)
  • steipete: Recent cron/gateway/run-log adjacent commits and local blame show recurring maintainer work in the touched runtime area; useful for access-control review routing. (role: recent maintainer; confidence: medium; commits: 43121fb0968a, 538605ff44d2, ca8bcea186; files: src/gateway/server-methods/cron.ts, src/cron/run-log.ts, src/cron/service/ops.ts)

Remaining risk / open question:

  • The intended visibility model for all-scope run-log rows remains broader than job-name enrichment; maintainers should confirm whether names-only scoping is enough for the linked security report.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3f3e94a604c1.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 9, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 9, 2026
@HemantSudarshan
HemantSudarshan deleted the codex/49175-cron-runs-scope branch May 10, 2026 06:59
@HemantSudarshan

Copy link
Copy Markdown
Contributor Author

Replaced by #80146: #80146

Closing this copy so the active PR uses the hemant/ source branch prefix. Commit SHAs and author/committer identity are unchanged.

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

Labels

app: web-ui App: web-ui gateway Gateway runtime proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cron.runs with scope=all leaks job names across sessions

1 participant