Skip to content

fix(cron): keep scratch reads scoped to their current owner - #161387

Merged
steipete merged 2 commits into
mainfrom
codex/cron-scratch-reader-20260929
Sep 29, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/cron-scratch-reader-20260929

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Automation scratch reads can return private content after their caller closes or a peer changes the job owner, and they still execute SQLite on the Gateway thread.

User Impact

Scratch reads now use the existing worker and retain the original caller and job scope. Legacy jobs without creation metadata can read and update scratch without a false definition conflict. Wire results, schema, retention and Doctor's maintenance behavior stay unchanged.

Why This Change Was Made

The worker reads the job definition and scratch in one transaction. The service compares that definition with the authorized job, and the Gateway checks caller authority again before replying. Heartbeat preflight awaits scratch before selecting its session and pending events. First-use opening stays with the canonical mutable actor; the read worker owns no schema writes.

Reads and writes reuse the original projection's creation-time fallback only when the stored metadata is absent or nonfinite. Actual persisted values still win. The write transaction, revision CAS, live commit guards and retained outcome remain the same owners. Scratch handlers and their privacy regressions move into focused siblings with the existing worker routing.

Evidence

Causal controls reproduce caller-thread SQL, private responses after caller closure and foreign owner transfer, and the legacy read/write false conflicts. The repaired paths pass. Runtime coverage is 500 unique cases composed from 20 final scratch cases, 262 Gateway receiving cases and 218 unchanged owner cases retained from the earlier 495-case run; this is not one 500-case invocation. Core and all 27 test type graphs, affected typed lint, scripts lint, all three unused-export scans and architecture guards pass. Fresh independent P0–P2 production review and P0–P3 final test review are clean. The legacy regression now pins only the clock-derived fallback returned by the real load, without polling. Removing the read fallback or the write fallback independently still causes the intended definition-conflict failure.

The final runtime-only build passed in 112.796s. The real built CLI/Gateway flow passed scratch set/read, restart persistence, unset and stale-revision refusal, plus the existing scheduler scenarios (78.966s scenario; 139.924s command). The final deterministic 20-case scratch command took 42.946s and four-file Gateway command 94.483s. Local proof uses macOS arm64 and Node 24.21; command timings include compilation and different warm states, not a request-latency comparison. No local Linux, Bun or published-driver execution is claimed.

Broad core lint found an inherited UI max-lines violation in ui/src/pages/model-setup/model-setup-page.ts (705 versus 700). Its blob is identical to the fixed base; the Cron change modifies no UI or lint policy. The failure is retained, the affected files pass, and the independent UI repair has its own owner.

Current CI attempt 2 (run 36633755509) finished with two test failures and a separate boundary-job deadline. The Codex launcher loses late stderr after process exit; controlled real-launcher cases reproduce the defect on the exact main baseline and tested merge, with repair in #161419. The TTS fixture incorrectly requires nonempty response text after a warm snapshot restores the answer; independent main reproduces that predicate failure, and c90f579d fixes the fixture. These controls do not claim the exact uninstrumented CI event ordering or snapshot state.

The boundary job completed all 126 plugin compiles and its required canary, but GitHub cancelled the whole job at its 20-minute deadline. The measured budget correction is 5e5e50e8. Its cancelled conclusion remains recorded. Final accounting is 90 successful, 51 cancelled, 21 skipped and 3 failed jobs (the two test roots plus the aggregate); 50 cancellations belong to the Node matrix and the boundary deadline is separate. Cancelled or skipped work is not passing coverage. The initial queued attempt executed no steps during the Blacksmith outage; one same-head hosted rerun produced these results.

Stream-state writes, remaining creator/session currentness and Doctor/roster caller migration remain separate work in the original campaign.

Related: #161332.

Move ordinary scratch reads through the existing shared-state reader. Bind
private content to the same native job-definition snapshot and recheck the
original source and caller before reply. Preserve first-use initialization
through the canonical actor and the synchronous Doctor maintenance owner.

Reuse the original creation-time fallback for legacy scratch read/write
revision checks without overriding finite persisted values. Keep the existing
write transaction, CAS, live grants and retained-outcome protocol.

Qualify with causal SQL/privacy/legacy controls, 500 composed unique runtime
cases, current core and 27 test type graphs, affected lint and architecture
guards, clean independent review, runtime build and real Gateway restart flow.
Retain the independently attributed unchanged UI max-lines failure separately.
@clawsweeper

clawsweeper Bot commented Sep 29, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Sep 29, 2026
@steipete
steipete marked this pull request as ready for review September 29, 2026 21:09
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. 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 Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 7:14 PM ET / 23:14 UTC (Revision 3).

ClawSweeper review

What this changes

The branch moves private automation scratch reads to OpenClaw's SQLite read worker, checks job and caller scope before returning content, and preserves reads and writes for legacy jobs missing creation metadata.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open. Current main still has the reported scratch-read path, and the merged write-side PR explicitly left reads for follow-up. The current head retains a distinct repair, with no blocking patch defect established in this review.

Priority: P0
Reviewed head: 1178a8c5089c0d4dc6ff8d7db92bfb1133c6fde0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused authority coverage and a reported real Gateway flow; the read-only review found no blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured PR body records a built CLI/Gateway run on macOS arm64 and Node 24.21 with after-fix scratch read, restart persistence, unset, and stale-revision refusal; production-handler and SQLite-worker regressions cover closed-caller and transferred-owner refusal before response. No stored schema or row representation changes, so data-model compatibility is not applicable. The run was reported by the contributor and was not repeated in this read-only review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured PR body records a built CLI/Gateway run on macOS arm64 and Node 24.21 with after-fix scratch read, restart persistence, unset, and stale-revision refusal; production-handler and SQLite-worker regressions cover closed-caller and transferred-owner refusal before response. No stored schema or row representation changes, so data-model compatibility is not applicable. The run was reported by the contributor and was not repeated in this read-only review.
Evidence reviewed 10 items Current main still uses the original read: The service reads scratch through the synchronous store path after loading the job; it has no worker snapshot or post-read caller check.
Introduced snapshot boundary: The pinned PR diff adds one transaction that reads the selected job definition and its scratch state together.
Final reply guard: The introduced Gateway handler checks live client authority and the job's caller scope again after the awaited read and before responding.
Findings None None.
Security None None.

How this fits together

Automation scratch is private per-job data in OpenClaw's shared SQLite state. Gateway requests and heartbeat preflight read it through the Cron service or read adapter before returning a result or adding context to a heartbeat.

flowchart LR
 A[Automation scratch request] --> B[Gateway caller check]
 H[Heartbeat preflight] --> C[Scratch read adapter]
 B --> C
 C --> D[SQLite read worker]
 D --> E[Job and scratch snapshot]
 E --> F[Current authority check]
 F --> G[Scratch result or refusal]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +219, Tests +321, Docs +7. Total +547 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 18 411 192 +219
Tests 7 399 78 +321
Docs 1 9 2 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 26 819 272 +547

Review metrics

Metric Value Why it matters
Production and test growth production +411/−192 lines; tests +399/−78 lines The production growth adds the worker snapshot and authority checks while retiring the ordinary synchronous read path.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/cron/service/ops-read.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #161387
Summary: This PR owns the outstanding scratch-read repair; the merged write-side work overlaps the subsystem, while the Codex launcher PR addresses a separate failure found during validation.

Members:

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

Technical review

Best possible solution:

Keep one authoritative job-and-scratch snapshot, refuse private replies after caller revocation or owner change, and let legacy jobs work without rewriting their stored rows.

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

Yes. Current-main source has an awaited scratch read after the initial Gateway scope check with no final caller recheck; the PR tests identify closure and peer-owner-transfer cases. This review did not execute the defect.

Is this the best way to solve the issue?

Yes. A single worker snapshot for the definition and content, followed by service and Gateway checks, is a bounded repair of the existing privacy contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 69d06b0b9c63.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The merged behavior would rely on new snapshot and final-reply checks to keep private scratch within its current caller and job scope.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records a built CLI/Gateway run on macOS arm64 and Node 24.21 with after-fix scratch read, restart persistence, unset, and stale-revision refusal; production-handler and SQLite-worker regressions cover closed-caller and transferred-owner refusal before response. No stored schema or row representation changes, so data-model compatibility is not applicable. The run was reported by the contributor and was not repeated in this read-only review.

Label justifications:

  • P0: The reported failure can expose private automation scratch after caller authority closes or job ownership changes.
  • merge-risk: 🚨 security-boundary: The merged behavior would rely on new snapshot and final-reply checks to keep private scratch within its current caller and job scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured PR body records a built CLI/Gateway run on macOS arm64 and Node 24.21 with after-fix scratch read, restart persistence, unset, and stale-revision refusal; production-handler and SQLite-worker regressions cover closed-caller and transferred-owner refusal before response. No stored schema or row representation changes, so data-model compatibility is not applicable. The run was reported by the contributor and was not repeated in this read-only review.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records a built CLI/Gateway run on macOS arm64 and Node 24.21 with after-fix scratch read, restart persistence, unset, and stale-revision refusal; production-handler and SQLite-worker regressions cover closed-caller and transferred-owner refusal before response. No stored schema or row representation changes, so data-model compatibility is not applicable. The run was reported by the contributor and was not repeated in this read-only review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-29T21:20:04.234Z sha 5bd96c5 :: blocked before merge. :: [P3] Use a deterministic clock in the legacy-row regression
  • reviewed 2026-09-29T21:38:20.462Z sha 1178a8c :: blocked before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the legacy-test clock finding: the test calls through the real SQLite load and pins only its transient creation-time fallback, then restores the call-through spy before the real scratch reads and writes. No polling, timer change, production seam, or weakened assertion remains. The whole scratch suite passes 20/20; removing either native fallback independently reproduces the intended read or write conflict. Fresh P0–P3 review is clean.

The generated data-model flag is not applicable. No schema, persisted JSON shape, version, retention, or upgrade driver changes. The optional creation fallback is transient: a finite stored value always wins, and the test proves a later persisted definition change is rejected. Existing Doctor imports and maintenance kernels are unchanged. The earlier 31 Doctor cases and final built Gateway restart/persistence flow remain applicable because this follow-up changes only the fixture. No published-driver run is claimed.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The clock finding is addressed in 1178a8c. The linked disposition records both causal fallback controls and the unchanged stored-schema/Doctor applicability boundary: #161387 (comment)

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete enabled auto-merge (squash) September 29, 2026 21:36
@steipete
steipete disabled auto-merge September 29, 2026 22:27
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 29, 2026
@steipete
steipete merged commit cbc0a9d into main Sep 29, 2026
187 of 278 checks passed
@steipete
steipete deleted the codex/cron-scratch-reader-20260929 branch September 29, 2026 23:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…#161387)

* fix(cron): keep scratch reads scoped across worker waits

Move ordinary scratch reads through the existing shared-state reader. Bind
private content to the same native job-definition snapshot and recheck the
original source and caller before reply. Preserve first-use initialization
through the canonical actor and the synchronous Doctor maintenance owner.

Reuse the original creation-time fallback for legacy scratch read/write
revision checks without overriding finite persisted values. Keep the existing
write transaction, CAS, live grants and retained-outcome protocol.

Qualify with causal SQL/privacy/legacy controls, 500 composed unique runtime
cases, current core and 27 test type graphs, affected lint and architecture
guards, clean independent review, runtime build and real Gateway restart flow.
Retain the independently attributed unchanged UI max-lines failure separately.

* test(cron): pin legacy scratch creation fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

1 participant