Skip to content

refactor(state): share prepared read and diagnostic types - #159128

Merged
steipete merged 6 commits into
mainfrom
perf/d4-state-worker-deslop
Sep 27, 2026
Merged

steipete merged 6 commits into
mainfrom
perf/d4-state-worker-deslop

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Removes duplicated state read-context and diagnostic activity type definitions left in the performance campaign's session/state owners.

User Impact

No runtime behavior change. The remaining three changed modules emit identical JavaScript to the branch base after TypeScript erasure and repository formatting. Authority checks, freshness, queue ordering, diagnostic cutoffs, schemas, stored data, and update behavior remain unchanged.

Why This Change Was Made

Diagnostic session activity includes the recovery owner's existing five-map shape instead of declaring it again. Its three marker types become private because the duplicate declaration was their only outside consumer. The state read-context alias derives from the capture owner's explicitly declared return type.

The snapshot-reader callback consolidation was withdrawn after investigating a Linux CI shutdown hang. agent-deletion-journal.read.ts is now byte-identical to the branch base. This deliberately leaves the PR entirely type-only; it does not claim to repair the latent shutdown hang.

D4 reviewed the thirteen supplied merged commits and their owners, plus D1a/D1b (#158656 and #158834). Distinct WAL ownership, worker settlement/cleanup ordering, label validation, physical identity checks, and resident-authority fallbacks remain intact. No shared worker-operation framework was introduced.

Evidence

  • Production: +9 / -19, net -10 LOC across three files. Tests/test support: 0 LOC changed.
  • Runtime equivalence: Node TypeScript erasure followed by repository oxfmt produces byte-identical JavaScript for all three changed files against main base 0a9fa7dafabec7ce52c5dac5bd71b9e3c1bcc784. The restored snapshot-reader source matches that base exactly.
  • Focused owner/sibling proof: node scripts/run-vitest.mjs src/logging/diagnostic-run-activity-owners.test.ts src/logging/diagnostic-run-activity.test.ts src/state/agent-deletion-journal.snapshot.test.ts src/state/openclaw-state-db-async-lifecycle.test.ts src/config/sessions/startup-migration.registry-recovery.test.ts — 68 passed, 58.30 s wall.
  • Final correction d0b610346fc6f30f7d952873cd47fe1132ba1577: the original 26-file Linux shard passed 92/92 in 130.40 s wall, without diagnostic probes or timeout changes. The four touched/originally touched files passed lint with 0 warnings and 0 errors, production tsconfig.core.json passed, and core-test-state-logging / core-test-gateway-server passed (41.3 s / 40.2 s). The first test-type invocation used noncanonical graph names and was rejected before compilation; the corrected invocation passed. Final Testbox workflow, lease tbx_01m3gb1c6xat19rb8bjntrhw4a; the earlier investigation lease completed and final lease was stopped after validation.
  • Test audit retained the existing authority, freshness, delayed-deletion, and diagnostic cutoff regressions. No tests or production test seams were added.
  • Formatting and git diff --check passed. Independent Codex review through P2 found no accepted/actionable findings.

The original failing CI job on 64a12451f897 first timed out in resumes admitted but unprocessed input after a Gateway restart after 120 seconds; subsequent cases found the fixture still closing, and suite cleanup timed out. The gateway closed (1006) log belonged to a passing sibling replay test.

The recorded 26-file/92-test shard passed locally on both that PR head (265.18 s) and main d9c7aa507db1 (265.37 s). On one Linux Testbox, the original PR head reproduced the hang (483.06 s), while that main revision passed all 92 tests (136.25 s). The exact embedded main base 0a9fa7dafabe also passed the unmodified Linux shard (119.68 s). Temporary shutdown-stage and timeout-only probes passed and were removed. The precise intermittent shutdown mechanism remains unestablished; passing replays are not presented as a fix. The conservative correction removes the PR's only runtime change.

A possible maintainer design follow-up remains a typed operation descriptor within the shared read owner. Its four plumbing files total 2,208 production lines, including 101 standalone repeated success/admission envelope lines. An estimated 100–200 net lines might be recoverable while retaining explicit validation, capture, byte budgets, and authority checks. This is an unimplemented estimate requiring a maintainer design decision.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 26, 2026 19:40
@steipete
steipete enabled auto-merge (squash) September 26, 2026 19:42
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 11:02 PM ET / September 27, 2026, 03:02 UTC (Revision 4).

ClawSweeper review

What this changes

The branch shares diagnostic recovery activity types and derives the SQLite read-context type from its capture function.

Merge readiness

✅ Ready for maintainer review

Keep this PR open. Current main still contains the duplicated declarations, and the revised branch is a coherent type-only cleanup. The earlier runtime change associated with a shutdown concern was withdrawn; the pinned diff shows no introduced functional defect.

Priority: P3
Reviewed head: d0b610346fc6f30f7d952873cd47fe1132ba1577

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused type-only patch with relevant existing boundary coverage and no identified correctness or security defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The changed production files retain their runtime statements; this MEMBER-authored type-only cleanup has no after-fix real-setup proof gate. The PR body reports type-erasure equivalence and focused Testbox checks. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The changed production files retain their runtime statements; this MEMBER-authored type-only cleanup has no after-fix real-setup proof gate. The PR body reports type-erasure equivalence and focused Testbox checks. No stored-data contract changes.
Evidence reviewed 7 items Pinned introduced diff: The merge-base-to-head patch changes only TypeScript type declarations across the three listed files; it contains no changed runtime statements.
Diagnostic type owner: The recovery module defines the five-map activity shape now included by the session activity type; its cleanup and recovery operations continue to use that shape.
Read-context owner: The capture function retains its explicit four-field return contract, which the proposed alias now derives with ReturnType.
Findings None None.
Security None None.

How this fits together

Diagnostic events feed a session activity tracker that produces health snapshots. SQLite read requests use a captured admission context before worker-backed reads; this PR changes the types describing those two flows.

flowchart LR
  A[Diagnostic events] --> B[Session activity]
  B --> C[Recovery activity contract]
  C --> D[Health snapshot]
  E[SQLite read request] --> F[Admission capture]
  F --> G[Read context contract]
  G --> H[Worker reader]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -10. Total -10 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 3 9 19 -10
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 9 19 -10

Review metrics

None.

Technical review

Best possible solution:

Keep one type owner for each flow while preserving the existing recovery and SQLite admission checks.

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

Not applicable: this PR addresses duplicated type declarations rather than a runtime bug. The pinned source diff establishes the cleanup target.

Is this the best way to solve the issue?

Yes. The proposed aliases use the existing type owners and leave the runtime recovery and read-admission paths intact.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2e09d9e2e60a.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a small internal type cleanup with no intended runtime or user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed production files retain their runtime statements; this MEMBER-authored type-only cleanup has no after-fix real-setup proof gate. The PR body reports type-erasure equivalence and focused Testbox checks. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-26T20:10:24.076Z sha a5ea038 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T22:36:04.186Z sha ad1dccc :: blocked before merge. :: none
  • reviewed 2026-09-27T00:06:22.927Z sha 64a1245 :: blocked before merge. :: none

@steipete

steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

CI investigation: the failure in checks-node-changed-extensions-bundle-17 (job 108477660650, run 36268164948) is an existing Feishu test synchronization race, unrelated to this refactor.

The failing assertion is monitor.post-replay.test.ts:136: reply delivery counts were [1, 0] rather than [1, 1]. The sender-retired diagnostics in that job belong to earlier authority/lifecycle tests; they are not this test's failure.

The fixture waits for an empty ingress queue, but transport adoption clears the queue before replay-claim commit and reply delivery complete. A controlled deferred-adoption schedule reproduces the exact assertion failure on main 915e37b7ddcbf884a78cb650e9463bfa9f0000e9. The fixture repair will await the already-owned reply-dispatcher completion promise, preserving all replay assertions and production behavior.

Bounded comparison after a frozen dependency install:

  • Exact PR head a5ea038b84ab89cf8638b0e682e0b2148f424ed0: focused file passed; original 16-file shard passed all 308 tests (110.05 s wrapper wall).
  • Main 915e37b7ddcbf884a78cb650e9463bfa9f0000e9: focused file passed; same 16-file shard passed all 308 tests (131.73 s wall).
  • Latest scheduled main failures were the already-repaired Cron fixtures, not this Feishu assertion.

Source inspection confirms the runtime change here reuses the same captured admission checks, in the same order; the remaining changes are TypeScript type ownership. A passing replay alone is not claimed as a fix. The separate fixture repair is tracked in #159168; a controlled deferred-adoption schedule fails before the fix and passes after it. The repaired original shard passes all 308 tests, and independent review is clean through P2.

Requesting exactly one targeted rerun of job 108477660650 on this unchanged head under the documented unrelated-fixture exception. Squash auto-merge remains enabled.

Rerun outcome: job 108480618180 passed on the unchanged head (20:25:59–20:34:54 UTC). The workflow remains canceled because 81 sibling checks were canceled by the original fail-fast; the only remaining failed job is the aggregate gate 108482055203. No second test rerun has been requested. Resuming the canceled coverage is with the coordinator under the stated single-job rerun limit.

Restore the original snapshot admission assertion callback while investigating the Linux Gateway restart timeout. Retain only type-shape consolidation with identical emitted JavaScript.
@steipete steipete changed the title refactor(state): reuse prepared admission and diagnostic facts refactor(state): share prepared read and diagnostic types Sep 27, 2026
@steipete
steipete merged commit 247f33e into main Sep 27, 2026
213 checks passed
@steipete
steipete deleted the perf/d4-state-worker-deslop branch September 27, 2026 03:08
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…59128)

* refactor(state): reuse prepared admission and diagnostic facts

* refactor(state): keep D4 consolidation type-only

Restore the original snapshot admission assertion callback while investigating the Linux Gateway restart timeout. Retain only type-shape consolidation with identical emitted JavaScript.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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