Skip to content

fix(state): reuse prepared owners for session inspections - #188070

Closed
fuller-stack-dev wants to merge 3 commits into
mainfrom
openclaw/keen-krill
Closed

fuller-stack-dev wants to merge 3 commits into
mainfrom
openclaw/keen-krill

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

What Problem This Solves

Repeated artifact-preserving session readiness reads can materialize the whole agent database and WAL, even when its execution owner already has a prepared native connection. On large stores, that turns a bounded session lookup into database-sized I/O and temporary allocation.

Follow-up to #187152. Complementary to #188009 (inspection transfer policy) and #187989 (history-read writer admission); this does not duplicate either change.

User Impact

Eligible warm exact-session inspections now query the already-prepared agent executor’s existing connection. They do not create another execution owner, open another native connection, or copy a database image. Cold, synchronous-host, unprepared canonical, and active-transaction cases retain the existing private-reader fallback.

This does not eliminate initialization/recovery copies, change SQLite durability or retention, or establish that all Team-server latency and disk growth are resolved. No deployment or restart is included.

Why This Change Was Made

The registered readiness regression reproduced a private image equal to the database plus WAL on each warmed observation, growing after a real committed update. The fix adds a strict prepared-generation borrow and non-opening worker accessor, then reuses the existing exact-facts kernel. It cannot enter generation creation, replacement, preparation, or schema-refresh paths.

Existing physical-source validation, canonical readiness, live request authority, cancellation, and accepted-work settlement remain authoritative. Plain ineligibility may use the old reader; revoked authority, changed identity, abort, and invalidated validation fail rather than selecting another owner.

Evidence

  • Test-first regression failed on the base with one private image where zero was expected.
  • 157 focused tests passed across seven files, including the registered readiness suite, prepared-owner controls, validation-cache coverage and review regressions. Six added fallback controls use real native transactions/canonical-unready receipts and real private-copy reads; four revocation cases fail on the preceding candidate while healthy fallback controls pass. Scoped lint, formatting, whitespace, test-line allocation and regenerated worker-inventory checks passed.
  • Measured warm observations perform real native session SQL after committed updates and facts invalidation: zero private images, zero image bytes, and zero additional native connections. This is not a response-cache-only proof. Database/WAL payloads and artifact names stay unchanged; existing warm SHM coordination bytes are excluded.
  • Independent isolated runtime QA on the preceding repaired candidate exercised the actual Gateway, loopback WebSocket, registered readiness RPC and HTTP health. Committed archive/unarchive changes were observed; cold fallback did not recreate an executor; revoked validation was refused. The final four-line validation-handoff refinement is covered by the added real-native/private-reader regression controls.
  • Existing maintenance/projection filesystem work elsewhere in the Gateway is not claimed to disappear. No production-scale or 35 GB latency benchmark is claimed.

Review and Validation Limits

Canonical independent API re-review completed on the final candidate at P0–P2: scoped-clean, both full-scope assessments complete, zero findings or filtered findings, and frozen source verified. Earlier findings covering post-query validation revocation, read-admitted startup fallback, and custody across prepared-read ineligibility are fixed with failing-before/passing-after controls. A separate native peer-review attempt timed out without a verdict and is not counted as approval.

The supported typecheck wrapper rejects the required canonical pnpm global-store layout before compiler launch with “Declaration input escapes checkout.” The wrapper, boundary implementation, package manifest and lockfile are unchanged from the base. Supplementary pinned-compiler checks show no touched-file diagnostics, but report unrelated transport/UI diagnostics; no clean typecheck is claimed. PR CI remains a separate gate.

@clawsweeper

clawsweeper Bot commented Oct 30, 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 Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reuse an already-prepared agent database connection for eligible exact-session inspections while retaining the existing private-reader fallback.

Example: Repeated readiness observations for agent:main:inspection after committed session updates.

  • Before: Each observation can copy the database and WAL into a private image.
  • After: Eligible warm observations query the existing connection with zero private images or additional native connections.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source and native regression design support the fix; independently inspectable runtime evidence for the final revision is limited.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports actual Gateway/WebSocket readiness QA on the preceding candidate, with final handoff changes covered by native regressions rather than supplied runtime output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated readiness observations can perform database-sized copying and temporary allocation even when a prepared connection already exists.
Reason: The maintainer-authored direction addresses measured unnecessary work while retaining the original preservation and authority contracts.

Merge readiness

✅ Ready for maintainer review

This PR addresses a concrete database-sized copying cost still present on current main; no actionable introduced defect was found, and required CI remains pending.

Priority: P2
Reviewed head: fe1cbcf8508a8d6198201e13874ffbbe1cd9cdc6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The final validation-handoff refinement has native regression coverage but no supplied final-head Gateway trace.
Agent review details

How this fits together

Session readiness requests pass through the history-reader owner, which selects a prepared agent executor or private reader and returns bounded session facts under current source and disclosure checks.

flowchart TD
A[Session readiness request] --> B[History reader owner]
B --> C[Prepared executor eligibility]
C --> D[Existing native connection]
C --> E[Private reader fallback]
D --> F[Exact session facts kernel]
E --> F
F --> G[Current authority and disclosure checks]
Loading

Technical review

Best possible solution:

Use the existing executor and query kernel for eligible warm inspections while preserving cold fallback, physical identity, live authority, and accepted-work settlement.

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

Current-main source directly shows the private-image path, and the committed readiness regression measures it after real updates; no target code was executed during this review.

Is this the best way to solve the issue?

The change removes unnecessary copying at the existing execution owner, reuses the exact-facts kernel, and preserves justified fallback paths without introducing a cache or competing owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Artifact-preserving readiness reads keeps the original intent (e242709: Readiness was designed to preserve source artifacts and recheck current session authority after awaited reads.)
  • Shared executor lifecycle and accepted-work settlement keeps the original intent (d22782a: One canonical executor owns native connection lifetime, bounded idle reuse, cleanup, and accepted-command settlement.)
  • Retained physical validation keeps the original intent (3ac0c05: Retain process-owned filesystem facts while preserving physical checks at admission and privileged boundaries.)
  • Startup read fallback keeps the original intent (9f32d25: Permit read-admitted session access while writable startup inspection remains pending.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 31c35d5 adds src/state/openclaw-agent-execution-owner.ts:110 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 31c35d5f5b09; files: src/state/openclaw-agent-execution-owner.ts)

PR surface

Source +323, Tests +627, Docs +12, Other +2. Total +964 across 21 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 11 441 118 +323
Tests 7 654 27 +627
Docs 2 21 9 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 21 1118 154 +964

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +441/−118; tests, support, and test routing +654/−27. Growth implements non-opening executor reuse and distinct custody, fallback, and work-count regressions without adding persisted state or another lifecycle owner.

Labels

Label changes:

  • add P2: Repeated readiness observations incur database-sized I/O on large stores, but the evidence establishes a bounded performance defect rather than a general 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: Repeated readiness observations incur database-sized I/O on large stores, but the evidence establishes a bounded performance defect rather than a general 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 29, 2026, 11:46 PM ET / October 30, 2026, 03:46 UTC.

@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for digging into this, @fuller-stack-dev. The prepared-owner borrow is careful work, and the regression that reproduces the private image on each warm read was useful.

I'm closing this because #188025 (merged as bdaf7df) removes the cause rather than reducing it:

  • Root cause: sessions.github.readiness ran inside the Doctor-only withArtifactPreservingStateReads({ agentDatabases: true }) scope, so every agent-database read became a whole-file copy. fix(gateway): stop GitHub readiness from copying whole agent databases #188025 takes readiness out of that scope. It now reads the live database through its owner. Path checks stay in workers, and the source-retirement checks stay.
  • Cold reads still copy here: this PR keeps the private-reader fallback for cold, unprepared and in-transaction cases. On the team Gateway the roboclaw agent database closes whenever it goes idle, so readiness would still copy all 35 GB on those reads.
  • Overlap: both PRs change the same readiness tests and paths. After fix(gateway): stop GitHub readiness from copying whole agent databases #188025, readiness no longer reaches the copy path, so the borrow machinery here (+1118 lines) has no readiness caller left.

If other inspection paths, such as Doctor, would still benefit from borrowing a prepared owner, please open that as a separate PR scoped to those callers. #188009 (byte copy instead of reflink) may also still be worth it for Doctor-side copies. Thanks again.

@obviyus obviyus closed this Oct 30, 2026
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. 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.

2 participants