Skip to content

fix(cron): keep descendant reads off the Gateway thread - #160508

Merged
steipete merged 3 commits into
mainfrom
codex/cron-descendant-worker-20260928
Sep 28, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/cron-descendant-worker-20260928

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron jobs still performed synchronous SQLite reads on the Gateway thread when checking descendant work, waiting for child summaries, or deciding whether delivery could proceed.

User Impact

Cron descendant observations now await the existing database read worker, keeping the host responsive during those reads. Pending descendants, successor runs, cancellation, and completion-delivery settlement retain their existing behavior. No configuration, schema, retention, or update changes are required.

Why This Change Was Made

The private Cron runtime adapter uses the existing registry snapshot owner and descendant query policies. Freshness and active-execution facts share one consuming frame, and run draining awaits a fresh observation at each refresh. Failed admission does not become an empty descendant set. The obsolete internal synchronous list adapter is removed.

Reaper and continuation deletion guards remain assigned to the separate lifecycle-writer migration: an earlier asynchronous observation cannot replace a current transaction guard.

Evidence

The actual Cron fallback failed on the original implementation with six host SQLite calls (two prepares, three gets, one all). With the migration, all eight observed host SQLite operation counters stay zero while a real worker reply is held, an event-loop turn proceeds, and the correct child answer returns after release.

The retained and rerun proof covers 344 unique cases, including committed update/delete/successor publication, another requester's ownership, close/source replacement/caller cancellation, freshness, yielded work, and queued delivery. CI correctly caught an introduced exported-name collision at e87cb3de; the private async operation is now hasUnsettledCronDescendants. All 227 affected runtime cases passed again, including all 14 worker cases, while the 117 unaffected cases retain their prior passing proof. The failed export guard, affected types, and lint pass after the correction. Independent full and delta reviews found no actionable P0–P2 issue.

The original candidate passed production types, all 26 core test type graphs, selected static guards, and full pnpm build. The private binding correction additionally passed core/Cron types and the maintained pnpm build qaRuntime profile; the full declaration build was not repeated for this identifier-only delta.

The old auto-merge request was explicitly retired before head replacement, with its native outcome retained. A real later conflict in the interim-retry fixture was resolved against one fixed main revision, 01747d9b2b11. The canonical fixture cleanup is preserved, including the paired descendant observation and cancellation-during-await controls. All production postimages remain identical to the prior reviewed head. The receiving composition passed all 24 fixture/real-worker cases, Cron types, type-aware lint, formatting, qaRuntime, and a fresh full candidate review.

Current head is 0c3b6d2b1065ddd719a3e4e548b915f4ae193f15. Exact-head CI 36464397184 completed with 163 successful jobs, 21 skipped jobs, one deadline-cancelled Node job, and its failed aggregate gate. Earlier export, UI, and heartbeat failures remain historical failures; their exception evidence is not reused for this head.

The remaining Node job first timed out in the unchanged session-change-event.test.ts held-generation fixture. It awaits publication draining before advancing fake timers, while the publication budget reads a real clock and may yield to fake setImmediate. The exact tested merge 829eb7ac and baseline 5117d94b have identical fixture, Gateway/UI/plugin, harness, and dependency inputs. The synthetic projection does not enter the changed Cron or run-wait paths; its imported live-registry accessors are unchanged. Independent source inspection supports the pre-existing-failure attribution. No baseline runtime reproduction is claimed here.

The log retains 408 passing case lines and 18 failing cases, including subsequent cleanup timeouts and a later unexpected-broadcast assertion. GitHub reports the one-hour deadline in its check annotations and records the job as cancelled. The uncompleted shard coverage remains unproven; CI is not presented as green. The exact-head review keeps tests.result=fail and the current run/attempt attribution for the explicitly authorized exception. The current hosted code review completed with no findings, security issues, or before-merge items. Native admission still revalidates current authority, reviews, security, source evidence, and the exact prepared head.

Measured proof cost and timing-review disposition

These are retained command and shard measurements, not invented standalone single-worker wall times for every file.

Scope Measured time Qualification
Original Cron fallback regression 99.27 s command wall; 648,560,640 B maximum RSS Expected failure: six host SQLite calls.
Initial 14-case worker invocation 130.05 s command wall; 6,726,762,496 B maximum RSS Cold worker compilation included; 11 passed and three incomplete fixture rows failed.
Corrected three worker classification cases 46.57 s command wall; 664,666,112 B maximum RSS Three passed; unchanged cases were initially reused.
Initial Cron follow-up, delivery, and interim-retry siblings 189.67 s reported shard duration 224 passed.
Initial run-wait and async-observation siblings 119.60 s reported shard duration 62 passed. Combined five-file command: 347.83 s wall time.
Registry scoped/query retirement checks 96.55 s reported shard duration; 145.31 s wrapper elapsed 44 passed.
Corrected binding: worker, follow-up, and delivery files 144.73 s command wall All 227 passed, including a complete green 14-case worker run.
Original full build 2,489.03 s command wall Passed; cold declaration generation dominated.
Corrected binding runtime build 118.71 s command wall Maintained qaRuntime profile passed.
Fixed-main receiving fixture and real worker 372.14 s wrapper; 352.48 s shard All 24 cases passed; transform work dominated.
Fixed-main runtime build 164.5 s reported phase total Maintained qaRuntime profile passed.
Prior 19a CI UI shard 7/9 626 s job elapsed Unchanged mocked /side timeout, then cleanup/fork retirement; failed.

The real-worker test protects SQL placement, publication freshness, and lifecycle refusal; a mock cannot establish those boundaries. Compiler/import and inherited sibling costs are included above. Different case counts and cache states prevent a valid whole-command before/after speed comparison. Test-support files have no independent executable wall time.

The initial hosted review found no code or security defect; its two before-merge items requested additional per-file timing reporting. The maintainer disposition retains the completed causal and sibling proof, reports actual costs and limits, and avoids repeating passing suites solely for a timing inventory. The prior 19a hosted review completed at 16:14:18 UTC with no findings, security issues, or before-merge items. Current admission still verifies the exact head, review, security, and attributed CI exception.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review September 28, 2026 15:10
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 4:06 PM ET / 20:06 UTC (Revision 7).

ClawSweeper review

What this changes

The branch moves scheduled-run descendant checks and follow-up reads through the subagent registry’s SQLite read worker, updates wait handling and tests, and documents the worker boundary.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still use synchronous Cron descendant reads, while this branch has credible real-worker proof and no established introduced defect.

Priority: P2
Reviewed head: 0c3b6d2b1065ddd719a3e4e548b915f4ae193f15

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the existing registry owner and has strong real-worker proof; the cancelled CI shard remains for native admission to assess.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): In isolated OpenClaw state, the production Cron fallback uses the real SQLite read worker while its reply is held: the event loop proceeds, parent-thread SQLite counters remain zero, and the child answer returns after release. The PR body records the before-fix host calls and passing follow-up runs. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): In isolated OpenClaw state, the production Cron fallback uses the real SQLite read worker while its reply is held: the event loop proceeds, parent-thread SQLite counters remain zero, and the child answer returns after release. The PR body records the before-fix host calls and passing follow-up runs. No stored-data contract changes.
Evidence reviewed 7 items Current main retains synchronous readers: The current-main Cron runtime adapter still exports the synchronous descendant readers, so the central change remains absent.
Latest release retains synchronous readers: The same adapter in v2026.9.6 exports the synchronous readers.
Worker-backed descendant observation: The introduced Cron adapter selects the descendant closure from registry facts and consumes hydrated runs through the existing snapshot owner.
Findings None None.
Security None None.

How this fits together

Scheduled Cron runs can spawn child agents whose state is kept in the subagent registry. Cron reads that state to decide whether to wait, use a child reply, or deliver its own result.

flowchart LR
A[Scheduled Cron run] --> B[Agent response]
B --> C[Subagent registry]
C --> D[SQLite read worker]
D --> E[Descendant status and replies]
E --> F[Wait or settle delivery]
F --> G[Outbound result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +50, Tests +367, Docs +10. Total +427 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 7 102 52 +50
Tests 10 471 104 +367
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 583 156 +427

Review metrics

Metric Value Why it matters
Production and test LOC production +102/-52 (net +50); tests and support +471/-104 (net +367) The production growth builds the worker-backed Cron adapter; most added code exercises the real worker and affected behavior.

Technical review

Best possible solution:

Use the registry-owned worker snapshot for Cron observations while preserving existing settlement rules and the separate lifecycle deletion guards.

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

Yes. Current-main source still routes Cron descendant reads through synchronous registry readers, and the PR records a real-worker regression that made six host SQLite calls before the change; this read-only review did not run it.

Is this the best way to solve the issue?

Yes. Reusing the registry snapshot owner removes the synchronous Cron adapter without adding configuration, a stored format, or a competing registry owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3775359ab87d.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This bounded runtime responsiveness fix affects scheduled runs without evidence of an emergency or broadly broken user workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): In isolated OpenClaw state, the production Cron fallback uses the real SQLite read worker while its reply is held: the event loop proceeds, parent-thread SQLite counters remain zero, and the child answer returns after release. The PR body records the before-fix host calls and passing follow-up runs. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. In isolated OpenClaw state, the production Cron fallback uses the real SQLite read worker while its reply is held: the event loop proceeds, parent-thread SQLite counters remain zero, and the child answer returns after release. The PR body records the before-fix host calls and passing follow-up runs. No stored-data contract changes.

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)
  • Jason (Json): 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 (6 earlier review cycles)
  • reviewed 2026-09-28T15:15:10.609Z sha e87cb3d :: blocked before merge. :: none
  • reviewed 2026-09-28T15:33:26.753Z sha e87cb3d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T16:06:14.934Z sha 19a3abb :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T16:14:18.050Z sha 19a3abb :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T17:28:51.862Z sha 19a3abb :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T18:32:14.790Z sha 0c3b6d2 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Sep 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the two timing-reporting items in the completed review: the PR body now records the retained command/shard wall times, RSS where measured, fixture-rerun composition, and cold-compiler limits.

Standalone single-worker wall times were not measured for every file. I am retaining the completed causal, lifecycle, and sibling proof rather than rerunning passing suites solely for a timing inventory. The real-worker boundary needs actual SQLite/worker execution; the grouped timings also include inherited compiler/import and outbound-adapter costs. No overall speedup is claimed from these noncomparable invocations.

This is the maintainer disposition of those reporting requests, not a claim that the bot changed its blocked-readiness text. The review found no code or security defect. CI, security, exact-head preparation, and native admission remain enforced; CI duration will be recorded after the active exact-head run finishes.

@steipete
steipete enabled auto-merge (squash) September 28, 2026 15:31
@steipete
steipete disabled auto-merge September 28, 2026 15:41
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 28, 2026
Integrate one fixed main revision for the real interim-retry test conflict. Preserve the canonical fixture cleanup and the paired descendant-state and cancellation-during-observation controls; production migration postimages remain unchanged.

Validation: 24 receiving fixture and real-worker cases, Cron types, lint, formatting, qaRuntime build and fresh full-candidate review. Prior-head CI attribution remains historical and will not qualify the replacement head.
@steipete
steipete merged commit 71cc104 into main Sep 28, 2026
259 of 262 checks passed
@steipete
steipete deleted the codex/cron-descendant-worker-20260928 branch September 28, 2026 20:27
@steipete

Copy link
Copy Markdown
Contributor Author

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

steipete added a commit that referenced this pull request Sep 28, 2026
Recover the focused clock repair from f46483c (#160182), whose
performance work was superseded while this validated fixture fix remained
unmerged. Fake debounce timers and real publication budgets could deadlock
the held-generation drain and cascade through the rest of the CI shard.
Bind the fixture's performance clock to fake Date and restore it before the
real-I/O case and at test completion. Production budgets and assertions stay
unchanged.

Validation: a finite CPU workload reproduces the original test/hook timeout
on CI's pinned Bun and passes both churn variants after the repair. The
normal owner/sibling suites pass 41 cases; the original CI selection passes
452 cases across 27 files. Complete changed checks and independent Codex
P0-P2 review pass. Testbox proof: run 36476506157.

Related: #160508, #160182
Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
)

* fix(cron): keep descendant reads off the Gateway thread

* fix(cron): distinguish the async settlement reader
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
Recover the focused clock repair from f46483c (openclaw#160182), whose
performance work was superseded while this validated fixture fix remained
unmerged. Fake debounce timers and real publication budgets could deadlock
the held-generation drain and cascade through the rest of the CI shard.
Bind the fixture's performance clock to fake Date and restore it before the
real-I/O case and at test completion. Production budgets and assertions stay
unchanged.

Validation: a finite CPU workload reproduces the original test/hook timeout
on CI's pinned Bun and passes both churn variants after the repair. The
normal owner/sibling suites pass 41 cases; the original CI selection passes
452 cases across 27 files. Complete changed checks and independent Codex
P0-P2 review pass. Testbox proof: run 36476506157.

Related: openclaw#160508, openclaw#160182
Co-authored-by: Vincent Koc <[email protected]>
steipete added a commit that referenced this pull request Sep 29, 2026
* refactor(cron): use database workers for session retention cleanup

Move continuation and reaper planning and ordinary deletion through the
existing reclamation worker while retaining live parent authority and
fresh durable descendant and maintenance checks before commit.

Preserve native mutation custody, cold validation proof, and publication
ordering. Carry session-absence authority through receipt cleanup.

Follow-up to #160508.

* fix(sessions): keep worker plan contracts independent of implementations

* fix(sessions): preserve SDK deletion state environment

Forward the existing SDK env option through lifecycle source capture,
while excluding it from cloneable deletion plans. Keep the physical
database ownership guard and all existing plugin assertions. Run the
SDK session-store tests in the existing host-broker worker group.

The original six-file Codex group passes all 24 cases, including both
CI failures; all 26 SDK session-store cases also pass. Core types,
scoped lint, SDK exports, line caps, and fresh Codex review pass.

* test(sessions): complete worker cleanup test routing

Route the conversation SDK deletion suite through the existing shared-state
host broker and import the reclamation runtime from its current owner.
Compare the archive destination by physical path on Windows while retaining
transcript contents and exact disk-accounting assertions.

The exact preceding CI exposed all three gaps. Focused runtime and routing
proof passes 504 cases with one Linux-only case skipped locally; affected
types and independent review pass. Windows CI remains platform proof.

* test(sessions): route remaining deletion consumers through broker

Complete the explicit core and plugin worker test registrations for real
permanent-deletion consumers. Preserve all archive and lifecycle assertions.

Control the clock only in the held-response Mattermost identity race:
the real five-second backfill deadline previously settled before cold
worker deletion committed. Keep the separate real deadline test unchanged.

Proof: 19 package cases, 185 unchanged Codex cases and 20 final Mattermost
cases, routing control, extension types, lint and fresh independent review.

* test(subagents): join retained cleanup before restart assertions

Wait for the existing admitted-work fixture to settle before polling row
removal, so asynchronous deletion cannot leave a restart fence contaminating
later cases. Preserve the original assertions, poll and timeout.

Route Feishu Doctor through the existing host broker for real SDK deletion.
Proof: original four-case sequence failed then passed after the one-statement
reorder; all 43 recovery/steer and 19 Feishu cases pass, with affected types,
lint, formatting and fresh independent review.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…aw#160858)

* refactor(cron): use database workers for session retention cleanup

Move continuation and reaper planning and ordinary deletion through the
existing reclamation worker while retaining live parent authority and
fresh durable descendant and maintenance checks before commit.

Preserve native mutation custody, cold validation proof, and publication
ordering. Carry session-absence authority through receipt cleanup.

Follow-up to openclaw#160508.

* fix(sessions): keep worker plan contracts independent of implementations

* fix(sessions): preserve SDK deletion state environment

Forward the existing SDK env option through lifecycle source capture,
while excluding it from cloneable deletion plans. Keep the physical
database ownership guard and all existing plugin assertions. Run the
SDK session-store tests in the existing host-broker worker group.

The original six-file Codex group passes all 24 cases, including both
CI failures; all 26 SDK session-store cases also pass. Core types,
scoped lint, SDK exports, line caps, and fresh Codex review pass.

* test(sessions): complete worker cleanup test routing

Route the conversation SDK deletion suite through the existing shared-state
host broker and import the reclamation runtime from its current owner.
Compare the archive destination by physical path on Windows while retaining
transcript contents and exact disk-accounting assertions.

The exact preceding CI exposed all three gaps. Focused runtime and routing
proof passes 504 cases with one Linux-only case skipped locally; affected
types and independent review pass. Windows CI remains platform proof.

* test(sessions): route remaining deletion consumers through broker

Complete the explicit core and plugin worker test registrations for real
permanent-deletion consumers. Preserve all archive and lifecycle assertions.

Control the clock only in the held-response Mattermost identity race:
the real five-second backfill deadline previously settled before cold
worker deletion committed. Keep the separate real deadline test unchanged.

Proof: 19 package cases, 185 unchanged Codex cases and 20 final Mattermost
cases, routing control, extension types, lint and fresh independent review.

* test(subagents): join retained cleanup before restart assertions

Wait for the existing admitted-work fixture to settle before polling row
removal, so asynchronous deletion cannot leave a restart fence contaminating
later cases. Preserve the original assertions, poll and timeout.

Route Feishu Doctor through the existing host broker for real SDK deletion.
Proof: original four-case sequence failed then passed after the one-statement
reorder; all 43 recovery/steer and 19 Feishu cases pass, with affected types,
lint, formatting and fresh independent review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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