Skip to content

fix(sessions): keep history readers independent of host acquisition - #174586

Merged
steipete merged 4 commits into
mainfrom
fix/history-reader-maintenance-closure
Oct 16, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/history-reader-maintenance-closure

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restores the history-reader import boundary broken by the agent-engine migration guard in #174360.

User Impact

No change to migration permissions or normal history results. Read-only history code no longer loads the host state-acquisition module just to reach the retained maintenance-authority check.

Why This Change Was Made

The engine imported its strict guard from the lease module, introducing history reader → readonly open → engine → lease → openclaw-state-db. #174360 explicitly requires that “the family guard also runs for ordinary forward opens,” so removing the guard would be wrong.

Move the existing guard and its single AsyncLocalStorage context into a private leaf module. The lease owner retains publication/renewal; all strict-guard consumers and their existing fault-injection spies use the leaf. Expected-context identity, live lease ownership and scope admission checks retain their order and behavior. There is no compatibility re-export, new authority mechanism, schema change, or migration change.

Evidence

Current-main baseline reproduced the exact forbidden backedge (4 pass / 1 fail). The existing architecture assertion remains unchanged.

Focused history-reader, maintenance, transcript-directive migration and historical-media migration suites cover the moved guard's consumers, including authority expiry before transaction commit, archive rename and final publication. All 42 focused cases passed (174.09 s including worker compilation); the wrapper inventory passed all 3 cases (6.93 s). Targeted source/test typecheck, type-aware lint, formatting, and isolated P2 autoreview pass. The native worker bundle builds successfully. Wrapper source-closure proof includes the new private leaf.

The PostgreSQL engine receives the same strict guard. After integrating main, all 22 cases in the direct engine, agent database owner, port, and Doctor PostgreSQL suites passed locally against the CI-pinned image, including the v27→v28 rollback cases. The temporary database was removed after proof.

The same change also updates the exact service-relay artifact inventory for the client SQLite catalog intentionally added by #174294. The runtime lineage writer retains the shared lazy catalog reader; the new catalog is a required emitted asset. All no-extra-chunk and unresolved-import checks remain. Its full test file moved from 56 pass / 1 fail to 57 pass (122.56 s wrapper), with targeted types, lint, formatting and separate P2 review passing.

The direct push of the test-only commit lost a main update race before writing any ref. Both reviewed fixes are included here for one CI run. No CI dispatch or rerun was used.

CI follow-up

The first CI run, 38954337120, exposed an existing worker-resume fixture cleanup gap: the case body completed, but root removal raced asynchronous database-resource retirement and failed with ENOTEMPTY. The follow-up awaits the existing async close owner before root removal. All six cases pass locally (38.36 s wrapper); targeted types/lint/format and P2 review pass. Every assertion and deadline is unchanged.

That run also hit the pinned-Bun CLI fork-recovery deadlock at its unchanged 100-second guard. It reproduces on this candidate and on clean base 746a52a3618e with the same no-output/no-diagnostics failure; the earlier #174545 independently records it on unchanged main. This remains an inherited CI failure, not a passing check or a repaired runtime. No retry, timeout change, skip or CI rerun was used. The previous auto-merge request was retired through native recovery before publishing the real fixture repair.

The prior head's run 38956699936 repeats that CLI deadlock and reports seven offline-maintenance refusals in sessions.abort-durability.test.ts. The abort suite passed all seven cases on the prior PR head. All seven failures reproduce on the run's exact protected-main parent f2f87767245f (46.79 s), with the same shared-state broker-admission stack. The test, shared-state authority owner, broker admission/reply and replacement worker have identical blobs between that baseline and the tested merge c229587471e2. These failures are inherited from the newer main context, not claimed fixed here; admission checks and every abort assertion remain intact. These observations qualify only the prior head; the new head requires its own CI result.

Main integration and current proof

Merged main a3355d9ef3d24cb6d89bb2fce84161ce996028b0 into the PR as ac02919bea050cfd3276457cd95edfb233babc8c. The single engine import conflict from #174036 is resolved by retaining main's new schema-version imports and this PR's maintenance-authority import. The final diff against that main remains the same 16-file repair; no unrelated repair edits were added.

On the merged tree, 107 cases passed across the relay inventory, wrapper closure, history imports, maintenance, storage migration, and Doctor migration suites (356.41 s including worker preparation). Another 22 cases passed in the four PostgreSQL importer/owner suites (160.76 s including catalog verification and worker preparation). The generated PostgreSQL catalog reported zero unexplained differences. All tests used one worker; assertions, coverage and deadlines are unchanged.

Targeted source/test typechecks, type-aware core and tooling lint, formatting, and isolated P2 review passed. The review found no actionable P0–P2 findings. No CI workflow was dispatched or rerun. The PR remains ready for the lead to land after the new head's CI; prior-head CI is retained only as prior-head evidence.

PR #174294 intentionally adds local client credential schema facts to the
shared lazy SQLite catalog reader. The service anchor's lineage writer
retains that reader, so its emitted closure includes the client catalog.
Keep the exact artifact inventory and all unresolved-import assertions.

Current-main baseline: 56 passed, one exact seventh-asset mismatch.
After: 57 passed (122.56 s wrapper / 118.15 s Vitest).
Targeted tsgo, type-aware lint, format, and P2 autoreview pass.
PR #174360 correctly requires the agent engine to revalidate retained
maintenance authority, including ordinary forward opens. Importing that
guard through the lease owner also pulled host state acquisition into the
read-only history graph.

Move the existing strict guard and its single AsyncLocalStorage context to
a private leaf. Migrate every strict-guard consumer and the existing
fault-injection spies. Lease identity, expiry and scope checks are unchanged.

Baseline: history import boundary fails with engine -> lease -> host state.
After: all 42 focused history, maintenance and migration tests pass; wrapper
source closure 3/3 passes. Targeted types, lint, formatting and P2 review pass.
PostgreSQL migration execution remains PR CI proof (no local server).
@clawsweeper

clawsweeper Bot commented Oct 16, 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 16, 2026 19:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T20:32:11.783180Z ac02919 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Oct 16, 2026
@steipete
steipete enabled auto-merge (squash) October 16, 2026 19:31
@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. labels Oct 16, 2026
@steipete
steipete disabled auto-merge October 16, 2026 19:38
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves the maintenance guard into a private leaf module, updates its consumers, and repairs two existing test expectations or cleanup paths.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, mechanically sound boundary repair supported by focused integration and architecture evidence; no shipped-entry-point demonstration was supplied.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal relocation is outside the ordinary contributor proof gate; supplied validation covers import closure, real-database maintenance consumers, archive fencing, and PostgreSQL migration suites.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: History readers unnecessarily load host state acquisition through the database engine.
Reason: The maintainer-authored repair restores an existing isolation contract without changing history results, permissions, configuration, or stored data.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR repairs a current import-boundary regression while preserving maintenance authority checks; no actionable introduced defects were found, and current-head CI remains unresolved.

Priority: P2
Reviewed head: ac02919bea050cfd3276457cd95edfb233babc8c

Before merge

None.

Findings

None.

Agent review details

How this fits together

History readers open existing agent databases through the engine adapter; maintenance callers supply the retained lease context that authorizes migrations and archive publication.

flowchart TD
  A[History readers] --> B[Read-only database opener]
  B --> C[Agent engine adapter]
  C --> D[Maintenance authority leaf]
  E[Maintenance lease owner] --> D
  F[Migration and archive writers] --> D
Loading

Technical review

Best possible solution:

Retain the strict guard in the private leaf and complete native landing once the current-head CI gate is resolved.

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

Source establishes history reader → read-only opener → engine → lease → host state acquisition, contradicting the existing architecture assertion; no target code was executed during this review.

Is this the best way to solve the issue?

Moving the unchanged guard and shared context together fixes the dependency at its producer while retaining lease ownership and every existing effect-boundary check.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Strict maintenance guard and retained async context keeps the original intent (b03d2e7: Participant-identity migrations required stopped-writer authority; later maintenance fencing retained live ownership checks before commit and archive publication.)
  • Engine migration admission keeps the original intent (407c309: Forward PostgreSQL migrations must retain the family maintenance guard and exact rollback contract.)
  • Service relay artifact inventory keeps the original intent (3a294a0: The exact inventory allows lazy catalog assets while preventing additional runtime chunks and unresolved imports.)
  • Worker resume fixture cleanup keeps the original intent (381b1e0: The fixture closes agent resources after exercising resume; awaiting the existing close owner completes that cleanup before root removal.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b03d2e7 adds src/state/openclaw-agent-db-lease.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b03d2e79e9aa; files: src/state/openclaw-agent-db-lease.ts)
  • Omar Shahine: Raw commit 70c2e66 adds src/state/openclaw-agent-db-lease.ts:59 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 70c2e666ec6a; files: src/state/openclaw-agent-db-lease.ts)

PR surface

Source -3, Tests +3, Other +1. Total +1 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 11 36 39 -3
Tests 4 11 8 +3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 16 48 47 +1

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repairs a concrete history-reader architecture regression with limited behavioral scope and unchanged migration permissions.
  • 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 (1 earlier review cycle)
  • reviewed 2026-10-16T19:37:55.209Z sha 7131956 :: needs maintainer review before merge. :: none

Reviewed October 16, 2026, 4:36 PM ET / 20:36 UTC (Revision 2).

CI finished the first resume case but root removal raced asynchronous
agent-database resource retirement and failed with ENOTEMPTY. The synchronous
close API starts that retirement without joining it. Await the existing async
owner before the shared fixture removes its root. Keep every assertion and
deadline unchanged.

All six file cases pass locally (38.36 s wrapper); targeted types, type-aware
lint, format and isolated P2 review pass. The CI failure is not claimed to be
a regression caused by the history import repair.
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 16, 2026
Integrate main a3355d9 and resolve the engine import conflict from
#174036. Retain both schema-version imports and the strict authority guard
from the private maintenance-authority module. No unrelated repair edits.

Focused proof: 107 tests across the relay inventory, wrapper closure,
history imports, maintenance, storage migration and Doctor migration
suites; 22 PostgreSQL tests across four direct engine/owner/port/migration
suites. Targeted typechecks, type-aware lint, formatting and isolated P2
review pass. No CI dispatch or rerun.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Oct 16, 2026
@steipete
steipete merged commit 1a314b8 into main Oct 16, 2026
168 of 174 checks passed
@steipete
steipete deleted the fix/history-reader-maintenance-closure branch October 16, 2026 21:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…penclaw#174586)

* test(build): include client catalog in service relay closure

PR openclaw#174294 intentionally adds local client credential schema facts to the
shared lazy SQLite catalog reader. The service anchor's lineage writer
retains that reader, so its emitted closure includes the client catalog.
Keep the exact artifact inventory and all unresolved-import assertions.

Current-main baseline: 56 passed, one exact seventh-asset mismatch.
After: 57 passed (122.56 s wrapper / 118.15 s Vitest).
Targeted tsgo, type-aware lint, format, and P2 autoreview pass.

* fix(sessions): keep history readers independent of host acquisition

PR openclaw#174360 correctly requires the agent engine to revalidate retained
maintenance authority, including ordinary forward opens. Importing that
guard through the lease owner also pulled host state acquisition into the
read-only history graph.

Move the existing strict guard and its single AsyncLocalStorage context to
a private leaf. Migrate every strict-guard consumer and the existing
fault-injection spies. Lease identity, expiry and scope checks are unchanged.

Baseline: history import boundary fails with engine -> lease -> host state.
After: all 42 focused history, maintenance and migration tests pass; wrapper
source closure 3/3 passes. Targeted types, lint, formatting and P2 review pass.
PostgreSQL migration execution remains PR CI proof (no local server).

* test(gateway): drain agent resources before removing resume fixture

CI finished the first resume case but root removal raced asynchronous
agent-database resource retirement and failed with ENOTEMPTY. The synchronous
close API starts that retirement without joining it. Await the existing async
owner before the shared fixture removes its root. Keep every assertion and
deadline unchanged.

All six file cases pass locally (38.36 s wrapper); targeted types, type-aware
lint, format and isolated P2 review pass. The CI failure is not claimed to be
a regression caused by the history import repair.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. 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: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant