Skip to content

fix(cron): reserve migrated heartbeat-task namespace - #123729

Merged
steipete merged 1 commit into
mainfrom
fix/cron-heartbeat-task-namespace
Aug 14, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/cron-heartbeat-task-namespace

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #123728

What Problem This Solves

Fixes an issue where users creating a main-session system-event automation could use a declaration key beginning with heartbeat-task: and have it silently treated as a doctor-migrated heartbeat task. Cron reported success while bypassing normal event delivery; with heartbeat disabled, the automation produced no operator-visible result.

Why This Change Was Made

Cron creation now reserves the migrated heartbeat-task declaration namespace behind the existing systemOwned service authority. One canonical predicate owns prefix classification and is shared by creation validation and runtime job detection. Existing doctor-migrated rows remain executable, editable, and removable.

This deliberately avoids duplicating namespace policy in the CLI, Gateway schema, public config, protocol, or storage layer. The net-neutral attempt reused the existing ownership option and consolidated prefix detection; the remaining production growth establishes the missing owner boundary.

Production LOC: +14/-6 (net +8) | Tests: +28/-11 (net +17)

User Impact

Ordinary automation declarations using the reserved heartbeat-task: namespace now fail with an explicit system-owned error before persistence. Normal declaration keys continue to create and run as before, and migrated heartbeat tasks remain fully manageable.

Evidence

  • Pre-fix regression: the reserved declaration unexpectedly resolved and persisted instead of rejecting.
  • Focused current-main proof:
    • node scripts/run-vitest.mjs src/cron/service.heartbeat-payload.test.ts src/commands/doctor-heartbeat-task-migration.test.ts
    • 2 cron tests and 12 doctor-migration tests passed.
  • Current changed gate:
    • node scripts/check-changed.mjs -- src/commands/doctor-heartbeat-task-migration.test.ts src/cron/heartbeat-task.ts src/cron/service.heartbeat-payload.test.ts src/cron/service/ops-mutations.ts src/cron/service/state.ts
    • Core production/test typechecks, changed-file Oxlint, formatting, import cycles, dependency, database-first, and repository guards passed. Remote workload routing was unavailable, so the wrapper used its documented local fallback.
  • Full build passed on Blacksmith Testbox run 31814183883.
  • Isolated built CLI/Gateway proof with heartbeat disabled:
    • reserved declaration exited 1 with a system-owned error and persisted no job;
    • an ordinary declaration created, listed, and removed successfully;
    • isolated free port/state, no external delivery.
  • Final immutable Codex autoreview: clean; no accepted/actionable findings. It confirmed the best-fix owner boundary and no Gateway, schema, config, protocol, security, or storage contract change.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete steipete self-assigned this Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 16:16
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:23 PM ET / 16:23 UTC.

ClawSweeper review

What this changes

The PR reserves the doctor-migrated heartbeat-task: cron declaration namespace so public automation creation is rejected while existing migrated tasks remain runnable, editable, and removable.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This is a focused owner-boundary repair for a source-reproducible silent cron-delivery failure; I found no blocking patch defect. It is maintainer-authored/labeled, so it should remain for normal maintainer merge judgment after exact-head checks finish.

Priority: P1
Reviewed head: ba8d34954d3e818c0d0031b5324cddb2b40fa307

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-verified fix with meaningful regression coverage and no blocking review findings.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an isolated built CLI/Gateway after-fix scenario.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an isolated built CLI/Gateway after-fix scenario.
Evidence reviewed 8 items Current-main defect path: Current main accepts a public declaration key without a namespace ownership check before persisting it.
Public entry point: The Gateway validates public cron input and calls the service without systemOwned; that option is not part of the closed public add schema.
Observable failure mechanism: Before normal main-session delivery, runtime classifies a main-session system-event job with the prefix as a heartbeat task and requests a heartbeat wake instead.
Findings None None.
Security None None.

How this fits together

Gateway and CLI cron requests create persisted jobs through the cron service; execution later selects normal main-session delivery or the heartbeat-task wake path. The change protects creation so a public declaration cannot enter the migration-only execution path.

flowchart LR
  A[CLI or Gateway declaration] --> B[Cron creation service]
  B --> C{Reserved heartbeat-task key?}
  C -->|Public caller| D[Explicit system-owned error]
  C -->|Doctor-owned caller| E[Persisted cron job]
  C -->|Ordinary key| E
  E --> F[Runtime classification]
  F --> G[Heartbeat wake or normal event delivery]
Loading

Before merge

  • Resolve merge risk (P1) - This intentionally rejects future create/upsert calls using heartbeat-task:; existing matching rows remain directly editable and removable, but no automatic cleanup is added for previously mis-created declarations.
  • Resolve merge risk (P1) - Production code is net +8 lines; the shared predicate and creation check are the minimal non-duplicated ownership boundary, so there is no credible net-neutral alternative without scattering prefix policy.
  • Complete next step (P2) - No repair lane is needed: this maintainer-labeled PR has no actionable finding and should proceed through normal maintainer merge review once exact-head checks complete.
Agent review details

Security

None.

PR surface

Source +8, Tests +17. Total +25 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 6 +8
Tests 2 28 11 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 42 17 +25

Review metrics

Metric Value Why it matters
Production versus test LOC production +8, tests +17 The bug fix adds one shared ownership predicate and one service guard; test growth covers rejection plus retained migrated-row behavior.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-heartbeat-task-migration.test.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #123728
Summary: This PR is the focused candidate fix for the linked public cron declaration impersonation bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the reserved namespace (recommended)
    Merge the intentional fail-closed rule: new public creates and declaration-key upserts fail explicitly, while persisted rows remain manageable by ID.
  2. Add an upgrade migration only if required
    Pause for a narrow migration only if maintainers require already-miscreated declarations to remain declaratively updatable through the reserved key.

Technical review

Best possible solution:

Land the single cron-service namespace guard after exact-head checks are green, preserving the existing runtime classification and direct update/remove path for persisted rows.

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

Yes—source-reproducible with a public main-session systemEvent cron declaration whose key starts heartbeat-task:; current main accepts it, then runtime takes the heartbeat-task wake branch before normal delivery.

Is this the best way to solve the issue?

Yes. The service creation boundary is the narrowest canonical fix because both CLI and Gateway converge there; schema-, CLI-, or runtime-only guards would duplicate or miss the ownership policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2b31cf114ba4.

Labels

Label changes:

  • add P1: The repaired path can report successful cron execution while silently bypassing normal main-session event delivery.
  • add merge-risk: 🚨 compatibility: The patch deliberately adds strict validation for a previously accepted declaration-key namespace, changing create/upsert behavior on upgrade.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an isolated built CLI/Gateway after-fix scenario.

Label justifications:

  • P1: The repaired path can report successful cron execution while silently bypassing normal main-session event delivery.
  • merge-risk: 🚨 compatibility: The patch deliberately adds strict validation for a previously accepted declaration-key namespace, changing create/upsert behavior on upgrade.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an isolated built CLI/Gateway after-fix scenario.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame ties the prefix classifier and creation path to commit c3ae887; the same area is repaired by this PR. (role: introduced behavior and current repair author; confidence: high; commits: c3ae887f465a, ba8d34954d3e; files: src/cron/heartbeat-task.ts, src/cron/service/ops-mutations.ts, src/cron/service/timer-execution.ts)
  • Ayaan Zaidi: Commit 7fcdded is the latest other recorded touch across the heartbeat-task and cron execution/migration surface. (role: recent adjacent contributor; confidence: medium; commits: 7fcddedaaf63; files: src/cron/heartbeat-task.ts, src/cron/service/timer-execution.ts, src/commands/doctor-heartbeat-task-migration.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head required checks complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper review disposition before merge:

  • Accept the intentional compatibility boundary. heartbeat-task: is the doctor-owned migration namespace; new public create/upsert attempts must fail explicitly. Existing persisted rows remain executable and manageable by ID. No cleanup/migration is added because there is no observed persistent user state requiring one.
  • Accept production net +8. The patch reuses systemOwned and adds one canonical predicate plus the creation-owner check; moving the rule into CLI, Gateway schema, config, or runtime would duplicate policy or preserve invalid state.
  • Exact-head CI is complete and green: https://github.com/openclaw/openclaw/actions/runs/31818553650

The exact-head ClawSweeper review reports no findings and names this service-boundary repair as the best possible solution. Its sole Rank-up moves: item—complete exact-head required checks—is satisfied.

@steipete
steipete merged commit ffd42dd into main Aug 14, 2026
239 of 247 checks passed
@steipete
steipete deleted the fix/cron-heartbeat-task-namespace branch August 14, 2026 16:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Public cron declarations can impersonate migrated heartbeat tasks

1 participant