Skip to content

refactor(state): join shared reads through async ownership - #175443

Merged
steipete merged 3 commits into
mainfrom
deslop/r05-2-read-operations-20261015
Oct 17, 2026
Merged

steipete merged 3 commits into
mainfrom
deslop/r05-2-read-operations-20261015

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Shared-state reads maintain a second producer/cleanup continuation machine around operations that already own their promises and native cleanup. A source-wide synchronous service pump then steps every reader to advance that mirror.

This recovers the read-lifecycle area of closed #174230 and overlapping #173527. Their historical managed-image failure is not waived or reused as proof. The wide donors are being recovered by area under campaign rule 11.

What Changed

No intended user-visible change. Read completion, cancellation, snapshot bytes, failed-close retry, and ordinary shutdown settlement retain their existing owners; this removes internal continuation bookkeeping.

One async operation now joins the query, transport retirement, snapshot cleanup, and producer cleanup before releasing its retained resources. Native transports keep their own progress mechanisms; the outer owner no longer duplicates them. Source registrations own close only. Actual failed-close retry and shutdown joins remain. Retained synchronous snapshots keep their bytes until their last asynchronous child releases them.

Keep physical/source admission, live authority at the actual read boundary, worker command capture/byte accounting, FIFO, caller cancellation after cleanup, original-file snapshots, PostgreSQL connection ownership, and ordinary native settlement. Main's newer PostgreSQL migration regressions are unchanged apart from one obsolete mock member. No schema/column, durability, retention, permission, configuration, public protocol, dependency, or SDK change. Phase E is untouched.

Production delta: 308 net lines removed, five production files (+261/-569). Total fourteen files +466/-877, including one shrink-only mock-baseline entry. Tests/support/baselines are excluded from production accounting. This is an area slice, not additive credit for overlapping donors.

Best-effort tradeoffs accepted

  • Manual producer/cleanup continuation machine and source-wide synchronous pumping (fix: retain shared-state snapshots through worker failures #160946, commit 9c93bc3): its linked Complete asynchronous runtime storage boundaries while retaining SQLite #144592 is an implementation campaign, not a human actual-use incident requiring synchronous completion without Promise callbacks. Reads now advance through normal async completion; a caller monopolizing the event loop delays that delivery. Native progress, accepted work, failed-close retry, and cleanup joins remain.
  • Repeated scope/source/borrowed identity checks around internal continuation steps: already-admitted reads rely on their retained snapshot/native owner and the transport's real admission boundary, rather than revalidating internal state at every transition. Unsupported mid-operation source replacement may fail visibly; actual current-authority checks and original snapshot bytes remain.
  • Duplicate metadata-command clone: the sole production producer in plugin-metadata-state-worker creates a fresh command and privately copied stateKeys array and never mutates/exposes them. Hypothetical internal reuse during worker setup is not a supported caller contract. General transport command capture remains unchanged.

Evidence

Review repair head 1844c2827e78164ce7ea4761fd0652f1e2d4b596: accepted P2 on consume error ordering. An encoded worker failure must not be hidden by a later borrowed-owner observation failure. The repair reports failed outcomes directly, retains receipt phase and all cleanup joins, and still observes successful reads before returning them. The regression failed before the fix for the intended error-identity mismatch; its successful-read control passed. Fresh independent repair review is scoped-clean P0–P2. Targeted two-root types, type-aware lint, formatting and whitespace pass. Both new controls and the complete lifecycle file pass (10 cases), as does the mandatory suppression guard (14 cases): 24 focused cases, overlapping the prior proof below, not 24 additional unique cases. The serial wrapper completed successfully in995.38s, including worker generation preparation and final verification; the lifecycle file was668.43s wall/93%transform, while the two new cases executed in74/77ms. Current-head hosted CI remains required; CI timing is not yet available. No timeout, retry, skip or suppression was added.

Prior head 35be9add3c535138fd3826bd82da30c997d0764b: CI run39029010858 completed successfully. The full paginated census has140 completed checks:83success,56eligibility skips,1neutralCodeQL; zero failures, cancellations or pending jobs. Both PostgreSQL conformance suites, baseline ratchets, selected Node tests, security-fast and the aggregate CI gate passed. Neutral CodeQL is not presented as a successful baseline comparison. This is prior-head evidence, not the repaired head's gate. No CI rerun or unchanged-head push was used.

Fresh independent review covered the complete area diff. One P2 proposed restoring the metadata command clone; declined after inspecting the actual sole producer and full reference census, for the ownership reason above. No accepted/actionable findings remain; this is not described as a scoped-clean review.

Serial isolated proof passed: targeted types, type-aware lint of all thirteen files, formatting/whitespace, 135 focused tests (82 unit, 39 Gateway-lease integration, 14 suppression guards), zero runtime value cycles, and zero static cycles. All four narrowly selected native PR-wrapper inventory/import-closure cases also passed. Ten existing PostgreSQL-service-dependent cases were skipped because no local service is available; they are not counted as passes. The wrapper-inventory selection excluded eighteen unrelated cases rather than running the broad eager-import suite. Full check-changed, broad suites, whole-graph tsgo, builds, and E2E are not run locally under the host budget. Exact-head hosted CI is the broad gate.

CI repair: the original head's mock ratchet correctly required removing the obsolete unannotated worker-mock fingerprint. The existing controlled-transport mock already names its isolation reason; no annotation, test, assertion, or policy was changed. The one-row shrink passed the real complete-index checker (9,145 grandfathered factories) and independent P0–P2 review with zero findings. That ratchet-only repair did not change production or test inputs. The subsequent error-ordering repair has the separate focused proof above.

The original head's unchanged Gateway role case (server.roles-allowlist-update.test.ts, “enforces operator and node permissions”) failed with the null-object TypeError/UNAVAILABLE signature. Scheduled main run 39025102777, job 117374543124, independently reports that exact case and signature. Main's health digest requires fields omitted by the unchanged shared health mock; neither path is modified here. This is inherited failure evidence, not a claim of green CI. The repaired exact head still requires its complete hosted check census, including PostgreSQL conformance.

@clawsweeper

clawsweeper Bot commented Oct 17, 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 October 17, 2026 11:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T12:53:45.809912Z 1844c28 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a87d6e654

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces shared-read continuation bookkeeping and source-wide pumping with asynchronous query and cleanup ownership.

Example: A caller cancels a shared-state read while its transport is closing.

  • Before: Continuation bookkeeping coordinates cancellation and retained cleanup.
  • After: The asynchronous owner joins cleanup before reporting caller cancellation.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and coherent simplification with both prior findings resolved; behavioral evidence remains test-based, and current-head CI is unfinished.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor is outside the ordinary contributor proof gate; supplied validation exercises read lifecycle and real database paths through tests, without claiming a shipped CLI or Gateway demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Duplicated lifecycle machinery makes reliable shared-state reads and cleanup harder to maintain.
Reason: The area owner explicitly accepts the scheduling tradeoff, and the introduced change removes duplicate bookkeeping without adding configuration or a competing owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed simplification resolves both earlier findings, and no additional actionable defect was found; exact-head CI remains pending.

Priority: P2
Reviewed head: 1844c2827e78164ce7ea4761fd0652f1e2d4b596

Before merge

None.

Findings

None.

Agent review details

How this fits together

Shared-state callers submit typed reads to worker transports; the read owner retains native handles and snapshot files until query and cleanup settlement, then returns data or the original failure.

flowchart TD
Caller[Shared state caller] --> Owner[Async read owner]
Owner --> Snapshot[Retained snapshot or native handle]
Owner --> Transport[Read transport]
Transport --> Worker[Database worker]
Worker --> Cleanup[Transport and snapshot cleanup]
Snapshot --> Cleanup
Cleanup --> Result[Read result or error]
Loading

Technical review

Best possible solution:

Retain the simpler asynchronous owner with native cleanup retry and snapshot custody, then land through the existing exact-head CI gate.

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

This is a refactor; source inspection verifies the earlier error-ordering defect is repaired, and the maintainer reports its regression failed before the repair and passed afterward.

Is this the best way to solve the issue?

The change gives one asynchronous operation responsibility for query and cleanup settlement while preserving transport admission, original snapshots, and failed-close retry.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Manual read continuations and source-wide pumping changes intended behavior with a stated reason (9c93bc3: Retain snapshot and native-child custody through failures and permit callback-free progress by later readers.)
  • Synchronous snapshot cleanup ownership keeps the original intent (281307e: Keep native-reader closure and private-snapshot cleanup owned together.)
  • Metadata snapshot fast path keeps the original intent (0873425: Avoid synchronous plugin-state snapshots during metadata loading.)
  • Gateway owner inspection source registration keeps the original intent (7c2aa57: Inspect the stopped Gateway lease without copying state during ordinary startup admission.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9c93bc3 adds src/state/openclaw-state-read-worker.ts:140 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c93bc347cec; files: src/state/openclaw-state-read-worker.ts)

PR surface

Source -308, Tests -102, Other -1. Total -411 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 260 568 -308
Tests 8 205 307 -102
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 14 465 876 -411

Review metrics

Metric Value Why it matters
Production versus tests Production +260/-568; tests/support +205/-307; mock baseline -1 The change reduces production lifecycle machinery while preserving focused cancellation, failure, cleanup-retry, and snapshot contracts.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A useful shared-state lifecycle simplification warrants normal review priority without evidence of an urgent user-facing regression.
  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-17T11:19:20.965Z sha 2a87d6e :: needs changes before merge. :: [P2] Preserve the query failure when native-owner observation fails | [P2] Remove the stale baseline entry for the isolated mock
  • reviewed 2026-10-17T11:38:12.558Z sha 35be9ad :: needs changes before merge. :: [P2] Preserve the query failure when native-owner observation fails

Reviewed October 17, 2026, 8:56 AM ET / 12:56 UTC (Revision 3).

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head: 1844c28. The accepted read-error masking finding is fixed and the PR body/proof/counts are current. Ten lifecycle cases and fourteen suppression cases pass, including the before-failing error-ordering regression and its successful-read authority control. Targeted types, type-aware lint, formatting, whitespace, and independent repair review pass. Hosted CI on this new head remains pending; no prior-head CI waiver is claimed.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Exact-head landing evidence for 1844c2827e78164ce7ea4761fd0652f1e2d4b596:

  • CI 39034080159 is green. The complete paginated exact-head check census contains 143 completed checks: 86 success, 56 conditional/eligibility skips, and one neutral CodeQL result. No failures, cancellations, or pending checks remain.
  • PostgreSQL integrations 117400604367 and PostgreSQL infra 117400604296 both succeeded. The locally skipped service-dependent PostgreSQL coverage is not counted as a local pass; hosted CI supplies it.
  • CodeQL 117400725968 is neutral because 18 main baseline configurations are unavailable. This is not represented as a successful alert comparison.
  • Independent review is complete. The accepted error-ordering defect and obsolete mock-baseline finding are fixed; the regression failed before the repair and passed afterward, with a successful-read authority control. Targeted types/lint/format, focused lifecycle and suppression proof, runtime/static cycle checks, and selected native wrapper guards passed. The exact-head automated review reports no findings or before-merge actions.
  • Net production reduction: 308 lines. Native read/snapshot cleanup, failed-close retry, caller authority, and ordinary write-capable settlement remain. No schema, durability, retention, permissions, public contract, dependency, or Phase E change.

This uses the ordinary native landing workflow. No inherited-failure, prior-head CI, or infrastructure exception is requested.

@steipete
steipete merged commit 997e2bf into main Oct 17, 2026
146 checks passed
@steipete
steipete deleted the deslop/r05-2-read-operations-20261015 branch October 17, 2026 13:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 17, 2026
Restore the captured physical-file check at the shared reader dispatch
boundary, after database admission waits. #175443 removed repeated outer
checks, but its remaining recorded-authority check does not detect a
pathname replacement. Keep native worker validation and release admission
on refusal; prepared snapshots retain their existing semantics.

Tighten the existing pairing regression to require the identity error.
Baseline on 8cfa2ec: replacement case timed out at 120.018 s;
after: 0.006 s. Lifecycle file 152.78 s -> 33.22 s including transform.
64 focused cases passed; state-logging/other type graphs, targeted lint,
formatting, and independent P2 autoreview passed. No CI rerun or dispatch.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…175443)

* refactor(state): join shared reads through async ownership

* test(state): retire obsolete read-worker mock baseline

* fix(state): preserve read failures before observation
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…law#175628)

Restore the captured physical-file check at the shared reader dispatch
boundary, after database admission waits. openclaw#175443 removed repeated outer
checks, but its remaining recorded-authority check does not detect a
pathname replacement. Keep native worker validation and release admission
on refusal; prepared snapshots retain their existing semantics.

Tighten the existing pairing regression to require the identity error.
Baseline on 1979379: replacement case timed out at 120.018 s;
after: 0.006 s. Lifecycle file 152.78 s -> 33.22 s including transform.
64 focused cases passed; state-logging/other type graphs, targeted lint,
formatting, and independent P2 autoreview passed. No CI rerun or dispatch.
SunnyShu0925 pushed a commit to SunnyShu0925/openclaw that referenced this pull request Oct 28, 2026
consume() only checked the caller signal after a read settled, so an
admission revoked while the read was in flight still returned a
successful reply. Re-assert the operation authority before returning the
value, skipping only operations that close() is already draining, which
keeps the accepted-reader settlement contract from openclaw#175443.
SunnyShu0925 pushed a commit to SunnyShu0925/openclaw that referenced this pull request Oct 29, 2026
consume() only checked the caller signal after a read settled, so an
admission revoked while the read was in flight still returned a
successful reply. Re-assert the operation authority before returning the
value, skipping only operations that close() is already draining, which
keeps the accepted-reader settlement contract from openclaw#175443.
shuisadev pushed a commit to shuisadev/openclaw that referenced this pull request Nov 16, 2026
consume() only checked the caller signal after a read settled, so an
admission revoked while the read was in flight still returned a
successful reply. Re-assert the operation authority before returning the
value, skipping only operations that close() is already draining, which
keeps the accepted-reader settlement contract from openclaw#175443.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant