Skip to content

perf(gateway): retain agent and session boot filesystem facts - #170467

Merged
steipete merged 1 commit into
mainfrom
steipete/coldload-gateway-boot-fs-work
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/coldload-gateway-boot-fs-work

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A signed-in reload of a dashboard deep link passed through 14 visible states over roughly 15 seconds in the campaign evidence. Gateway boot RPCs repeatedly prepared agent paths, workspace Git display facts, session sources, and database identity. After the Talk fix, filesystem callbacks accounted for roughly 735 inclusive samples.

Change

PR A of the split requested by the campaign lead. Retain those process-owned facts in their existing owners. Shared directory observation provides external invalidation and one coarse fallback. The generic observer has no auth-specific behavior. Auth-profile and secret changes are in stacked PR #170842; this PR has zero security-review-policy matches.

Database proof survives native-handle close. A newly admitted history lane checks physical identity before capturing its request receipt; warm lanes use retained facts. Captured receipts remain fixed through queued work. Receiver admission and privileged writes keep their current physical checks and post-await authority revalidation, rejecting swapped files even before watcher delivery.

Delete repeated request preparation and the duplicate Git discovery implementation. Simplify the registry reconciliation callback and workspace observer closure. No schema, protocol, durability, configuration-option or UI source changes.

Evidence

Candidate a7a8c725268aafc3b8f90bb7ef5264c2d6e3e7d1, based on main 27aef9ac6a0231b9fa494905a79361b30097fe67. Fresh independent review: no actionable P0–P2 findings.

Focused source-mode one-file tests (pnpm exec vitest run --config <owner> <file> --maxWorkers=1):

Owner Passed Wrapper / Vitest wall
Generic directory observation 4/4 15.33 / 8.60 s
Agent directory registry 6/6 66.91 / 60.96 s
Workspace Git display 1/1 15.51 / 6.08 s
Database validation, including stale authority and replacement 50/50 144.29 / 130.74 s

Synthetic fixture: six agents/workspaces, 120 auth profiles per agent, 300 sessions, 240 transcript messages and one widget, with plugins disabled. Main 27aef9ac6a02 and this exact candidate each completed 225 counted and 900 profiled RPCs with zero errors, using identical synthetic fixture paths.

Synchronous existence / stat / native-realpath API calls per RPC:

RPC Main PR A
talk.catalog 56 / 40 / 26 56 / 40 / 20
chat.startup 3 / 20 / 38 3 / 0 / 0
agents.list 38 / 0 / 13.07 2 / 0 / 0.8
models.authStatus, models.list 1 / 0 / 3 1 / 0 / 0
tools.catalog 0 / 0 / 1 0 / 0 / 0
board.get 0 / 7 / 4 0 / 5 / 2
Session list/subscribe/resolve/describe and config 0 / 0 / 0 0 / 0 / 0

Talk's remaining auth filesystem calls belong to PR B. Board admission and shared Gateway lease guards remain direct. Async log-file operations inheriting RPC traces are excluded from the owned-fact claim. No private captures or real state were used; both scratch Gateways shut down cleanly.

Main-thread samples are noisy on this loaded Mac; inclusive categories overlap. Total samples 4,261 → 2,586; filesystem 1,688 → 524; agent registry 342 → 5; SQLite identity 591 → 292; session-source preparation 391 → 4. CPU across threads 4,607 → 3,527 ms and burst wall time 3,454 → 2,998 ms do not establish an end-to-end reload improvement.

Exact-head CI run 38366281729 completed green: 63 jobs passed, 25 skipped, zero failures, including the Gateway/agents checks CI selected. AWS Crabbox cbx_045d3624cf3e uploaded source but refused hydration because it could not verify the Actions workspace Git root/origin; no test payload ran. That guard was preserved. CI resolved the broad-proof uncertainty, so remote setup was stopped.

Size and release context

Production delta +502 LOC: 568 additions / 66 deletions across 11 production/inventory paths, using the campaign's exclusion filter. Growth implements bounded retained projections, shared external invalidation and admission-time replacement checks. The superseded request-time paths and duplicate Git scan are removed.

Release-note context: reduce redundant Gateway filesystem work during Control UI boot without weakening database authority. No changelog edit. This PR is ready for review; the campaign lead lands it. Do not auto-merge.

@clawsweeper

clawsweeper Bot commented Oct 13, 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.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: a7a8c725268aafc3b8f90bb7ef5264c2d6e3e7d1

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 13, 2026
@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. labels Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR retains filesystem facts in Gateway owners and refreshes them through write publications and shared directory observations.

Example: A dashboard client requests talk.catalog with six synthetic agents and 120 auth profiles per agent.

  • Before: The reported request performs 56 synchronous existence checks, 40 stat calls, and 26 native realpath calls.
  • After: The reported request performs four existence checks and no stat or native realpath calls.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful measured performance work, but the destination migration defect remains and scoped cleanup introduces another correctness failure.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The full body supplies production Gateway RPC measurements in a synthetic six-agent environment with successful request waves and reduced filesystem calls; this supports the performance mechanism, while authority and lifecycle correctness remain subject to the listed findings.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Dashboard boot RPCs repeatedly perform filesystem discovery and identity work on the Gateway thread.
Reason: The maintainer-directed change targets measured work, uses existing owners, and adds no configuration or public API.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep this PR open: the measured performance improvement is useful, but destination migration admission and scoped teardown still have blocking defects.

Priority: P2
Reviewed head: 1bfcd0a20da38f507b012309ade1016c476ff43b

Before merge

  • Keep destination migration checks current at credential effects (P1) - After an empty SQLite owner caches absence of auth-profiles.json, restoring that file leaves this guard permissive until observation or the 30-second fallback runs. AuthStorage.withLock and updateAsync both consume this guard, so a credential write can populate the destination before migration is required; subsequent observation then treats the legacy file as warning-only because SQLite is populated. This prior finding remains unfixed. Adding refreshAuthProfileFileState to the destination-refusal test hides the original trigger. Keep cached presence for discovery, retain a direct source check at credential-write admission, and restore the negative control without pre-refreshing observations.
  • Scope observation cleanup to the closing state owner (P2) - closeOpenClawStateDatabaseByPathAsync passes the selected physical identity to every registered resource, but this callback ignores it and clears every auth directory. If root A has a prepared auth read while root B closes, A's capture subsequently throws 'Auth profile database file identity changed' despite its owner and file remaining valid. The new callback in session-utils-store-sources.ts has the same defect and retires A's pending history preparation. Retire only facts bound to the supplied closing identity, reserving global cleanup for an undefined identity, and cover one root closing while another retains a read.
  • Complete next step - Bring the expanded validation production and test files within their existing max-lines budgets, and classify the remaining failed CI checks against the base before requesting landing.

Findings

  • [P1] Keep destination migration checks current at credential effects — src/agents/auth-profiles/legacy-source-diagnostic.ts:341-343
  • [P2] Scope observation cleanup to the closing state owner — src/agents/auth-profiles/file-state.ts:41

Tests

  • Low-value test src/gateway/server-methods/models-auth-status.test.ts: The added refresh-order test asserts calls to mocked internal preparers rather than refreshed credential results; replace it with an RPC assertion or consolidate it with the credential-publication coverage.
  • Missing end-to-end proof: The supplied Gateway benchmark demonstrates performance, but the destination-refusal regression now refreshes observations first and no scoped-close regression keeps an unrelated root's read alive.
Agent review details

How this fits together

Gateway boot RPCs consume agent, auth, workspace, and session facts derived from filesystem paths and SQLite owners; committed writes and directory observations update those retained facts.

flowchart TD
A[Dashboard RPCs] --> B[Gateway readers]
B --> C[Retained owner facts]
C --> D[SQLite read workers]
E[Owner write publications] --> C
F[Directory observations] --> C
D --> G[RPC responses]
Loading

Technical review

Best possible solution:

Retain cached discovery while checking migration readiness at credential effects and retiring observations only for their closing owner.

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

Both findings have concrete source paths: restore a legacy file after cached absence before a credential write, or close root B while root A retains an auth reader or session-source preparation; no target code was executed.

Is this the best way to solve the issue?

Caching in existing owners fits the measured problem, and persisted-source separation addresses the earlier baseline concern; effect admission and scoped cleanup must preserve their existing contracts.

Full review comments:

  • [P1] Keep destination migration checks current at credential effects — src/agents/auth-profiles/legacy-source-diagnostic.ts:341-343
    After an empty SQLite owner caches absence of auth-profiles.json, restoring that file leaves this guard permissive until observation or the 30-second fallback runs. AuthStorage.withLock and updateAsync both consume this guard, so a credential write can populate the destination before migration is required; subsequent observation then treats the legacy file as warning-only because SQLite is populated. This prior finding remains unfixed. Adding refreshAuthProfileFileState to the destination-refusal test hides the original trigger. Keep cached presence for discovery, retain a direct source check at credential-write admission, and restore the negative control without pre-refreshing observations.
    Confidence: 0.99
  • [P2] Scope observation cleanup to the closing state owner — src/agents/auth-profiles/file-state.ts:41
    closeOpenClawStateDatabaseByPathAsync passes the selected physical identity to every registered resource, but this callback ignores it and clears every auth directory. If root A has a prepared auth read while root B closes, A's capture subsequently throws 'Auth profile database file identity changed' despite its owner and file remaining valid. The new callback in session-utils-store-sources.ts has the same defect and retires A's pending history preparation. Retire only facts bound to the supplied closing identity, reserving global cleanup for an undefined identity, and cover one root closing while another retains a read.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Legacy auth-source refusal changes intended behavior with a stated reason (19a98c8: The SQLite-only cutover deliberately rechecked retired credential filenames recreated by restores or older binaries.)
  • Persisted auth-row reuse changes intended behavior with a stated reason (d3d2d2e: Avoid repeated worker reads while preserving source provenance, publication invalidation, and revocable request authority.)
  • Database read-validation capture changes intended behavior with a stated reason (ad3c930: Carry physical database identity into worker reads without allowing replacement files to borrow prior validation.)
  • Registered agent-directory identity keeps the original intent (0427564: Preserve custom-directory ownership and remove only membership added by a request.)
  • Workspace Git discovery changes intended behavior with a stated reason (b4b1984: Keep managed-worktree eligibility consistent between agent presentation and session creation.)
  • Session-source preparation keeps the original intent (3ed79ce: Capture routing once while retaining final physical-target and reader authority.)
  • Pending-input history reads keeps the original intent (84af472: Move bounded history reads to workers while retaining captured storage identity and write custody.)
  • Auth committed-state publication keeps the original intent (381b1e0: Publish canonical committed auth facts incrementally without main-thread SQLite rereads.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +1235, Tests +1424, Other +2. Total +2661 across 48 files. Added test files: 6.

View PR surface stats
Area Files Added Removed Net
Source 21 1342 107 +1235
Tests 26 1479 55 +1424
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 48 2823 162 +2661

Review metrics

Metric Value Why it matters
Production versus test growth Production net +1,237 lines; tests net +1,424 lines. Growth implements retained observations, publication, and lifecycle coverage; the measured hot-path savings support the scope, but the owner-boundary findings remain.

Labels

Label changes:

  • add P2: This is a measured Gateway performance improvement with normal maintenance priority; the introduced findings separately block merge.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • remove P1: Current review triage priority is P2, so this older priority label is no longer current.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This is a measured Gateway performance improvement with normal maintenance priority; the introduced findings separately block merge.
  • merge-risk: 🚨 auth-provider: Cached legacy-source absence can admit a credential write into a destination that requires migration.
  • merge-risk: 🚨 availability: Closing an unrelated state database invalidates active auth and session-read preparation.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-13T01:01:27.399Z sha 956b67a286420b06a948fb633535f87e464145cb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-13T02:32:53.347Z sha 102a035b7b7d9b58fd489ce16322de6903478651 :: blocked before merge. :: [P1] Keep destination migration checks current at credential effects | [P1] Establish a row baseline before treating observation as an auth change

Reviewed October 12, 2026, 11:52 PM ET / October 13, 2026, 03:52 UTC (Revision 3).

@steipete
steipete force-pushed the steipete/coldload-gateway-boot-fs-work branch from 956b67a to 102a035 Compare October 13, 2026 02:23
@steipete steipete changed the title perf(gateway): reduce filesystem work during client boot perf(gateway): retain boot filesystem facts in their owners Oct 13, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL and removed size: S labels Oct 13, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. 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 Oct 13, 2026
@steipete
steipete force-pushed the steipete/coldload-gateway-boot-fs-work branch from 102a035 to 1bfcd0a Compare October 13, 2026 03:42
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 13, 2026
@steipete
steipete force-pushed the steipete/coldload-gateway-boot-fs-work branch from 1bfcd0a to 97fb85f Compare October 13, 2026 04:25
@steipete
steipete force-pushed the steipete/coldload-gateway-boot-fs-work branch 3 times, most recently from a095ea4 to 510ac80 Compare October 13, 2026 07:12
@steipete
steipete force-pushed the steipete/coldload-gateway-boot-fs-work branch from 510ac80 to a7a8c72 Compare October 13, 2026 07:59
@steipete steipete changed the title perf(gateway): retain process-owned boot filesystem facts perf(gateway): retain agent and session boot filesystem facts Oct 13, 2026
@steipete
steipete merged commit 3ac0c05 into main Oct 13, 2026
164 of 165 checks passed
@steipete
steipete deleted the steipete/coldload-gateway-boot-fs-work branch October 13, 2026 10:00
steipete added a commit that referenced this pull request Oct 13, 2026
#170467 (3ac0c05) intentionally retains agent directory observations
with one coarse fallback. The utility-only browser handoff first registers
that observer while fake timers are active, so runAllTimersAsync drains
its recurring maintenance interval until the 10000-timer guard aborts.

Fake only Date and timeout methods used by handoff polling. Keep every
custodian route, bootstrap, presence, deadline, and failure assertion;
production preparation, directory maintenance, and onboarding are unchanged.

Proof: before 1/15 fails with the hourly timer error; after 27/27 handoff
and sibling cases pass (17.75s wrapper). Commands types, targeted lint,
boundary guards, formatting, and independent P2 review pass. The tsdown
js-extension regression also passes on main containing 18e4969.
steipete added a commit that referenced this pull request Oct 13, 2026
PR #170826 intentionally permits captured or fallback pricing to survive
plugin cache retirement until the next config or restart. Assert every log
record and its estimated cost on that path; retain the typed rejection when
the database admission is revoked.

PR #170467 introduced process-owned directory observation with a shared
30-second fallback interval. Prepare agent directory facts before the
fixture installs its refresh clock. Keep every zero-timer, backoff, scope
drain and cancellation assertion.

Before: two failures across these files on main. After: all 14 cases pass
through pnpm test with --maxWorkers=1 (29.89s wrapper, 15.74s Vitest).
Targeted infra test types, typed and boundary lint, formatting, and
independent review through P2 pass. Production behavior is unchanged.
steipete added a commit that referenced this pull request Oct 13, 2026
…170842)

Second half of the Gateway process-owned file state work (first half #170467): auth-profile file identity, persisted rows, runtime snapshots and secrets facts are held by their owners, updated write-through, and invalidated by directory observation for external writers (CLI, Doctor, manual edits). Readers capture the database file identity; assertCurrent() rejects stale authority when the observed identity changed. Per-request fs calls: talk.catalog 56/40/26 -> 4/0/0 existence/stat/realpath (with #170467).

Security review: Peter (admin and SecOps) signed off 2026-10-13. Admin-merged over the inherited server.config-patch agents.create 10 s timeout, which reproduces on the exact main base under CI's two-CPU budget (main 66/67, head 67/67; evidence in the PR body).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
openclaw#170467 (d2aac29) intentionally retains agent directory observations
with one coarse fallback. The utility-only browser handoff first registers
that observer while fake timers are active, so runAllTimersAsync drains
its recurring maintenance interval until the 10000-timer guard aborts.

Fake only Date and timeout methods used by handoff polling. Keep every
custodian route, bootstrap, presence, deadline, and failure assertion;
production preparation, directory maintenance, and onboarding are unchanged.

Proof: before 1/15 fails with the hourly timer error; after 27/27 handoff
and sibling cases pass (17.75s wrapper). Commands types, targeted lint,
boundary guards, formatting, and independent P2 review pass. The tsdown
js-extension regression also passes on main containing ab0bbfc.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
PR openclaw#170826 intentionally permits captured or fallback pricing to survive
plugin cache retirement until the next config or restart. Assert every log
record and its estimated cost on that path; retain the typed rejection when
the database admission is revoked.

PR openclaw#170467 introduced process-owned directory observation with a shared
30-second fallback interval. Prepare agent directory facts before the
fixture installs its refresh clock. Keep every zero-timer, backoff, scope
drain and cancellation assertion.

Before: two failures across these files on main. After: all 14 cases pass
through pnpm test with --maxWorkers=1 (29.89s wrapper, 15.74s Vitest).
Targeted infra test types, typed and boundary lint, formatting, and
independent review through P2 pass. Production behavior is unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…penclaw#170842)

Second half of the Gateway process-owned file state work (first half openclaw#170467): auth-profile file identity, persisted rows, runtime snapshots and secrets facts are held by their owners, updated write-through, and invalidated by directory observation for external writers (CLI, Doctor, manual edits). Readers capture the database file identity; assertCurrent() rejects stale authority when the observed identity changed. Per-request fs calls: talk.catalog 56/40/26 -> 4/0/0 existence/stat/realpath (with openclaw#170467).

Security review: Peter (admin and SecOps) signed off 2026-10-13. Admin-merged over the inherited server.config-patch agents.create 10 s timeout, which reproduces on the exact main base under CI's two-CPU budget (main 66/67, head 67/67; evidence in the PR body).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts 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