Skip to content

fix: keep failed idle database cleanup from blocking every agent - #157693

Open
roboclaw-bot wants to merge 18 commits into
mainfrom
openclaw/address-all-agent-outage-p0-157325
Open

roboclaw-bot wants to merge 18 commits into
mainfrom
openclaw/address-all-agent-outage-p0-157325

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #157325. Builds on merged same-owner cleanup recovery in #159451 and preserves the earlier #157064 contributor history.

What Problem This Solves

When one agent's idle database cleanup fails, a healthy agent can lose its warm database capacity too. Operators also lack protected cleanup diagnostics that explain the failure and next repair step.

User Impact

Healthy agents keep reusable database capacity while the failed owner retains its generation and lease custody. Detailed readiness reports the native failure under the active redaction policy without making an otherwise healthy Gateway unready.

No schema, migration, retention, durability, or permission change is introduced. Do not delete database or lease files to clear the diagnostic. The original Windows/Linux outage trigger remains unidentified: this fixes cleanup isolation and diagnostics, not that initiating platform fault.

Why This Change Was Made

Main already contains worker-error hydration, worker-slot failure settlement, and same-owner recovery. The remaining fix frees a failed owner's reusable idle slot, not its cleanup custody. It projects current owner-held diagnostics through the existing readiness owner; revoked owners retain restart-only guidance. Raw errors remain with the cleanup owner rather than caching policy-dependent text.

The changed-PR CI adjustment isolates process-heavy system-runtime children at their existing two-worker ceiling without serializing unrelated siblings. Already-serial hosted rows retain their original worker allocation and timing identity. Extracted children return through the canonical packing owner; unrelated siblings retain their shared parallel envelope. Coverage, row budgets, and unique check identities are preserved. Full-plan defaults, worker-envelope normalization, and volume preparation remain unchanged.

Evidence

  • Relevance: on pinned main 58a3e19e9a61, the capacity regression expects only failed owner first to close but also observes healthy fifth closing (37 ms case; 39.07 s cold command wall). The repaired idle suite passes. Later integrated main e25ad96fb3d62c9934f4be4797b1a5e4cbcb4fc3 only changes completed absent-file retirement in this owner; its retained/released first-session regressions are preserved and pass.
  • Signed head 83ca4232ccafc6b2f10837974ac6a4c6b971ca8f preserves previous PR head e87adcc0d01296ed8218aa9b9a78635885cfdf7d and the pinned main above without rewriting history. It retains main's accepted-work/lifetime, physical-file identity, error-stack materialization, startup-worker handling, reader-before-executor shutdown, prepared readiness, and agent-deletion diagnostics. Retired pending-agent readiness is not restored.
  • 266 distinct cases pass across eight owner files across the recorded proof phases: 7 idle-owner, 47 native cleanup/recovery/creation, 39 readiness/HTTP, and 172 full-file canonical planner cases plus the new hosted-allocation regression. The final three affected planner cases pass after the serial-input guard; unchanged default-path proof is reused. The real-worker lease fault retains the exact failed lease, executes healthy-agent work, preserves nested native causes, and replaces only the original owner's lease after recovery.
  • Review regressions reproduced, then passed: the real worker emits Node-shaped ERR_SQLITE_ERROR / errcode=5; its retained error flows through the production readiness checker and a listening Gateway HTTP server, using a claimed loopback port and a real fetch client. A configured trusted-proxy identity exercises authenticated detail and unauthenticated remote aggregation over TCP. The endpoint includes errcode=5, masks the synthetic bearer value, and immediately masks an additional canary after applyLoggingConfig publishes a new rule. The isolated listener is not the operator's live Gateway, a model-run proof, or a platform-outage reproduction.
  • The planner fixture proves actual two- and three-group overlap with concurrency 2 on Blacksmith and hybrid. Two 160-second children become bounded serial rows. With runtime 160 s plus two unrelated 120-second children, isolation keeps the siblings together in one parallel row: two final rows, not three. Both variants fail with three rows before the repair and pass afterward, preserving selected files, worker ceilings, unique check identities, and row budgets. An already-serial GitHub-hosted selection remains identical with its inherited three-worker allocation and timing. The full 172-case planner proof is reused for unchanged default paths; all three affected cases pass after the final isolation repair.
  • Five targeted type configurations pass: core production, state/logging tests, Gateway server tests, scripts, and root tooling tests. Scoped lint, all-16-file formatting, diff checks, and test-line allowance (+398/400) pass. Current-base SQL portability and database dialect/worker guards show no added SQL constructs or live worker calls (166→166; deprecated-only 15→15); these SQL-unchanged proofs are reused after the diagnostic/presentation repair. No guard, timeout, baseline, or assertion is weakened.
  • Local review: Local ClawSweeper completed an uncached review of the full committed range e25ad96fb3d62c9934f4be4797b1a5e4cbcb4fc3 → 83ca4232ccafc6b2f10837974ac6a4c6b971ca8f: no findings; patch correct, security cleared, and real-behavior proof sufficient. Prior P2 redaction/native-code and CI-planner findings have red-before/green-after proof. An earlier P3 suggestion to avoid optional diagnostic formatting on aggregate probes is deferred: this repair preserves the shared prepared-readiness contract, and no latency failure was demonstrated. Broad-selection headroom under the 130-row matrix cap was not measured locally; exact-head CI owns broad coverage.
  • Current-head CI: CI run is attached to exact head 83ca4232ccafc6b2f10837974ac6a4c6b971ca8f and in progress; no current-head green gate is claimed. Older passing or failed runs do not qualify this head. The PR remains unmerged with auto-merge off; no native preparation or merge admission is claimed, and the retained tooling-state incompatibility was not bypassed.
Listening HTTP terminal capture — synthetic fixture data only

A real client receives the retained worker error through the listener. The before-request sees the controlled canary; after the logging owner applies the new rule, detailed output masks it and still includes the native result code. The unauthenticated remote identity is supplied through an explicitly trusted loopback proxy. No response or auth value is fabricated in this capture; listener addresses and ports are omitted.

{
  "before": {
    "status": 200,
    "canaryVisible": true
  },
  "after": {
    "status": 200,
    "body": {
      "ready": true,
      "coreReady": true,
      "failing": [],
      "uptimeMs": 144,
      "agentCleanup": [
        {
          "agentId": "first",
          "reason": "Agent database cleanup failed | controlled idle worker lease failure; cleanu…vate; Authorization: Bearer synthe…cret | ERR_SQLITE_ERROR | controlled lease release refused (code=ERR_SQLITE_ERROR, errcode=5)",
          "repairHint": "Idle cleanup retries on this agent's next request. If cleanup remains blocked, restart the Gateway; do not delete its database or lease."
        }
      ]
    }
  },
  "unauthenticatedRemote": {
    "status": 200,
    "body": {
      "ready": true
    }
  }
}
Test cost and scope

The recorded changed-owner run passes 219 cases in 156.20 s command wall: idle shard 1.76 s, existing full planner file 98.05 s, readiness/HTTP 6.85 s, and real-worker/HTTP fault shard 8.67 s (3.809 s fault case). The remaining 46 lifecycle/creation cases pass in 77.70 s command wall (45.42 s test shard). Before the final CI-only repair, the uninstrumented replay passes all four affected cases (three planner and one real-worker/listening-HTTP case) in 19.76 s command wall; its real-worker case takes 4.218 s. The separate terminal capture passes in 14.26 s command wall (3.853 s fault case); temporary console instrumentation was removed before commit. After the final CI-only repair, all three affected planner cases (including both two-/three-group variants) pass in 4.12 s wrapper time; both script and tooling-test types, scoped lint/format, and the +398/400 test-line guard pass again.

The lease, recovery, physical-creation, and real-error-to-HTTP contracts need real workers and storage; helper mocks cannot prove them. The added planner assertions and HTTP flow reuse existing fixtures. Local worker preparation and targeted checks are not a complete package build; exact-head CI owns broad coverage. Earlier finalization and SPA-fixture timeouts remain historical unexplained failures, not claimed fixes.

Residual scope against the pinned main: 16 files, +546/−39. Cached formatted cleanup text and duplicate diagnostic dispatch are removed; there is no new lifecycle, storage, or retry owner.

Contributor credit: requested by @RomneyDa for the release-blocking outage; thanks to @desksk and @PashaGanson for the Windows/Linux reports. Worked on by @RomneyDa.

Work session: https://team.openclaw.ai/chat/roboclaw/dashboard/68c9aa3c-c787-440d-be5f-66ec9dd1706e

@clawsweeper

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

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 24, 2026 23:30
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Sep 24, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR frees healthy idle capacity after database cleanup fails, preserves nested failure causes, exposes protected diagnostics, and serializes selected system-runtime CI work.

Example: Four agents are warm when a fifth finishes, and cleanup of agent first fails with SQLITE_BUSY.

  • Before: The failed owner consumes an idle slot, forcing the healthy fifth agent to close instead of staying warm.
  • After: The fifth agent stays warm while first retains its lease and cleanup custody; authorized readiness details show the redacted cause and recovery hint.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The scoped patch is correct and supported by native-owner coverage and successful CI; harness evidence does not establish the original shipped-Gateway incident.
Proof confidence 🦐 gold shrimp (3/6) This collaborator/bot PR is outside the ordinary contributor proof gate; supplied native-worker fault coverage exercises cleanup custody, healthy-agent database work, redaction, and recovery, while shipped-Gateway incident coverage remains unproven.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Healthy agents pay unnecessary database reopen costs after another agent's cleanup fails, while operators lose the underlying failure details.
Reason: The remaining defect is visible on main, and the Gateway owner has already approved the diagnostic-only readiness direction.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: its remaining cleanup-capacity and diagnostic repairs are useful and absent from main; no actionable introduced bug was found.

Priority: P2
Reviewed head: 9b57a580bb67e68f14a944b7506df98d8081418f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied shipped-Gateway run identifies the original platform trigger or demonstrates an actual agent turn during that incident.
Agent review details

How this fits together

The agent execution owner manages native SQLite generations and idle reuse; worker failures enter that owner, and cleanup facts leave through Gateway readiness diagnostics.

flowchart TD
  A[Agent requests] --> B[Execution owner]
  B --> C[Idle executor pool]
  B --> D[SQLite worker broker]
  D --> E[Native database generation]
  E --> B
  B --> F[Protected readiness diagnostics]
Loading

Technical review

Best possible solution:

Land the scoped capacity and diagnostic repair while preserving cleanup custody and tracking the original platform fault separately.

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

Current main shows the failed-idle-capacity path directly, and the supplied native-worker fixture exercises it; the original Windows/Linux initiating fault remains unidentified.

Is this the best way to solve the issue?

The repair keeps one cleanup owner, preserves same-agent recovery and revocation, and follows the recorded readiness decision without changing persisted formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 35b6b308f6cb.

Provenance checked

  • Idle executor capacity keeps the original intent (1240759: Retain four warm executors to avoid costly agent-switch reopens; the accepted memory tradeoff remains intact.)
  • Failed cleanup custody and readmission keeps the original intent (f0423d5: Retry failed cleanup through the same non-revoked owner before replacement, retaining its generation and lease.)
  • Readiness failure policy keeps the original intent (d996f7b: Terminal shared-state admission failures must make readiness fail; the new cleanup projection preserves that rule and follows the explicit owner decision.)
  • Selected CI packing changes intended behavior with a stated reason (24100ea: Pack selected work through canonical resource and timing policies; this PR explains serializing process-heavy system-runtime work within its existing worker envelope.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +56, Tests +288, Docs +20, Other +16. Total +380 across 17 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 69 13 +56
Tests 7 298 10 +288
Docs 2 20 0 +20
Config 0 0 0 0
Generated 0 0 0 0
Other 2 30 14 +16
Total 17 417 37 +380

Review metrics

Metric Value Why it matters
Production versus test growth Production/tooling +99/−27; tests/support +298/−10 Most added coverage exercises native lease custody, recovery, diagnostic visibility, and canonical planner behavior; production changes stay within existing owners.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The remaining patch repairs warm-capacity loss and diagnostic gaps after main's broader cleanup recovery changes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (24 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-30T01:32:36.790Z sha 0bbba8f :: blocked before merge. :: none
  • reviewed 2026-09-30T04:20:17.815Z sha de89351ceaa5bbc76584bb1e866ae9318576fcb3 :: blocked before merge. :: none
  • reviewed 2026-09-30T05:06:04.305Z sha d15f15e :: blocked before merge. :: none
  • reviewed 2026-09-30T05:14:54.798Z sha d15f15e :: blocked before merge. :: none
  • reviewed 2026-10-10T06:48:27.264Z sha 4321a27 :: needs changes before merge. :: none
  • reviewed 2026-10-10T07:27:29.158Z sha 737c180 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T08:39:36.222Z sha 737c180 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-11T06:18:25.794Z sha 9b57a58 :: needs maintainer review before merge. :: none

Reviewed October 11, 2026, 3:11 AM ET / 07:11 UTC (Revision 25).

@creanet-64

Copy link
Copy Markdown
Contributor

Additional release-candidate validation supporting this PR's isolation approach:

  • Independently checked current main at 90f63c185: the foreign idle-owner path still directly awaits idle.closeIdle(). Same-owner readmission is now present, but that does not by itself isolate a foreign cleanup failure.
  • A local release/2026.9.7 adaptation of this PR's owner-isolation logic, without the readiness changes, passed real SQLite-worker lease-delete fault injection: unrelated agents could execute native commands while the failed owner retained cleanup custody, and removing the injected fault allowed recovery.
  • Additional owner-boundary tests covered joining an in-flight close before same-owner replacement, preserving explicit revocation, rechecking the waiting caller's authority after foreign cleanup, and propagating retirement-finalization errors after native cleanup succeeds. That last case guards against swallowing arbitrary errors in the isolation catch.

This is supporting validation of your existing work, not a claim to a new isolation design. The tests were run on the local release adaptation, not on the current head of this PR. We have not identified the original field-native failure or established long-term production stability.

We also isolated a separate, release-specific reclamation defect during that work: #159916. It concerns a dedicated worker terminated before dispatch and does not replace this PR's cross-agent isolation fix.

If narrowing the readiness portion helps unblock the existing review, the local result supports keeping the cleanup-isolation repair independently useful. No change to the PR's branch has been made by us.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 28, 2026
@RomneyDa
RomneyDa force-pushed the openclaw/address-all-agent-outage-p0-157325 branch from a1481eb to 5b91e09 Compare September 28, 2026 20:47
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 28, 2026
@RomneyDa
RomneyDa force-pushed the openclaw/address-all-agent-outage-p0-157325 branch from 5b91e09 to 76ffea9 Compare September 28, 2026 21:08
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa
RomneyDa force-pushed the openclaw/address-all-agent-outage-p0-157325 branch from 76ffea9 to c9b2069 Compare September 28, 2026 21:22
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

steipete added a commit that referenced this pull request Oct 25, 2026
An explicit cron run reads its authorized job definition and private scratch separately inside a SQLite read transaction. Read both in one dialect-layer LEFT JOIN so they share a statement snapshot, removing three SQL statements per SQLite run without another worker request.

The job reader keeps its all-column authorization relation, ordered narrow projection, exact returned-ID check, existing decoder/config revision and legacy creation fallback. Missing scratch still reports revision 0; deletion keeps its revision tombstone. The standalone maintenance reader remains. No schema, cache, write, receipt, claim-before-effect, delivery authority, FIFO or 64-receipt retention change.

PostgreSQL retains the shared reader's outer read-only transaction and rollback: its exact-job read is 4→3 SQL, not 4→1. SQLite exact-job is 4→1, heartbeat 3→1; PostgreSQL heartbeat remains 3→3. Accepted noncontract edges: an absent/malformed job can now require scratch SELECT privilege, and malformed job plus unsafe numeric scratch can reject the numeric data first. These do not remove the existing caller/source/cancellation checks.

The production delta is +3 lines: one joined query replaces the transaction and duplicate read while sharing NULL handling with heartbeat. Existing test files cover read-after-write, tombstones, missing jobs/monitors and both database engines. No new suite or runner is added.

Acceptance was registered before measurement: the committed `scripts/bench-cron-run.mts` drives signed WebSocket `cron.run` against an isolated synthetic Gateway/provider, once cold and twice warm. Each run must produce one start, one finish, one Responses request and exact-run history verification. Compare execution, history verification and settlement separately and together, plus shutdown and the entire invocation. The scratch owner must fall from 4→1 SQL with 1 request and 0 MAIN throughout; no cost may be deferred outside the run. Keep cold/warm separate and report median/p95/range. Three same-platform alternating pairs when calm, or one pair plus source attribution under campaign load. Counts and profiles make no latency/CPU-speed claim; timing claims require the timing lock, load below 24 and ≥5 alternating samples per arm. A 20% user-facing regression stops acceptance. Delivery mode none does not claim an external-send proof.

The same-platform explicit comparison (baseline 814e732, candidate 93a6c4) gives:

| SQL / requests / MAIN | Baseline | Candidate |
| --- | --- | --- |
| Cold execution + verification + settlement | 257 / 80 / 0 | 254 / 78 / 0 |
| Warm 1 | 247 / 64 / 0 | 235 / 60 / 0 |
| Warm 2 | 252 / 61 / 0 | 245 / 65 / 0 |
| Warm median | 249.5 / 62.5 / 0 | 240 / 62.5 / 0 |
| Warm descriptive p95 | 252 / 64 / 0 | 245 / 65 / 0 |
| Warm range | 247–252 / 61–64 / 0 | 235–245 / 60–65 / 0 |
| Shutdown | 22 / 6 / 5 | 40 / 10 / 5 |
| Whole invocation | 1383 / 356 / 58 | 1369 / 352 / 58 |

Each of the three runs completed one start, finish, Responses request and exact history verification. The scratch owner is exactly 4/1/0 → 1/1/0 in every run, all in its execution phase, with no extra or deferred scratch requests. All execution/verification/settlement phases are SQL-error-free and runtime MAIN remains zero. The count comparison is diagnostic, not an error-free full invocation: the frozen analyzer rejects two failed shutdown `state_leases` DELETEs (`database is locked`). Shutdown exceeds the 20% stop threshold; it was stopped and explicitly accepted by the coordinator as inherited after an independent main shutdown-lock reproduction. The separate SHUTDOWNLOCK lane owns that repair. The scratch join changes no lease code or writes. No latency or CPU-speed claim is made.

The frozen 3.1.5 standard workload is a different scheduled `cron.add` flow: three valid baselines gave 06.cron 231/62/0, 235/65/0, 233/63/0 (median 233/63/0), versus ordinary warm 45/12/0. The descriptive excess is 188 SQL/51 requests, not causal subtraction. One extra standard setup aborted before any Gateway; it supplies no performance evidence. The existing scratch source is identical across that baseline and the explicit baseline. Full current-standard delta is deferred to the next census.

Validation: count regression red on baseline (2 SELECTs and BEGIN/COMMIT), all 17 scratch-store tests green on the candidate; two isolated Codex P0–P2 reviews scoped-clean. The existing two-engine conformance test passed on actual SQLite and PostgreSQL 17, with catalog/trigger parity and cleanup verified. Test cost: scratch cases totaled 6.528 s (125.95 s file duration, mostly transform); the two engine cases totaled 1.846 s (260.62 s file duration, mostly transform). The candidate build and official source-freshness check passed at measured runtime head 93a6c4d; the three-sample invocation completed with the shutdown limitation above. Exact-head CI run 40176443806 completed successfully: 39 successful jobs, 26 skipped, no failures, including all three actual PostgreSQL shards, production/test types, lint, source contracts, Madge, and worker/T1/dialect ratchets. The earlier run passed types, lint and source contracts but found a worker-inventory omission: the new direct query was conservatively labeled T1. Head a187ecf corrects only inventory metadata and regenerates its snapshot: the worker snapshot and its private heartbeat helper are W, while the native Doctor reader stays T3. No runtime or SQL change is involved. The generated snapshot also catches up existing main classifications; targeted script lint and formatting pass. The two production reviews remain valid; this tooling-only correction adds no production review round. PG review approved the semantics at 68c24c4, and the coordinator explicitly carried REVIEW-OK to 93a6c4d because only benchmark TypeScript annotations changed. Candidate counts and the inherited-shutdown disposition are recorded; the corrected head’s CI and all three PG shards passed. The test-only import relocation avoids another open PR's adjacent import change; production bytes remain identical to both isolated reviews and database proof. The benchmark annotations fix CI TS7022 without changing emitted behavior.

Final-head overlap at a187ecf: complete shared-index base-versus-candidate merge-tree comparison covers 21 peers (#183410, #183285, #181057, #180871, #180286, #180139, #169241, #168956, #168615, #167546, #167471, #165039, #161997, #157922, #157693, #156613, #141004, #137788, #136476, #129388, #121204). No new source conflict paths, regions or messages. Six peers (#181057, #180871, #180139, #169241, #129388, #121204) have added or changed conflicts confined to the fully generated worker inventory. The coordinator explicitly accepted this class because main's snapshot was stale and generated outputs must be regenerated, not hand-edited. The same exact-head disposition carries PG REVIEW-OK because runtime bytes are unchanged. Exact-head CI and all three PostgreSQL shards passed.

PG checklist: (1) read-only; existing writer transaction/advisory-lock, DML/conflict and cross-store commit ordering unchanged. (2) At most one joined row via the existing composite primary keys, original job fields plus four scratch fields, unchanged 256 KiB scratch write bound. (3) No cache/generation or invalidation change; one statement snapshot, existing outer PG read transaction retained. (4) No schema/admission/identity/retry/probe change. (5) Same worker owner, one request, no MAIN expansion; target 4→1 SQL in all three real Gateway runs, with the inherited shutdown failure disclosed above. (6) Actual PostgreSQL 17 and SQLite owner conformance passed; all three final-head PostgreSQL CI shards and the other selected static checks passed.

Knip was run separately because ordinary PR CI excludes it. The canonical candidate export scan failed with 26 script, 20 production and 16 full-tree findings; none is in a changed file. All 62 occurrences (52 unique file/symbol pairs), scanner/config/compiler inputs and package inputs are unchanged from merge-base dada70f. The only removed imports, runSqliteReadSnapshotSync and loadCronRows, both retain multiple real production consumers. Current-main diagnostic sections reported 14 script and 7 production findings; main has already repaired 40 candidate occurrences in unrelated changes. Its separate full-tree scan was intentionally stopped after the coordinator accepted the source-attributed inherited findings; it is not a passing full-main scan. No ignored exports, baselines or unrelated code were changed. The failed candidate scan is explicitly accepted as inherited; all branch changes and selected CI static checks pass.

Pre-merge shared-index refresh retains 17 open peers from that audit. Only #180871 moved (f140f16); its fresh base-versus-candidate comparison still adds conflicts solely in the generated worker inventory, within the coordinator-accepted class. No new source conflicts.

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
An explicit cron run reads its authorized job definition and private scratch separately inside a SQLite read transaction. Read both in one dialect-layer LEFT JOIN so they share a statement snapshot, removing three SQL statements per SQLite run without another worker request.

The job reader keeps its all-column authorization relation, ordered narrow projection, exact returned-ID check, existing decoder/config revision and legacy creation fallback. Missing scratch still reports revision 0; deletion keeps its revision tombstone. The standalone maintenance reader remains. No schema, cache, write, receipt, claim-before-effect, delivery authority, FIFO or 64-receipt retention change.

PostgreSQL retains the shared reader's outer read-only transaction and rollback: its exact-job read is 4→3 SQL, not 4→1. SQLite exact-job is 4→1, heartbeat 3→1; PostgreSQL heartbeat remains 3→3. Accepted noncontract edges: an absent/malformed job can now require scratch SELECT privilege, and malformed job plus unsafe numeric scratch can reject the numeric data first. These do not remove the existing caller/source/cancellation checks.

The production delta is +3 lines: one joined query replaces the transaction and duplicate read while sharing NULL handling with heartbeat. Existing test files cover read-after-write, tombstones, missing jobs/monitors and both database engines. No new suite or runner is added.

Acceptance was registered before measurement: the committed `scripts/bench-cron-run.mts` drives signed WebSocket `cron.run` against an isolated synthetic Gateway/provider, once cold and twice warm. Each run must produce one start, one finish, one Responses request and exact-run history verification. Compare execution, history verification and settlement separately and together, plus shutdown and the entire invocation. The scratch owner must fall from 4→1 SQL with 1 request and 0 MAIN throughout; no cost may be deferred outside the run. Keep cold/warm separate and report median/p95/range. Three same-platform alternating pairs when calm, or one pair plus source attribution under campaign load. Counts and profiles make no latency/CPU-speed claim; timing claims require the timing lock, load below 24 and ≥5 alternating samples per arm. A 20% user-facing regression stops acceptance. Delivery mode none does not claim an external-send proof.

The same-platform explicit comparison (baseline 814e732, candidate 93a6c4) gives:

| SQL / requests / MAIN | Baseline | Candidate |
| --- | --- | --- |
| Cold execution + verification + settlement | 257 / 80 / 0 | 254 / 78 / 0 |
| Warm 1 | 247 / 64 / 0 | 235 / 60 / 0 |
| Warm 2 | 252 / 61 / 0 | 245 / 65 / 0 |
| Warm median | 249.5 / 62.5 / 0 | 240 / 62.5 / 0 |
| Warm descriptive p95 | 252 / 64 / 0 | 245 / 65 / 0 |
| Warm range | 247–252 / 61–64 / 0 | 235–245 / 60–65 / 0 |
| Shutdown | 22 / 6 / 5 | 40 / 10 / 5 |
| Whole invocation | 1383 / 356 / 58 | 1369 / 352 / 58 |

Each of the three runs completed one start, finish, Responses request and exact history verification. The scratch owner is exactly 4/1/0 → 1/1/0 in every run, all in its execution phase, with no extra or deferred scratch requests. All execution/verification/settlement phases are SQL-error-free and runtime MAIN remains zero. The count comparison is diagnostic, not an error-free full invocation: the frozen analyzer rejects two failed shutdown `state_leases` DELETEs (`database is locked`). Shutdown exceeds the 20% stop threshold; it was stopped and explicitly accepted by the coordinator as inherited after an independent main shutdown-lock reproduction. The separate SHUTDOWNLOCK lane owns that repair. The scratch join changes no lease code or writes. No latency or CPU-speed claim is made.

The frozen 3.1.5 standard workload is a different scheduled `cron.add` flow: three valid baselines gave 06.cron 231/62/0, 235/65/0, 233/63/0 (median 233/63/0), versus ordinary warm 45/12/0. The descriptive excess is 188 SQL/51 requests, not causal subtraction. One extra standard setup aborted before any Gateway; it supplies no performance evidence. The existing scratch source is identical across that baseline and the explicit baseline. Full current-standard delta is deferred to the next census.

Validation: count regression red on baseline (2 SELECTs and BEGIN/COMMIT), all 17 scratch-store tests green on the candidate; two isolated Codex P0–P2 reviews scoped-clean. The existing two-engine conformance test passed on actual SQLite and PostgreSQL 17, with catalog/trigger parity and cleanup verified. Test cost: scratch cases totaled 6.528 s (125.95 s file duration, mostly transform); the two engine cases totaled 1.846 s (260.62 s file duration, mostly transform). The candidate build and official source-freshness check passed at measured runtime head 93a6c4d; the three-sample invocation completed with the shutdown limitation above. Exact-head CI run 40176443806 completed successfully: 39 successful jobs, 26 skipped, no failures, including all three actual PostgreSQL shards, production/test types, lint, source contracts, Madge, and worker/T1/dialect ratchets. The earlier run passed types, lint and source contracts but found a worker-inventory omission: the new direct query was conservatively labeled T1. Head a187ecf corrects only inventory metadata and regenerates its snapshot: the worker snapshot and its private heartbeat helper are W, while the native Doctor reader stays T3. No runtime or SQL change is involved. The generated snapshot also catches up existing main classifications; targeted script lint and formatting pass. The two production reviews remain valid; this tooling-only correction adds no production review round. PG review approved the semantics at 68c24c4, and the coordinator explicitly carried REVIEW-OK to 93a6c4d because only benchmark TypeScript annotations changed. Candidate counts and the inherited-shutdown disposition are recorded; the corrected head’s CI and all three PG shards passed. The test-only import relocation avoids another open PR's adjacent import change; production bytes remain identical to both isolated reviews and database proof. The benchmark annotations fix CI TS7022 without changing emitted behavior.

Final-head overlap at a187ecf: complete shared-index base-versus-candidate merge-tree comparison covers 21 peers (openclaw#183410, openclaw#183285, openclaw#181057, openclaw#180871, openclaw#180286, openclaw#180139, openclaw#169241, openclaw#168956, openclaw#168615, openclaw#167546, openclaw#167471, openclaw#165039, openclaw#161997, openclaw#157922, openclaw#157693, openclaw#156613, openclaw#141004, openclaw#137788, openclaw#136476, openclaw#129388, openclaw#121204). No new source conflict paths, regions or messages. Six peers (openclaw#181057, openclaw#180871, openclaw#180139, openclaw#169241, openclaw#129388, openclaw#121204) have added or changed conflicts confined to the fully generated worker inventory. The coordinator explicitly accepted this class because main's snapshot was stale and generated outputs must be regenerated, not hand-edited. The same exact-head disposition carries PG REVIEW-OK because runtime bytes are unchanged. Exact-head CI and all three PostgreSQL shards passed.

PG checklist: (1) read-only; existing writer transaction/advisory-lock, DML/conflict and cross-store commit ordering unchanged. (2) At most one joined row via the existing composite primary keys, original job fields plus four scratch fields, unchanged 256 KiB scratch write bound. (3) No cache/generation or invalidation change; one statement snapshot, existing outer PG read transaction retained. (4) No schema/admission/identity/retry/probe change. (5) Same worker owner, one request, no MAIN expansion; target 4→1 SQL in all three real Gateway runs, with the inherited shutdown failure disclosed above. (6) Actual PostgreSQL 17 and SQLite owner conformance passed; all three final-head PostgreSQL CI shards and the other selected static checks passed.

Knip was run separately because ordinary PR CI excludes it. The canonical candidate export scan failed with 26 script, 20 production and 16 full-tree findings; none is in a changed file. All 62 occurrences (52 unique file/symbol pairs), scanner/config/compiler inputs and package inputs are unchanged from merge-base 71bc695. The only removed imports, runSqliteReadSnapshotSync and loadCronRows, both retain multiple real production consumers. Current-main diagnostic sections reported 14 script and 7 production findings; main has already repaired 40 candidate occurrences in unrelated changes. Its separate full-tree scan was intentionally stopped after the coordinator accepted the source-attributed inherited findings; it is not a passing full-main scan. No ignored exports, baselines or unrelated code were changed. The failed candidate scan is explicitly accepted as inherited; all branch changes and selected CI static checks pass.

Pre-merge shared-index refresh retains 17 open peers from that audit. Only openclaw#180871 moved (f140f16); its fresh base-versus-candidate comparison still adds conflicts solely in the generated worker inventory, within the coordinator-accepted class. No new source conflicts.

Co-authored-by: Peter Steinberger <[email protected]>
Preserve main lifecycle notifications, agent recovery readiness, and proxy probe policy while retaining cleanup isolation and diagnostic proof. Adapt native lease fault injection to DELETE RETURNING and the HTTP fixture to the current readiness contract.
Integrate current main while retaining its detached async root for idle cleanup and restart drain. Preserve the unchanged cleanup-isolation patch and its resource-owned diagnostic reporting.

Copy link
Copy Markdown

Additional scoped runtime observation (2026-11-02), possibly useful for #157325 / this PR.

Environment: Linux, Node24.22.1, a locally modified2026.10.10-beta.5 installation with multiple prior backports. This is not an unmodified release/current-main reproduction.

Before the admission stall, logs recorded a transaction on the shared state DB labeled audit.writer.process lasting25,337ms (callback/sql24,237ms; commit1,100ms). While it was outstanding:

  • an agent-execution worker's database.prepareWrite failed at BEGIN with SQLiteBUSY5 after5,699ms;
  • another agent-execution worker's close request failed at BEGIN with SQLiteBUSY5 after5,287ms, followed by Agent database idle cleanup failed: database is locked;
  • a different actor that had used that second worker subsequently reported Agent database execution admission is closed.
    Later stale-lease FULL checks returned healthy but took165–178s. The transaction callback label does not identify the individual SQL statement, and this timing/worker correlation does not establish every revocation edge or the originating25s delay. In particular, the close request failure must not be equated with a proven failure inside SQLite's native close API.

Separately, a private regression using the installed compiled closeNative and idle-release policy with a real temporary SQLite write lock reproduces failed cleanup causing eviction of a healthy fifth owner. Your functional idle-capacity deletion fixes that regression while retaining the exact failed generation, owner/custody and error; same-owner cleanup retries after lock release.15 controls and syntax pass. We activated only that narrow functional hunk, without the diagnostic-interface changes. No live fault was injected; this is not proof that it fixes the initiating write stall, every admission error, or end-to-end latency.

Is there an existing follow-up specifically covering shared-state BEGIN contention during agent cleanup/preparation and the resulting peer admission invalidation?

This branch has not been deployed

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

4 participants