Skip to content

perf(sessions): avoid registry waits for canonical recovery stores - #175129

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-delivery-discovery-boot-stall-20260919
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-delivery-discovery-boot-stall-20260919

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restart delivery discovery unnecessarily requests the shared-state ownership registry even when every session store has a canonical per-agent path. A busy state reader can therefore delay discovery before pending delivery input is inspected.

User Impact

Canonical agent-store recovery no longer waits for an ownership registry lookup that cannot change the selected owner. Fixed/shared store ownership, ambiguous physical aliases, admission checks, and unreadable-registry refusal remain intact.

Why This Change Was Made

The target resolver already returns the owner encoded by canonical per-agent paths. Dedupe nevertheless requested registry rows first, forcing deferred recovery inventory through discovery, cleanup, a shared-state registry read, and a second discovery request. Demand the registry only where ownership actually depends on it, and reuse the first snapshot throughout the synchronous dedupe pass.

Production delta: +12/-10 lines. The two net additional lines preserve the existing one-registry-read-per-pass contract for fixed/shared stores while removing the unconditional read. There is no new persistent cache, schema, configuration, worker, or fallback path. Tests add 41 lines; documentation adds four.

Evidence

  • Focused local proof: node scripts/run-vitest.mjs src/config/sessions/session-store-target-inventory.test.ts src/config/sessions/targets-dedupe.test.ts src/config/sessions/targets.test.ts --maxWorkers=1 — 32 passed. The canonical recovery regression fails on the original implementation with session-target-registry-required and passes with registry access still deferred.
  • Linux rig, 50 canonical agent stores: all six baseline inventory calls requested registry rows; all six patched calls resolved all 50 targets with the registry still deferred (29–67 ms). This proves removed work, not a comparable timing speedup.
  • Review caught repeated registry listings for shared targets in the first patch. Its regression failed with three listings instead of one; the final implementation reuses the first demanded snapshot. Fresh independent Codex review of the complete corrected candidate is scoped-clean through P2.
  • Changed-file oxfmt, repository oxlint scoped to the changed files, and git diff --check passed. Broad validation runs in PR CI; no Testbox/Crabbox lease was allocated.

Packaged Gateway measurements

Sequential Linux-rig runs used the supported gatewayWatch runtime build, synthetic 5,000-session/6,000-run fixtures with 200 approvals, 100 cron jobs, 12 projects/worktrees, and ~240 MiB of state. Each version had one initial start and one actual restart of its own fixture. The patched build used 66ffabc522ac plus the final production change. All completed with clean shutdowns. The separate 50-agent proof covers multiple-store topology; this row-count fixture has one agent store.

Restart measurements:

Revision deliveryDiscoveryMs Process start to HTTP ready Process start to recovery completion
c5733c40baa2 891.0 ms 15.374 s 19.831 s
66ffabc522ac 812.0 ms 17.236 s 20.881 s
66ffabc522ac + final fix 1,022.7 ms 18.508 s 24.694 s

First-start discovery was 1,220.4 / 849.9 / 876.4 ms respectively. An additional unchanged-candidate start on the same fixture measured 754.1 ms discovery, 23.740 s HTTP readiness, and 30.699 s recovery completion. HTTP readiness precedes delivery recovery completion; these are distinct boundaries.

The shared 8-CPU rig had load ~13 and 1–3% sampled idle CPU during candidate runs. Candidate discovery spans 754–1,023 ms around the baseline's 812–850 ms, while reader admission, execution recovery, and registry activation also vary substantially. These measurements establish neither a discovery speedup nor end-to-end startup neutrality. The deterministic benefit is removal of the unnecessary registry queue dependency.

The reported production 0.6 ms → 50-second discontinuity was not reproduced or bisected to a specific commit. Source audit found no direct discovery-algorithm change between the cited revisions. This PR removes a proven unnecessary wait without claiming to explain the entire incident. Confirming incident resolution after deployment remains a follow-up.

CI inherited-failure exception

Landing under the authorized inherited-failure exception for head adf22fb0a9df645cbad03ca96578e3f246825e39.

The only failing product check is PostgreSQL conformance. PR job 117319295899 reports src/infra/database-engine/matrix-roots.postgres.test.ts → ports every retained token/account root with the state family and restores fresh namespaces timing out at 300,000 ms; the job subsequently hit its 30-minute overall budget. Scheduled main job 117309835227, at 737a0ac25447438a039295a6200ced99d6bc4a6d, reports the identical case and timeout. The test blob is identical in main and this PR (ed1c853fdd3486c10f6e8b2c0a360c9af3e4c243). No new failing test case appears in the PR log.

All other selected code checks passed. The aggregate CI gate is red because PostgreSQL conformance was canceled by the job budget. Focused inventory/dedupe/target tests passed (32 tests), including both regressions; independent review is clean and the review thread is resolved. No CI rerun was requested. This exception does not claim the PostgreSQL check passed.

Resolve canonical per-agent ownership from its existing path contract before requesting registry rows. Fixed/shared stores and ambiguous aliases retain authoritative registry reads and refusal semantics. This removes a redundant shared-state reader dependency from restart delivery discovery without adding a cache or changing storage.
@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 in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 17, 2026 05:08
@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-17T05:26:17.252991Z adf22fb 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 docs Improvements or additions to documentation size: XS labels Oct 17, 2026

@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: a5ed73a512

ℹ️ 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 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 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The branch now preserves one lazy registry snapshot per discovery pass, with a regression for multiple shared targets. The PR body includes the final packaged restart measurements and their limitations.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 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 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 loads ownership registry rows only when target selection needs them and shares one snapshot throughout each dedupe call.

Example: Restart discovery finds canonical session stores for agents main and helper while registry access is deferred.

  • Before: The inventory requests registry rows and requires another discovery pass.
  • After: Both canonical targets resolve while registry access remains deferred.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with relevant regression coverage and packaged runtime evidence; performance conclusions remain appropriately limited.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Linux packaged Gateway start/restart measurements exercise recovery with the final production change, while canonical inventory comparisons demonstrate removal of the registry dependency; neither establishes a latency improvement or resolution of the broader incident.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Restart delivery discovery can wait behind a shared-state reader even when canonical paths already determine every store owner.
Reason: The maintainer-authored direction removes proven unnecessary work with a narrow change; resolving the broader reported startup incident remains outside its stated claim.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it removes an unnecessary recovery dependency that remains on current main, and the corrected patch has no actionable findings.

Priority: P2
Reviewed head: adf22fb0a9df645cbad03ca96578e3f246825e39

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session target discovery converts configured and discovered store paths into logical agents and physical database targets for recovery and other session readers.

flowchart TD
  A[Recovery discovery] --> B[Prepared store inventory]
  B --> C[Discovery worker]
  C --> D[Target dedupe]
  D --> E[Canonical path owner]
  D --> F[Lazy registry snapshot]
  E --> G[Selected database targets]
  F --> G
Loading

Technical review

Best possible solution:

Retain the lazy invocation-local snapshot and existing ownership checks, then land through the normal exact-head CI gate.

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

Current-main source shows canonical recovery inventory demanding registry rows before path resolution; the supplied regression reports the expected base failure, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch removes the redundant read at its existing owner and preserves one snapshot per synchronous pass without introducing another cache or resolver.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Registry admission and physical-owner dedupe changes intended behavior with a stated reason (fix(sessions): bound store lookup to stop gateway CPU wedge without dropping retired stores #124516: The earlier optimization skipped identity matching where path ownership already won but deliberately retained eager registry failure semantics; later worker discovery introduced deferred registry reads. Local history across the moved module confirmed the contributor trail, although older content searches encountered a missing promisor object.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Sergio Cadavid: Raw commit 45c6b47 adds src/config/sessions/targets-dedupe.test.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: low; commits: 45c6b47ed082; files: src/config/sessions/targets-dedupe.test.ts)

PR surface

Source +2, Tests +41, Docs +4. Total +47 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 12 10 +2
Tests 2 41 0 +41
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 57 10 +47

Labels

Label changes:

  • add P2: Removing an unnecessary shared-reader dependency improves recovery preparation without establishing an urgent outage or a measured end-to-end speedup.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Removing an unnecessary shared-reader dependency improves recovery preparation without establishing an urgent outage or a measured end-to-end speedup.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 17, 2026, 1:37 AM ET / 05:37 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing under the authorized inherited-failure exception for head adf22fb0a9df645cbad03ca96578e3f246825e39.

The only failing product check is PostgreSQL conformance. PR job 117319295899 reports src/infra/database-engine/matrix-roots.postgres.test.ts → ports every retained token/account root with the state family and restores fresh namespaces timing out at 300,000 ms; the job subsequently hit its 30-minute overall budget. Scheduled main job 117309835227, at 737a0ac25447438a039295a6200ced99d6bc4a6d, reports the identical case and timeout. The test blob is identical in main and this PR (ed1c853fdd3486c10f6e8b2c0a360c9af3e4c243). No new failing test case appears in the PR log.

All other selected code checks passed. The aggregate CI gate is red because PostgreSQL conformance was canceled by the job budget. Focused inventory/dedupe/target tests passed (32 tests), including both regressions; independent review is clean and the review thread is resolved. No CI rerun was requested. This exception does not claim the PostgreSQL check passed.

@steipete
steipete merged commit 64495be into main Oct 17, 2026
150 of 157 checks passed
@steipete
steipete deleted the steipete/perf-micro-delivery-discovery-boot-stall-20260919 branch October 17, 2026 05:59
steipete added a commit that referenced this pull request Oct 17, 2026
Drain retained parent shared-state handles after the Doctor child settles,
including unsuccessful exits, before revoking schema admission. The next
parent access must admit the resulting database schema again. This keeps
updates from silently reusing admission from before Doctor migrated it,
without restoring per-read schema probes removed in #175077.

Refuse destructive Doctor session migration before target preparation when
the shared-state database is absent but its SQLite sidecars survive. Keep
legacy source and WAL bytes intact and tell the operator to restore the
matching database. Canonical-path recovery retains #175129's registry-read
optimization; source preservation no longer depends on that incidental read.

The existing regressions reproduced on origin/main cec76b0: both
Doctor exit-code cases and shared-state orphan-WAL preservation failed.
After the fix all 11 cases in the two owning files pass unchanged.
Core types, targeted lint, formatting, docs MDX and whitespace checks pass.
Independent P2 review found no actionable P0-P2 findings.
Sibling proof: 65/65 pass across Doctor authority/delegation and session
recovery/restore; 186.85 s command wall. No tests or assertions changed.
OAuth's same-hourly failure is covered by active PR #175069 and untouched.
steipete added a commit that referenced this pull request Oct 17, 2026
…5295)

Reopen cold state handles after an observed schema-owner handoff so a
newer schema is refused before the first write callback. Keep warm
schema admission cached as intended by #175077.

Retain exact execute-refusal provenance through worker retirement and
deliver the original host lifecycle error. Preserve shared preparation
from #175008, native-exit joining and unknown execute settlement.

Exercise registry error handling with a custom store that requires the
registry after #175129. Keep every existing assertion.

Before: three deterministic main failures,35passes,128.76s wall.
After: all38tests pass,211.93s wall including worker rebuild; files took
92.46s/54.14s/49.98s through native --maxWorkers=1 wrapper.
Targeted types/lint/format pass; P2 review scoped-clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…penclaw#175129)

* perf(sessions): avoid registry waits for canonical recovery stores

Resolve canonical per-agent ownership from its existing path contract before requesting registry rows. Fixed/shared stores and ambiguous aliases retain authoritative registry reads and refusal semantics. This removes a redundant shared-state reader dependency from restart delivery discovery without adding a cache or changing storage.

* fix(sessions): reuse demanded ownership snapshot during discovery
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…#175300)

Drain retained parent shared-state handles after the Doctor child settles,
including unsuccessful exits, before revoking schema admission. The next
parent access must admit the resulting database schema again. This keeps
updates from silently reusing admission from before Doctor migrated it,
without restoring per-read schema probes removed in openclaw#175077.

Refuse destructive Doctor session migration before target preparation when
the shared-state database is absent but its SQLite sidecars survive. Keep
legacy source and WAL bytes intact and tell the operator to restore the
matching database. Canonical-path recovery retains openclaw#175129's registry-read
optimization; source preservation no longer depends on that incidental read.

The existing regressions reproduced on origin/main 65bc05f: both
Doctor exit-code cases and shared-state orphan-WAL preservation failed.
After the fix all 11 cases in the two owning files pass unchanged.
Core types, targeted lint, formatting, docs MDX and whitespace checks pass.
Independent P2 review found no actionable P0-P2 findings.
Sibling proof: 65/65 pass across Doctor authority/delegation and session
recovery/restore; 186.85 s command wall. No tests or assertions changed.
OAuth's same-hourly failure is covered by active PR openclaw#175069 and untouched.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…nclaw#175295)

Reopen cold state handles after an observed schema-owner handoff so a
newer schema is refused before the first write callback. Keep warm
schema admission cached as intended by openclaw#175077.

Retain exact execute-refusal provenance through worker retirement and
deliver the original host lifecycle error. Preserve shared preparation
from openclaw#175008, native-exit joining and unknown execute settlement.

Exercise registry error handling with a custom store that requires the
registry after openclaw#175129. Keep every existing assertion.

Before: three deterministic main failures,35passes,128.76s wall.
After: all38tests pass,211.93s wall including worker rebuild; files took
92.46s/54.14s/49.98s through native --maxWorkers=1 wrapper.
Targeted types/lint/format pass; P2 review scoped-clean.
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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