Skip to content

perf(auth): reduce allocations from unrelated file watcher events - #186370

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-fs-watcher-churn-20260919
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-fs-watcher-churn-20260919

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Auth-file observation allocates a temporary database-key array and predicate for every unrelated directory rename, including SQLite sidecars that it immediately ignores. This is residual work after #183348, #183818, and #184250; all three were ancestors of the profiled build.

User Impact

Lower allocation during directory event churn, with no change to watched paths, notification timing, credential identity checks, or configuration. Native filesystem event counts are unchanged.

Why This Change Was Made

Iterate the existing identity map directly and return at the first exact basename match. Undefined names and legacy auth names retain their refresh path. No cache, invalidation policy, exclusion list, or public API is added. Production delta is +3 lines: the explicit loop removes the temporary snapshot and per-event predicate while preserving matching and early return. Test-line delta is zero.

Evidence

Five interleaved base/candidate pairs, each replaying 256,000 unrelated rename events through 64 real auth owners and the directory-observer callback composition, with one retained database per directory. Native handles are mocked; allocation sampling and untraced CPU/GC runs are separate. Base: d7acde6ae97e3e95c3ce4b07fb86cd6eb92db7fb.

Owner workload metric Base mean Candidate mean Change
Sampled owner bytes/event 249.85 64.42 −74.2%
Total sampled bytes/event 273.32 85.93 −68.6%
Untraced CPU / 256k events 104.09 ms 84.80 ms −18.5%
Untraced GC / 256k events 0.526 ms 0 ms −0.526 ms
Auth publications for irrelevant events 0 0 unchanged

The benchmark's --allocations --max-owner-bytes-per-event 100 regression assertion fails on all five base runs and passes on all five candidate runs. Candidate owner samples span 57.38–72.23 B/event; base spans 242.73–256.56. The semantic test also passes on base; the allocation assertion is the red/green proof. A four-identity sensitivity run before mocking native handle setup measured 383.78→161.75 owner B/event.

CPU host one-minute load was 25.9–31.1 (base) and 25.9–30.2 (candidate); a build was concurrently active. The paired CPU deltas were −11.52, −69.45, −7.91, +0.19, and −7.75 ms. Only two minor collections occurred per baseline run; no candidate or major collections occurred in these short windows. Baseline max GC pauses were 0.222/0.360/0.272/0.284/0.271 ms; candidate had none. Loop tails have only 112–386 samples/run and are context only. RSS/heap at the end of these short, non-normalized GC windows averaged 263.0/54.5 MiB base versus 276.1/59.4 MiB candidate; this is not retained-heap proof.

Reproduce the owner workload with:

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/auth-file-watch-events-measure.ts --state-dir <new-dir> --allocations --max-owner-bytes-per-event 100
# Use --owner <frozen-file-state.ts> for baseline, retaining its relative imports.
# Omit --allocations and the threshold for CPU/GC runs; --identities 4 tests multiple databases.

Focused proof: auth file-state, worker, and owned-directory observation tests (27 passed); the final zero-growth test consolidation also passed (14 tests). Build passed (5m16s); changed-file lint/format passed. Export collision guard and both source-closure test files passed (32 tests). Test-line ceiling is inherited over budget; no baseline was changed and this diff adds zero test lines.

Independent subagent review (autoreview route unavailable): fresh context, complete diff and relevant owners, P2+ scoped clean. Autoreview itself refused the provider route because it did not match the operator configuration; no configuration was changed. The test-only consolidation preserves the reviewed branches.

The explicitly requested fast-path proof is used for this semantics-preserving owner allocation deletion. A bounded isolated Gateway watcher census is recorded below; no ten-minute A/B whole-Gateway performance claim is made. Native onchange allocation remains outside this fix.

The candidate-only, two-minute canonical-harness census used the built Gateway, 10,800 sessions, 40 plugins, 65 clients, mock turns/tools/native subagents and worktree churn. A synthetic 5,000-write/delete burst of an unrelated watcher-probe.sqlite-journal file in the observed agent directory delivered 235 rename notifications over the 15.007-second counter interval (940 events/min). These were the only watcher events during that interval; no recursive workspace watcher was implicated. Native event delivery rate is unchanged by this patch and was not measured in a separate base Gateway. The much higher production event incidence was not reproduced on macOS; the owner callback cost is established by the replay above.

Candidate census context (not an A/B performance gate): main-thread CPU 10.79%, GC 0.227 s/min, event-loop p99 32.70 ms (5,604 samples), client sessions.list p99 106.26 ms and server handler p99 48.64 ms (265 samples each; below the p99 gating threshold), RSS 2,114 MiB, main heap 526.8 MiB. Eight mock turns completed with eight tool calls/results and twenty committed writes. Allocation rate was not sampled in this timing-only census.

The census ended at host load averages 15.02/20.60/19.67 (1/5/15 minutes). Measurements used the pre-rebase build; the final branch was rebased onto caf3034ae081 with the authored patch unchanged.

Iterate the existing identity map when filtering unrelated file renames. Preserve replacement and legacy-source invalidation without allocating a key snapshot and predicate per event.\n\nOwner replay allocation falls from 249.9 to 64.4 bytes/event across five interleaved pairs; native watcher policy is unchanged.
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 22:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T22:51:55.156511Z 4885be2 Draft marked ready
ℹ️ 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.

@github-actions

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: 4885be2d50e780868b80cd6434f84016e70b6234
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/file-state.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. 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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces a temporary database-key array and predicate with direct map iteration when filtering auth-directory events.

Example: A rename event arrives for openclaw-agent.sqlite-wal.

  • Before: The auth observer allocates a database-key array and predicate before ignoring the event.
  • After: The auth observer checks the existing map directly and ignores the event.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-verified optimization with credible owner-level measurements; comparative performance evidence remains confined to callback replay.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored allocation deletion is outside the ordinary contributor proof gate; its reported owner replay measures the changed callback composition, while the isolated Gateway census establishes native event delivery without claiming an A/B performance result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Busy auth directories generate irrelevant filesystem notifications that create avoidable garbage.
Reason: The maintainer-authored direction removes measured waste without adding configuration, state, APIs, or another decision owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it removes measured allocation waste with a small, behavior-preserving change, and no actionable defect was found.

Priority: P2
Reviewed head: 4885be2d50e780868b80cd6434f84016e70b6234

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The allocation comparison uses callback replay with mocked native handles; the reported native Gateway census is candidate-only and does not establish a Gateway-wide allocation improvement.
Agent review details

How this fits together

Native directory events pass through the shared directory observer to the auth file-state owner, which filters irrelevant names and refreshes identity or legacy-source facts for relevant notifications.

flowchart LR
  A[Native directory event] --> B[Directory watch adapter]
  B --> C[Shared directory observer]
  C --> D[Auth filename filter]
  D --> E[Identity and source refresh]
  E --> F[Auth snapshot invalidation]
Loading

Technical review

Best possible solution:

Retain the direct iteration in the existing auth owner and land through the normal CI gate.

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

Current main visibly expands the identity-map keys and creates a predicate for unrelated rename events; reported replay measurements quantify that cost, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

Direct iteration is the smallest complete fix: it deletes temporary work at the existing owner while preserving matching, refresh scheduling, and identity checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Auth directory filename filtering keeps the original intent (716d395: The prior private-helper cleanup retained immediate native events and the existing recovery fallback; the current change preserves both.)
  • Content-event filtering and semantic coverage keeps the original intent (99dd80d: Avoid identity refreshes for named content changes while retaining replacement, deletion, nameless-event, and recovery detection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced change preserves filtering: The pinned introduced diff replaces array expansion and some with direct iteration; named content events, legacy names, nameless notifications, and exact database-basename matches retain their existing outcomes. (src/agents/auth-profiles/file-state.ts:185, 4885be2d50e7)
  • Current main still contains the allocation: Fetched main retains the temporary key-array expansion, so the optimization remains distinct work. (src/agents/auth-profiles/file-state.ts:192, 0a6415bed1d7)
  • Performance evidence has explicit scope: The PR reports five interleaved replay pairs with owner allocation falling from 249.85 to 64.42 bytes/event and unchanged zero publications for irrelevant events; it explicitly separates mocked native handles from its candidate-only Gateway census. (scripts/perf/auth-file-watch-events-measure.ts:93, 4885be2d50e7)
  • Retained semantic coverage: The existing test now exercises sidecar rename events while retaining database replacement and nameless-deletion invalidation checks; the PR correctly states that this semantic test also passes on the base. (src/agents/auth-profiles/file-state.test.ts:215, 4885be2d50e7)
  • Feature history and original intent: Available history repeatedly identifies Peter Steinberger across auth-file ownership, lifecycle repairs, and event filtering; the merged content-event optimization preserves replacement and recovery detection. Local history traversal reached unavailable older blobs, so file-creation provenance is not asserted. (src/agents/auth-profiles/file-state.ts:186, 99dd80d614bd)
  • Maintainer authority and current checks: The security guard confirms maintainer authority and explicitly requires no additional SecOps approval for this head; the aggregate CI status remains pending and GitHub reports the PR mergeable. (4885be2d50e7)

Likely related people:

  • Peter Steinberger: Raw commit 99dd80d adds src/agents/auth-profiles/file-state.ts:186 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 99dd80d614bd; files: src/agents/auth-profiles/file-state.ts)

PR surface

Source +3, Tests 0, Other +239. Total +242 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 5 +3
Tests 1 2 2 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 239 0 +239
Total 3 249 7 +242

Labels

Label changes:

  • add P2: A measured allocation reduction benefits directory-event churn with limited behavioral scope.
  • 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.

Label justifications:

  • P2: A measured allocation reduction benefits directory-event churn with limited behavioral scope.
  • 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.

Reviewed October 27, 2026, 7:06 PM ET / 23:06 UTC.

@steipete
steipete merged commit eec15d7 into main Oct 27, 2026
211 of 218 checks passed
@steipete
steipete deleted the steipete/perf-micro-fs-watcher-churn-20260919 branch October 27, 2026 23:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…claw#186370)

Iterate the existing identity map when filtering unrelated file renames. Preserve replacement and legacy-source invalidation without allocating a key snapshot and predicate per event.\n\nOwner replay allocation falls from 249.9 to 64.4 bytes/event across five interleaved pairs; native watcher policy is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: M 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