Skip to content

perf(cron): reuse the selected partition for prompt scratch - #180816

Merged
steipete merged 2 commits into
mainfrom
dbasync/autoproj
Oct 22, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/autoproj

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Scheduled automation prompt preparation reselects the cron partition synchronously even though the Gateway already selected and owns it.

User Impact

Gateway cron turns avoid a runtime MAIN-thread database lookup. Scratch contents, partition selection, standalone callers, and session storage behavior are preserved. No migration or configuration change is required.

Why This Change Was Made

Carry the selected cron store through the existing job runner and preparation request as cronStorePath. It remains distinct from the session storePath. Standalone callers retain their configuration-based selection. This removes a repeated lookup without adding a cache, generation, schema change, transaction, or authority check.

Evidence

  • The production prompt regression fails on the base's caller SQL, then checks selected-partition reads, fresh scratch after an in-process write, and standalone fallback after partition changes.
  • Scratch: 16 tests passed with verified compiled artifacts. Corrected-head Gateway runner replay: 85 passed; CI covers scheduled plugin commands.
  • Formatting, basic lint and final line-cap check pass. Two isolated Codex review rounds found no actionable P0–P2 findings. Worker T1 calls remain 170/15; dialect constructs remain unchanged. The local compiler wrapper refuses the approved internal dependency store before compilation; exact-head CI supplies type-aware proof. Knip findings match the exact base (36 production / 55 full-tree / 0 scripts); no new findings. Exact-head CI 39823789470 passed, including all three PostgreSQL shards; the aggregate, security, and dependency gates are green.
  • Frozen v3.1.4 baseline at d2c70ddbf19: cron 242 SQL / 64 requests / 1 MAIN; warm median 45 [45–48] / 11 [11–12] / 0. Measured cron: 242/64/1 → 242/64/0; the removed MAIN lookup is offset by one unrelated background statement. Warm causal counts remain 45 [45–48] / 11 [11–12] / 0. Whole workload 2934/798/98 → 2939/801/96. The single frozen pair passed 14 turns, cron, shutdown and restart. No aggregate or latency savings claim.
  • Production +9/−4 lines; tests +39/−1 lines.

Concurrent Work

Natural merge checks are clean against #178965 (35ae687) and #178904 (5570f12). Draft heads #179011 (ffc0372), #179062 (941c2b0) and #179669 (3b24d61) have exactly the same 17 conflicts with both the unchanged base and this head, all outside this PR's edited files. The coordinator accepted these inherited conflicts. Additional main-targeted PRs #156667, #152243, #141018, #172601, #173953 and #175678 have unchanged conflict sets against the base and corrected head. Their existing conflict blocks are unchanged except for the expected added storePath argument inside #152243’s broad server-cron.ts block; no Workshop logic changed. The release-branch backport #180270 is excluded from the main-branch fence.

Credit: builds on the scheduled-command runner by Jason (Json), @fuller-stack-dev. Preserve this human credit in the squash commit:

Co-authored-by: Jason (Json) [email protected]

Carry the Gateway-owned cron partition through scheduled run preparation, keeping the standalone configuration fallback. Avoid the runtime MAIN database lookup without confusing the session store with the cron store.
@clawsweeper

clawsweeper Bot commented Oct 22, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T17:23:14.935403Z 87e0296 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
Keep the selected cron partition separate from the service parameter surface.

Co-authored-by: Jason (Json) <[email protected]>
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR carries the Gateway-selected cron partition into automation prompt preparation instead of selecting it again.

Example: Job scratch-owner has scratch revision 2 containing updated scratch.

  • Before: Prompt preparation synchronously looks up the cron partition before reading scratch.
  • After: Gateway runs reuse their selected partition and include revision 2 without that lookup; standalone callers retain configuration-based selection.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-supported, with a meaningful production-owner regression; direct inspection of the reported Gateway measurement is limited to the body account.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate and changes no authority chain. Its body records a production Gateway baseline/candidate workload; the inspected screenshots show an automation reply rather than partition selection or SQL counts, so they provide no additional proof of this optimization.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Scheduled automation preparation performs an avoidable synchronous database lookup on the Gateway thread.
Reason: The maintainer-authored direction follows the repository's prepared-fact ownership rule and removes measured caller-thread work without introducing another state owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR removes a redundant main-thread partition lookup through the existing cron owner, with no actionable correctness or security findings.

Priority: P2
Reviewed head: e0c7f6fcedced964e179a199649bbd2535ab5106

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway cron service selects a job partition and dispatches scheduled runs; preparation reads that partition's current scratch through the existing worker and appends it to the agent prompt.

flowchart TD
  A[Gateway partition selection] --> B[Cron service]
  B --> C[Scheduled job runner]
  C --> D[Automation prompt preparation]
  E[Standalone configuration selection] --> D
  D --> F[Scratch read worker]
  F --> G[Agent prompt]
Loading

Technical review

Best possible solution:

Reuse the cron service's selected partition while keeping scratch freshness and standalone selection with their existing owners.

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

Current-main prompt preparation reaches the synchronous machine-state partition reader; the committed regression targets that path, and the PR reports its base failure without this review executing code.

Is this the best way to solve the issue?

This is the smallest complete fix: carry the already-selected partition through existing owners, keep the session store separate, and preserve the standalone fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 71bbd18bb2a9.

Provenance checked

  • Automation prompt scratch selection keeps the original intent (ec5d369: The heartbeat migration made ordinary Automations authoritative for scratch and prompt context.)
  • Scratch worker admission and freshness keeps the original intent (cbc0a9d: Move scratch reads off the Gateway thread while retaining original scope and current admission checks.)
  • Scheduled-command dispatch before ordinary prompt preparation keeps the original intent (ad40743: Requester-bound plugin schedules must execute through their reserved command path rather than ordinary agent prompts.)
  • Gateway service partition ownership keeps the original intent (04d4e9c: Prepare startup database facts asynchronously and retain the service's selected store.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit ad40743 adds src/gateway/server-cron-agent-run.ts:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad407430c464; files: src/gateway/server-cron-agent-run.ts)

PR surface

Source +5, Tests +38. Total +43 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 9 4 +5
Tests 3 39 1 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 48 5 +43

Review metrics

Metric Value Why it matters
Production versus test changes Production +9/−4; tests +39/−1 The small production increase carries the existing partition across preparation boundaries; the regression checks selection, freshness, and standalone behavior.

Labels

Label changes:

  • add P2: Removes synchronous database work from scheduled prompt preparation with limited scope and no demonstrated urgent user-facing outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Removes synchronous database work from scheduled prompt preparation with limited scope and no demonstrated urgent user-facing outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 22, 2026, 1:51 PM ET / 17:51 UTC.

@steipete
steipete merged commit 691a3e1 into main Oct 22, 2026
142 of 143 checks passed
@steipete
steipete deleted the dbasync/autoproj branch October 22, 2026 17:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…#180816)

Reuse the Gateway-selected cron partition during isolated automation prompt preparation, keeping session storage separate and preserving standalone config selection. Removes one runtime MAIN SQL lookup per cron turn.

Co-authored-by: Jason (Json) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant