Skip to content

fix(gateway): avoid filesystem stalls during catalog refresh - #200136

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-main-thread-sync-lock-create-20260919
Nov 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-main-thread-sync-lock-create-20260919

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway event-loop stalls when a filesystem transaction delays the catalog refresh sidecar lock or audited runtime metadata operations.

Production evidence: Team 25c97908, 2026-11-16 05:02 PST, showed the Gateway main thread in D-state for 1.97 seconds inside openat2(O_CREAT) for openclaw-agent.sqlite.plugin-model-catalog.lock. The kernel stack was btrfs_create → start_transaction → wait_current_trans; scheduler:update.remote-model-catalog recorded a 2,002 ms event-loop stall while worktree removals drove a btrfs commit.

User Impact

Catalog publication no longer creates that sidecar lock on the Gateway thread. Audited config, OpenClaw ID, installer, skill, cron and session-artifact paths use async filesystem operations or consume existing owner facts. Prompt reduction preserves disclosed output paths without probing temporary files; a later read reports an expired artifact.

This is a bounded repair stage, not a claim that every Gateway path is sync-free. General fs-safe locks, source-capture custody, timeline durability and managed update handoff require separate owner work. No schema, configuration or dependency change is included.

Why This Change Was Made

The catalog's async file-lock wrapper reached synchronous native filesystem operations. Its sidecar duplicated canonical database writer custody. Publications now use that existing writer; credential cleanup queues its candidate read behind earlier publications, then releases the read barrier before entering individual writers. Later publications retain transactional auth revalidation. Outside writers require exclusive offline custody.

The accompanying audit converts direct runtime metadata calls, preserves async key creation and launch/stop ordering, deletes redundant existence probes, and reuses async catalog identity and inspection-budget readers. Config startup also reuses its existing fingerprint instead of computing it again. Production delta: −9 lines; guards and reproducible proof tooling are separate.

Evidence

The synthetic fixture contains a 35.06 GiB agent database, 5,000 sessions and 62,000 workspace files totaling 1.10 GB. No production data was copied. Five interleaved baseline/candidate pairs and A/A controls used Node 26.12.1 on APFS. The fault targets the actual native catalog openBeneath(O_CREAT) call; this is fault-injection evidence, not a btrfs kernel reproduction.

Median measurement Parent Candidate
Publication, 2,000 ms create fault 2,016.48 ms 4.83 ms
Maximum heartbeat gap, fault armed 2,012.03 ms 1.82 ms
Publication, no fault 4.963 ms 4.219 ms
Main-thread CPU, no fault 2.986 ms 2.307 ms
Sync Node FS calls / native catalog creates 20 / 1 0 / 0

Every process verified committed catalogs through a fresh reader. Allocation medians were 4.31 MB → 3.44 MB, but A/A variation was too large to claim a precise gain. An initial +0.37 ms undelayed heartbeat difference did not reproduce in a bounded 20-sample-per-arm followup; both series and CPU profiles are retained. Reproducer: scripts/perf/catalog-publication-measure.mjs.

Focused proof passed: 39 catalog tests, 47 model/prompt-prefix tests, 84 session/spill tests, 32 skill-install tests, 62 OpenClaw ID tests, and the audit batches of 58, 96 and 349 tests. The final reloader simplification passed all 146 reloader tests. Twenty existing native-iroh tests were skipped because that addon is unavailable locally. Regression guards fail on the exact parent for catalog publication, spill probes and the other reproduced mutation paths.

Codex local autoreview is scoped-clean through P2 for the main change against parent 6670297776a00 and the subsequent four-file CI repair at 225aaebe7329c. pnpm check:changed and the scoped repair rerun pass the applicable type, lint, format and boundary checks except two proven parent dead-export failures: ProjectedContinuationSource and partContinuation. A clean exact-parent run reproduces both; their exports were introduced by 24385a20428a3 / #200056. These are recorded main regressions, not ignored noise. No guard baseline was changed.

Initial CI at dc75193ca69fd found stale synchronous fault hooks in three peer-link consumer suites and unregistered benchmark lint suppressions. The repair preserves all authority assertions, passes all seven affected cases under pinned Bun and all 14 suppression-guard tests, and replaces global module-loader interception with the native addon selected by fs-safe. A repeated native smoke still observes one delayed baseline create versus zero candidate creates. pnpm check:changed --base dc75193ca69fd passes its applicable gates except the same two attributed parent dead exports.

Exact-head CI and hosted ClawSweeper review are required before landing. No open ClawSweeper checklist item will be bypassed.

Delete redundant catalog sidecar locking and order credential candidate reads through canonical writer admission. Move audited config, identity, installer, skill and session metadata operations to asynchronous filesystem APIs while preserving their ownership and settlement rules.

Extend the existing main-thread filesystem guards and add a production-shaped synthetic catalog benchmark with native lock-create fault injection. Preserve disclosed spill paths during prompt projection without probing temporary files.
@clawsweeper

clawsweeper Bot commented Nov 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T15:06:29.928315Z 225aaeb 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 225aaebe7329cccbb76363ff8f72e231cefc4890
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/plugin-model-catalog-credentials.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes catalog sidecar locking and converts audited runtime filesystem operations to asynchronous APIs.

Example: Catalog publication encounters an injected 2,000 ms native lock-create delay.

  • Before: The reported median publication takes 2,016.48 ms, with a 2,012.03 ms maximum heartbeat gap.
  • After: The reported median publication takes 4.83 ms, with a 1.82 ms maximum heartbeat gap and no catalog lock creation.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair is coherent and both earlier blockers are fixed; proof is strongest at the production-owner boundary, while broad exact-head CI remains pending.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied interleaved native fault-injection measurements exercise the real catalog publication owner and worker transport under Gateway custody, verify persisted results through a fresh reader, and report zero candidate lock creates; their scope excludes a whole-Gateway or btrfs kernel reproduction.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Filesystem pressure during catalog refresh can pause the Gateway event loop and delay unrelated work.
Reason: The maintainer-authorized direction addresses a recorded production stall with measured improvement and reuses existing ownership rather than adding another runtime subsystem.

Merge readiness

✅ Ready for maintainer review

Both earlier findings are resolved, and no new actionable code or security defect was found. This maintainer-authored PR remains useful; exact-head CI is still pending.

Priority: P2
Reviewed head: 225aaebe7329cccbb76363ff8f72e231cefc4890

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway catalog refresh publishes provider models through the agent database worker; credential cleanup joins the same writer queues before inspecting persisted catalogs.

flowchart TD
  A[Catalog refresh] --> B[Agent writer admission]
  C[Credential removal] --> D[Ordered candidate inspection]
  D --> B
  B --> E[Catalog worker transaction]
  E --> F[Persisted model catalogs]
  F --> G[Model registry readers]
Loading

Technical review

Best possible solution:

Use the existing database writer admission for catalog ordering and asynchronous filesystem APIs for the audited metadata operations.

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

Current-main source retains the implicated lock path, and the supplied native fault-injection results reproduce its event-loop stall; no target code was executed during this review.

Is this the best way to solve the issue?

Removing redundant locking at the existing writer owner addresses the cause while preserving credential cleanup ordering, and the accompanying asynchronous conversions retain their existing owners and contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Catalog publication and credential cleanup ordering changes intended behavior with a stated reason (fc17c21: Publication and cleanup shared filesystem locks so cleanup could not skip credentials hidden in an earlier uncommitted publication.)
  • Persisted catalog reads keeps the original intent (93625aa: Move SQLite reads off the Gateway thread while retaining read authority, physical identity checks, cancellation, and worker settlement.)
  • Config journal fingerprints and immutable-update inspection keeps the original intent (3af3493: Persist only per-install keyed fingerprints for config-change comparison; immutable inspection subsequently required reading existing keys without creating or hardening them.)
  • OpenClaw ID key loading and promotion keeps the original intent (37a3b16: A linked claw must use the key named by its binding, promote a matching staged key, and refuse missing or mismatched keys without minting replacements.)
  • Peer-link fault and revocation hooks keeps the original intent (b09f4a0: Default-object builtin calls keep fault and revocation hooks observable on Bun; the asynchronous replacement retains that access pattern and updates affected consumers.)
  • Installer rollback keeps the original intent (d1b9f90: Restore missing package entries after interrupted replacement while preserving held files, directory identity, retained backups, and recovery authority.)
  • Disclosed spill-output pointers changes intended behavior with a stated reason (53b53f1: The previous projection avoided pointing at deleted spill files; the PR explicitly documents preserving disclosed paths and reporting expiry when subsequently read.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason O'Neal: Raw commit e0d16ec adds src/agents/plugin-model-catalog-execution.ts:54 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e0d16ecdd581; files: src/agents/plugin-model-catalog-execution.ts)

PR surface

Source -9, Tests +170, Docs +10, Other +314. Total +485 across 59 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 29 294 303 -9
Tests 27 289 119 +170
Docs 2 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 314 0 +314
Total 59 907 422 +485

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +294/-303; tests +289/-119 Production shrinks by nine lines; test growth extends existing filesystem work-count, persistence, ordering, and lifecycle coverage.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Reported filesystem pressure causes transient Gateway-wide pauses, with a focused repair and measured owner-level improvement.
  • 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.
  • 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 (1 earlier review cycle)
  • reviewed 2026-11-16T14:50:50.426Z sha dc75193 :: needs changes before merge. :: [P2] Update peer-link consumer fixtures to intercept asynchronous effects | [P2] Resolve the benchmark's unregistered lint suppressions

Reviewed November 16, 2026, 10:15 AM ET / 15:15 UTC (Revision 2).

Migrate peer-link revocation and effect-admission fixtures to fs.promises while preserving authority assertions. Intercept the native addon selected by fs-safe in the catalog benchmark instead of the global module loader.
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations labels Nov 16, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed both open items at 225aaebe7329cccbb76363ff8f72e231cefc4890:

  1. Peer-link consumer fixtures: the Doctor revocation hook and effect observers, updater hook, and CLI hook now intercept the actual promise-based operations. Revocation occurs after the real unlink; effect observation occurs at submission. Existing refusal, admission-order, and filesystem-result assertions remain unchanged. All seven previously failing cases pass under pinned Bun.
  2. Benchmark suppressions: removed all three suppressions and the global module-loader patch. The benchmark uses fs-safe's selected native package, wraps its actual openBeneath, and restores it. Scoped lint and all 14 suppression-guard cases pass without an allowlist change. Native smoke still catches one delayed baseline lock create and zero candidate creates.

A fresh scoped Codex autoreview is clean through P2. The changed-file check passes its applicable gates except the two previously documented exact-parent dead exports introduced by #200056. New-head CI remains required.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@steipete
steipete enabled auto-merge (squash) November 16, 2026 15:29
@steipete
steipete merged commit 59d9759 into main Nov 16, 2026
167 of 169 checks passed
@steipete
steipete deleted the steipete/perf-micro-main-thread-sync-lock-create-20260919 branch November 16, 2026 15:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

vincentkoc added a commit that referenced this pull request Nov 16, 2026
…tgres-compaction-watched-prompt-20261116

* commit '9e810f7101557b006d5ff223d955f14dc43329f0': (23 commits)
  chore(ui): refresh control ui locales (#200164)
  fix(update): stop reporting unset git config keys as failing checks (#200153)
  test: consolidate redundant coverage (198793, part 2) (#198936)
  revert: skills-used full-transcript scan on every chat history page (#200159)
  refactor(sessions): follow the chat by key for stored delivery references (#200099)
  fix(update): bridge 2026.11.5-beta.4 updaters (#200152)
  fix(gateway): avoid filesystem stalls during catalog refresh (#200136)
  fix(ci): match update refusal probe to selected candidate (#200043)
  fix(agents): keep read-only steering carriers when publishing suppressed user envelopes (#200156)
  test: consolidate suites while retaining recovery owners (#198933)
  test: consolidate redundant coverage (198789, part 2) (#198932)
  refactor(cli): consolidate camera command tests (#200144)
  fix(cli): avoid initializing provider runtime during cleanup (#200139)
  fix(ui): show mobile destinations without the drawer exit delay (#198879)
  chore(ui): refresh control ui locales (#200146)
  fix(knowledge): keep historical claims distinct and reject changed retries (#200140)
  fix(ui): align dropdown arrows on mobile New Session
  improve(sessions): archive inactive transcripts by default (#199899)
  refactor(agents): own background commands and yield waits by the chat (#200097)
  fix(models): guessed non-chat models leave the default picker instead of being refused (#200102)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…w#200136)

* fix(gateway): avoid filesystem stalls during catalog refresh

Delete redundant catalog sidecar locking and order credential candidate reads through canonical writer admission. Move audited config, identity, installer, skill and session metadata operations to asynchronous filesystem APIs while preserving their ownership and settlement rules.

Extend the existing main-thread filesystem guards and add a production-shaped synthetic catalog benchmark with native lock-create fault injection. Preserve disclosed spill paths during prompt projection without probing temporary files.

* test(gateway): observe asynchronous metadata effects

Migrate peer-link revocation and effect-admission fixtures to fs.promises while preserving authority assertions. Intercept the native addon selected by fs-safe in the catalog benchmark instead of the global module loader.
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Partial adaptation of 59d9759 (#200136).
Move applicable catalog and filesystem preparation into existing owners,
retaining current authority checks and immutable update inspection.

INCOMPLETE: catalog zero-synchronous-I/O proof still fails at existing native
execution/admission descriptor checks. Session path containment
also retains synchronous predecessor owner operations. Do not
treat this local draft as a completed release pick or publish it without
resolving the recorded gaps in remaining-pass-results.json.

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Continue #200136 on the release base with bounded async filesystem preparation and the existing containment policy. Preserve candidate ordering, cross-root fallback, and symlink revalidation. The existing zero-synchronous-I/O usage regression is now green; catalog admission remains incomplete.

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
… reads

Adapt #200136 through existing execution, writer, descriptor and clean-close seal owners. Preserve native identity fencing, live creation authority and synchronous service settlement.

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Follow up the release adaptations of #200136 (59d9759), #200192 (9323fb9), and #200222 (3f33eb9). Preserve validated worker fields across asynchronous admission; restore required imports, await diagnostics, and normalize the nullable path adapter.

Parent review complete. Doctor regression failed before the repair; 17 parent tests across Doctor and attachment boundaries pass afterward. Seven-file scoped typed lint, format and whitespace checks pass. Worker session-path suite: 9 passed. Full release qualification remains pending.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: XL 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