Skip to content

fix: keep cold credential reads responsive on slow filesystems - #200192

Merged
steipete merged 3 commits into
mainfrom
steipete/lane2535-auth-reader
Nov 16, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/lane2535-auth-reader

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #200136

What Problem This Solves

Fixes: cold credential reads can block Gateway requests on synchronous database identity and inspection-budget filesystem probes before reaching the read worker.

User Impact

Credential reads remain responsive while filesystem metadata is slow. The existing worker still validates the complete captured file identity before opening the database and transferring credentials. Runtime retirement and same-root usage ordering remain enforced. No configuration, schema, durability, or dependency changes.

Why This Change Was Made

The Team 25c9790 incident on 2026-11-16 at 05:02 PST exposed a 1.97 s main-thread btrfs transaction wait in catalog lock creation and a 2,002 ms event-loop stall. #200136 deleted that redundant lock. This follow-up repairs the cold credential-read boundary uncovered by the same audit.

The existing async identity owner now prepares the reader's physical file facts; the existing SQLite worker owns complete key/birthtime validation. Redundant host probes and reverse lookups of already-known agent identities are deleted. All internal reader-factory callers await preparation. Unresolved agent discovery participates in the existing read-resource lifetime before yielding, so retirement cannot deliver credentials or admit fresh file/cache state. Usage requests reserve the existing preparation queue before async work, preserving ordering.

Inspection budget preparation also becomes async in the existing session and one-shot read owners. Captured runtime context and accepted-work settlement survive that await. Production grows by 37 lines across 22 modules: async discovery and resource lifetime replace duplicate checks. No new cache, queue, protocol, or authority owner.

Evidence

Final focused proof passes 78 tests across eight files, including actual credential reads, candidate stores, source checks, usage admission, and the broker consumer. Additional OAuth settlement/concurrency proof passes 22 cases. A real read-child regression rejects a wrong captured birthtime that the parent incorrectly accepted. Cold registry-retirement and post-retirement admission regressions fail before their repairs and pass afterward. Existing main-thread FS observation verifies the cold read flow.

The canonical check:changed entry point (node scripts/check-changed.mjs --base HEAD) completed. Task-owned mock/type findings were repaired; final touched core/services/agents type graphs, lint, format, and diff checks pass. Structural SQLite worker, import, schema, and line gates passed. Unchanged dead exports reproduce on exact parent 6670297 and originate in 24385a2 / #200056: a confirmed main regression, not a baseline waiver. The whole check command is not claimed green.

Three isolated Codex passes completed. One P2 was rejected after checking both production callers: usage admission occurs before entering the reservation owner, and its unconditional cleanup releases the reservation. The other passes had no findings; no accepted/actionable findings remain.

Twenty serialized fresh Node 26.12.1 processes exercised a real synthetic 37,641,338,880-byte database containing 5,000 session rows and one synthetic auth row. Each sample verifies returned credentials and disposal. Four identical-baseline controls, four zero-delay A/B pairs, and four A/B pairs with one injected 2,000 ms target metadata delay all completed. No Team data was used. The surrounding 62,000-file workspace is not scanned by this owner.

Median Before After
No-delay owner time 4.758 ms 4.724 ms
No-delay main-thread CPU 1.968 ms 1.943 ms
No-delay parent-process CPU 8.344 ms 7.868 ms
No-delay main-isolate allocation 868,468 bytes 630,268 bytes
Delayed owner time 2,014.252 ms 2,008.244 ms
Delayed maximum heartbeat gap 2,010.365 ms 8.814 ms
Scoped synchronous metadata calls 7 0

Candidate delayed heartbeat maximum across all four samples was 15.553 ms. A/A owner median was 4.288 ms, range 3.746–5.951; main CPU 1.876 ms. No-delay latency/CPU differences are within process spread. Allocation controls varied substantially, so the lower candidate allocation median is not claimed as an improvement. During the injected delay, the responsive candidate executes heartbeat/runtime timers for two seconds while baseline blocks them: its measured CPU/allocation includes that extra instrumentation work and does not isolate owner overhead.

These are APFS fault-injection measurements, not direct btrfs measurements. Each measured target has cold application identity/file-state/row-cache admission and an explicit known agent ID; a separate clone warms module/read-worker startup. OS page cache and unknown-directory discovery are not claimed cold. Parent CPU excludes the spawned SQLite child's CPU.

Two earlier native-staging cancellation cases exceeded their original 10 s deadlines. Exact-parent isolated replays passed; a diagnostic replay of the same three files passed 56/56 without changing barriers or deadlines. That does not establish their cause, a fix, or inheritance. Diagnostic-only edits are excluded, and the uncertainty remains for exact-head CI.

Diagnostic/legacy source reads, unknown-directory generic writes, source cohort comparison, and secrets activation/rollback remain separate audited boundaries. No global zero-sync claim. Changed modules have no runtime Control UI import; no Node import was added to a browser-facing module.

Initial CI 43921173131 found a missing consumer migration in the auth-watch benchmark added by #186370 after this lane's base. Main was integrated for this named type failure; fixture setup now awaits the async identity owner before its unchanged assertion. Scripts types, targeted lint/format, and fresh Codex review pass. No production change or compatibility alias was added.

The actual small benchmark smoke separately fails with zero intercepted watch callbacks instead of 64. That identical failure reproduces on exact CI main parent 4a74c61. #197445 / 36afa92 moved all directory watches into the existing child host, while this benchmark still intercepts the parent's fs.watch. This is a confirmed main benchmark regression for follow-up; the smoke is not claimed passing and an unrelated benchmark redesign is excluded.

Final-head CI 43924604188 succeeded on2ed553960fde3a48eb5206aecd8f5b8aacf388ad. Final ClawSweeper review6924641156 has zero open items; native review and preparation are complete. Landing is pending.

Prepare physical identity and inspection budgets asynchronously, preserve reader retirement and usage ordering, and let the read worker validate complete captured identity. Remove redundant host probes and already-known agent lookups. Cold 35 GiB synthetic read proof reduces a two-second injected event-loop stall to 8.8 ms; 78 focused cases pass.
@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-16T18:05:35.200326Z 2ed5539 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.

@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 Nov 16, 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. 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 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 makes cold credential identity discovery and SQLite inspection-budget preparation asynchronous while preserving worker-side file validation.

Example: A cold credential read encounters an injected 2,000 ms metadata delay.

  • Before: The supplied owner-level measurements report a median maximum heartbeat gap of 2,010.365 ms.
  • After: The same measurements report 8.814 ms while still verifying returned credentials and reader disposal.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is coherent and owner-level measurements are useful, but required Gateway behavior proof remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Cold credential reads can freeze unrelated Gateway requests when filesystem metadata is slow.
Reason: The maintainer-authored direction repairs a demonstrated availability problem without adding configuration, persistence formats, dependencies, or another owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a current main-thread blocking path using existing owners, and source review found no concrete introduced defect; exact-head CI remains pending.

Priority: P2
Reviewed head: 2ed553960fde3a48eb5206aecd8f5b8aacf388ad

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Show a cold credential read through an isolated running Gateway under delayed target metadata, with successful authentication and unrelated requests remaining responsive.
Agent review details

How this fits together

Gateway authentication preparation resolves agent and shared credential stores, prepares physical file identities, and receives credential rows from isolated SQLite readers.

flowchart TD
  A[Gateway credential request] --> B[Auth profile read owner]
  B --> C[Async agent and file identity discovery]
  C --> D[Existing reader lifecycle]
  D --> E[Isolated SQLite child]
  E --> F[Validate identity and read credentials]
  F --> B
Loading

Technical review

Best possible solution:

Keep asynchronous preparation in the existing auth and inspection owners, with physical identity validation in the isolated reader.

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

Current main visibly performs synchronous identity and inspection-budget metadata probes on this path; the PR supplies matching fault-injection measurements, but this review ran no target code.

Is this the best way to solve the issue?

The diff follows the smallest complete repair: reuse async physical-fact preparation, remove redundant parent probes, migrate callers, and preserve existing lifecycle and usage-ordering owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Asynchronous auth reads and retained file facts keeps the original intent (1d4202d: Move runtime credential reads into isolated readers while preserving source admission and cleanup; later retained file facts reduced repeated preparation.)
  • Candidate database identity and absence adoption keeps the original intent (dc4b96e: Allow a newly created agent database to adopt its first physical identity while rejecting replacement of an already captured file.)
  • Inspection budgets and worker settlement keeps the original intent (d46c7ee: Keep database inspection responsive while retaining timeout, cancellation, child-close, and staging custody.)
  • Usage preparation ordering keeps the original intent (32ec67e: Reserve preparation before asynchronous routing so overlapping credential bookkeeping cannot reorder ready writes.)
  • Agent directory reverse registry keeps the original intent (3ac0c05: Retain prepared agent-directory facts instead of repeating filesystem resolution on runtime paths.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned change and current-main defect: The introduced diff replaces synchronous identity preparation in the auth reader; fetched main still calls captureAuthProfileFileIdentity and inspectDatabasePathIdentitySync before reaching the isolated reader. (src/agents/auth-profiles/sqlite-read.ts:260, f4fa17a710be)
  • Preparation retains existing lifecycle ownership: Unknown-agent discovery registers an existing candidate resource before yielding, transfers to the known-agent resource, and avoids preparing a runtime row-cache reader after revocation or closure. (src/agents/auth-profiles/sqlite-read.ts:230, 2ed553960fde)
  • Physical validation remains in the child: The auth request carries captured birthtime, and the child validates complete identity before reading and before transferring credential rows; the regression extends the existing real-child replacement test. (src/infra/sqlite-readonly-location.worker.ts:484, 2ed553960fde)
  • Supplied performance evidence: The full PR body describes serialized fresh-process reads of a synthetic 37,641,338,880-byte database, credential verification, disposal, controls, and injected metadata delays; it explicitly limits the claims to owner-level APFS measurements. (2ed553960fde)
  • Earlier review and consumer repair: The previous review records no findings; the benchmark-specific comparison shows replacement of the removed synchronous identity helper with an awaited call to its async owner. (scripts/perf/auth-file-watch-events-measure.ts:98, 2ed553960fde)
  • Exact-head gates: The current head remains mergeable, the aggregate CI status is pending, and security-sensitive review reports sufficient maintainer authority; no additional SecOps approval is enforced for this change. (2ed553960fde)

Likely related people:

  • Peter Steinberger: Raw commit 1d4202d adds src/agents/auth-profiles/sqlite-read.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d4202ddbc05; files: src/agents/auth-profiles/sqlite-read.ts)
  • RoboClaw: Raw commit c6f29fd adds src/agents/auth-profiles/sqlite-read.ts:9 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c6f29fdc84df; files: src/agents/auth-profiles/sqlite-read.ts)

PR surface

Source +37, Tests +124, Other 0. Total +161 across 44 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 22 328 291 +37
Tests 21 257 133 +124
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 2 0
Total 44 587 426 +161

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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Slow filesystem metadata can block unrelated Gateway work during cold credential preparation, with a bounded existing-owner repair.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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-11-16T17:58:47.098Z sha 16fe0d0 :: needs maintainer review before merge. :: none

Reviewed November 16, 2026, 1:10 PM ET / 18:10 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Nov 16, 2026
@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: 2ed553960fde3a48eb5206aecd8f5b8aacf388ad
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/authorization.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/candidate-stores.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • 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.
  • src/agents/auth-profiles/inline-usage-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-refresh-peers.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/paths.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-read.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/source-check.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/sqlite-read.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/sqlite.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store-update-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store-update.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/upsert-with-lock.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/usage-write.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/plugin-model-catalog-auth.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.

@steipete

Copy link
Copy Markdown
Contributor Author

The previous review has zero open items. Final head 2ed5539 integrates main for a newly added benchmark consumer and migrates its two setup lines to the existing async identity owner. Scripts types/lint and fresh Codex review pass. The separate benchmark watch-mock failure is reproduced on exact CI main parent and attributed to #197445 in the updated body; no passing smoke is claimed. Original production behavior and measurement are unchanged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 9323fb9 into main Nov 16, 2026
154 of 160 checks passed
@steipete
steipete deleted the steipete/lane2535-auth-reader branch November 16, 2026 18:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

fuller-stack-dev added a commit that referenced this pull request Nov 16, 2026
…200242)

#200203 moved resolveIdentityPathViaExistingAncestor from
src/infra/boundary-path.ts to src/infra/path-existence.ts. #200192, merged
just before it, added a new import of that function from boundary-path.js in
oauth-refresh-peers.ts, so main has failed to typecheck and bundle since
9e66164. Import it from path-existence.js, as #200203 did for the other
callers.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…law#200192)

* fix: keep cold credential reads responsive on slow filesystems

Prepare physical identity and inspection budgets asynchronously, preserve reader retirement and usage ordering, and let the read worker validate complete captured identity. Remove redundant host probes and already-known agent lookups. Cold 35 GiB synthetic read proof reduces a two-second injected event-loop stall to 8.8 ms; 78 focused cases pass.

* test: await async identity preparation in auth watch benchmark
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…penclaw#200242)

openclaw#200203 moved resolveIdentityPathViaExistingAncestor from
src/infra/boundary-path.ts to src/infra/path-existence.ts. openclaw#200192, merged
just before it, added a new import of that function from boundary-path.js in
oauth-refresh-peers.ts, so main has failed to typecheck and bundle since
8ecc0fc. Import it from path-existence.js, as openclaw#200203 did for the other
callers.
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Backport 9323fb9 (#200192) and
3f33eb9 (#200222) as one credential-owner
slice on the 2026.11.6 release base. Reuse native admission preparation
without importing replacement execution or snapshot architecture.

Preserve physical-alias FIFO reservations, capture shared ownership before
awaiting preparation, and retain one-shot cancellation/deadline settlement.

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Recheck the canonical registry immediately before publication and retain extra descriptors until joined host or worker retirement. Parent independently reviewed native overlap, generation preservation, and both cleanup paths; 47 targeted tests passed.

Follow-up to backports #200192 and #200222.

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 commands Command implementations P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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