Skip to content

improve(auth): reduce pauses during concurrent credential reads - #152140

Merged
steipete merged 4 commits into
mainfrom
codex/perf-auth-read-spawn-broker-7006
Sep 18, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/perf-auth-read-spawn-broker-7006

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent agent turns repeatedly create isolated credential readers from the Gateway process. Native process creation blocks its main thread while agents prepare authentication.

Why This Change Was Made

Canonical credential reads use the Gateway's existing spawn broker. Every read still creates and closes its own isolated SQLite reader, checks current source identity, and returns fresh rows. The reader waits for IPC readiness and cleanup, preserving both read and cleanup failures with the original cause.

An authoritative broker refusal before launch now closes the proxy and permits one native fallback using the captured environment, working directory, and arguments. Cancellation, timeout, uncertain admission, other errors, and cleanup failure remain terminal. This addresses the availability review finding without replaying an uncertain launch. Snapshot readers keep native spawning.

The broker host also owns its prepared worker path for startup and restarts, preserving the lazy build boundary. The PR wrapper inventory includes the newly reachable broker dependencies.

User Impact

Node-based Linux Gateways can keep canonical credential-reader process creation off their main thread. Operation without a broker remains available. No result cache, persistent reader pool, configuration, schema, dependency, or public SDK change is introduced.

Evidence

  • Final source: 98 tests across six files passed, including broker refusal, cancellation before launch and fallback, timeout precedence, captured working directory, fresh rows, snapshot routing, broker loss, and cleanup. Five new behavior regressions failed against the preceding implementation; its timeout-priority control passed.
  • Final source formatting, git diff --check, and the repository core TypeScript lane passed locally.
  • Fresh independent review of the final four-file repair was scoped-clean with no P0–P2 findings. Earlier owner/boundary and wrapper-inventory changes also passed independent review.
  • The preceding runtime passed a full build and 97 tests across nine suites. The inventory correction passed 14 existing wrapper closure/handoff tests. That local full build predates the fallback repair. Final-head CI passed on d6d502e051f9b1cd10206598d280c51935e36d3a, including the required CI gate.
  • Final-source baseline/candidate/candidate/baseline comparison used loadAuthProfileStoreForRuntimeAsync, Node 24.19.0 on Linux, one warmup and four measured batches per workload per arm. All 1,336 complete stores and freshness results matched; both candidate arms closed all 668 brokered readers. All processes joined and source was restored.
Workload Baseline median batch Candidate median batch Median per-batch event-loop delay p99, before → after
Small, serial 333.9 ms 316.7 ms 1.56 → 1.72 ms
Small, concurrent 32 1329.8 ms 903.4 ms 53.00 → 8.13 ms
Moderate, serial 318.7 ms 316.1 ms 1.39 → 1.58 ms
Moderate, concurrent 32 1353.8 ms 930.2 ms 65.73 → 7.69 ms

Concurrent median batch latency fell 31–32%, parent CPU fell 52–64%, and event-loop delay p99 fell 85–88%. Serial pooled latency gains were smaller (0.8–5.1%), and moderate serial gains were not consistent across arms; serial event-loop delay p99 increased 0.16–0.19 ms. Peak parent RSS increased 1.1% (11.1 MiB) for moderate concurrent reads and decreased 1.4–2.1% in the other cells. Both candidate concurrent medians were faster than both baselines; the second concurrent baselines were 8–11% slower than the first. All adverse observations are retained. These results do not establish whole-Gateway speedup, overall memory reduction, or total CPU savings; parent CPU excludes the broker and reader processes.

The parent revision's CI run failed the existing PR-worktree interruption test because two esbuild processes briefly outlived its wrapper. Owner/test bytes were unchanged, but missing process lineage prevents excluding a timing contribution. The failure remains recorded without claiming its cause was fixed. The same shard and all required checks passed on the final revision. Earlier local type-aware lint exceeded the 8 GiB cap; hosted lint passed on the final revision.

@steipete steipete self-assigned this Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 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 agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 18, 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 Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 6:21 PM ET / 22:21 UTC (Revision 5).

ClawSweeper review

What this changes

Routes canonical credential-reader processes through the existing spawn broker, adds one native fallback after confirmed non-admission, preserves cleanup guarantees, and updates tests, documentation, and wrapper dependencies.

Merge readiness

✅ Ready for maintainer review

The improvement remains useful, and the latest repair resolves the previous availability concern. No blocking correctness or security findings remain.

Priority: P2
Reviewed head: d6d502e051f9b1cd10206598d280c51935e36d3a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong runtime measurements and meaningful lifecycle coverage; the prior availability concern is resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied final-source Linux/Node benchmark exercises the production credential-loading entry point through real brokered SQLite readers, reports matching fresh stores and joined children, and measures reduced concurrent pauses; lifecycle tests provide supplemental fault coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied final-source Linux/Node benchmark exercises the production credential-loading entry point through real brokered SQLite readers, reports matching fresh stores and joined children, and measures reduced concurrent pauses; lifecycle tests provide supplemental fault coverage.
Evidence reviewed 9 items Prior availability concern resolved: The previous review requested a decision about native recovery after proven non-admission. The current body explicitly selects recovery, and the implementation requires successful cleanup, notStarted, the broker-unavailable error code, and a fresh cancellation check before creating a native replacement. Native replacements cannot enter another broker fallback.
Authoritative refusal and cleanup lifecycle: The host marks local admission refusals as not started; ordered failed worker-admission results establish the same fact before the error arrives. Reader sessions preserve captured environment, working directory, and arguments, and join broker cleanup when proxy closure lacks a native exit outcome.
Credential ownership remains intact: The changed caller only distinguishes canonical sources from snapshots. Existing cancellation, physical-file identity, captured admission, and post-read ownership checks remain. The child retains its source lease and uses the existing read-only query and framed-transfer owners; no Codex runtime or protocol contract is involved.
Findings None None.
Security None None.

How this fits together

Agent preparation reads stored credentials through isolated SQLite reader processes. The Gateway’s spawn broker moves process creation away from its main thread while the credential owner continues checking source identity and returning fresh rows.

flowchart TD
 A[Agent credential preparation] --> B[Choose reader transport]
 B -->|Canonical database and broker available| C[Spawn broker]
 B -->|Snapshot or no broker| D[Native process launch]
 C -->|Confirmed non-admission only| D
 C --> E[Isolated SQLite reader]
 D --> E
 E --> F[Join process and cleanup]
 F --> G[Validate ownership and return fresh credentials]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +95, Tests +321, Docs +6, Other +4. Total +426 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 138 43 +95
Tests 3 387 66 +321
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 0 +4
Total 11 535 109 +426

Review metrics

Metric Value Why it matters
Production versus test growth Production +95 net LOC; tests +321; wrapper inventory +4 Production growth implements broker readiness, cleanup joining, and bounded recovery; tests cover the corresponding lifecycle failures.
Measured concurrent responsiveness Batch latency −31–32%; event-loop delay p99 −85–88% The reported production-entrypoint comparison supports the stated concurrency benefit without claiming whole-Gateway speedup.

Technical review

Best possible solution:

Keep one credential-read owner with fresh isolated reads, broker-assisted spawning, and native recovery limited to confirmed non-admission.

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

Not applicable as a discrete correctness bug; the performance mechanism is source-supported and the supplied real-entrypoint benchmark measures its before/after effect.

Is this the best way to solve the issue?

Yes. Reusing the existing broker avoids another process manager or credential cache, while the guarded native fallback preserves availability without replaying uncertain launches.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded improvement to Gateway responsiveness during concurrent credential preparation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied final-source Linux/Node benchmark exercises the production credential-loading entry point through real brokered SQLite readers, reports matching fresh stores and joined children, and measures reduced concurrent pauses; lifecycle tests provide supplemental fault coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied final-source Linux/Node benchmark exercises the production credential-loading entry point through real brokered SQLite readers, reports matching fresh stores and joined children, and measures reduced concurrent pauses; lifecycle tests provide supplemental fault coverage.

Evidence

What I checked:

  • Prior availability concern resolved: The previous review requested a decision about native recovery after proven non-admission. The current body explicitly selects recovery, and the implementation requires successful cleanup, notStarted, the broker-unavailable error code, and a fresh cancellation check before creating a native replacement. Native replacements cannot enter another broker fallback. (src/infra/sqlite-readonly-worker.ts:282, d6d502e051f9)
  • Authoritative refusal and cleanup lifecycle: The host marks local admission refusals as not started; ordered failed worker-admission results establish the same fact before the error arrives. Reader sessions preserve captured environment, working directory, and arguments, and join broker cleanup when proxy closure lacks a native exit outcome. (src/process/spawn-broker/host.ts:348, d6d502e051f9)
  • Credential ownership remains intact: The changed caller only distinguishes canonical sources from snapshots. Existing cancellation, physical-file identity, captured admission, and post-read ownership checks remain. The child retains its source lease and uses the existing read-only query and framed-transfer owners; no Codex runtime or protocol contract is involved. (src/agents/auth-profiles/sqlite-read.ts:230, d6d502e051f9)
  • Real performance evidence: The supplied PR-body snapshot, sourceRevision d10af4e31e916a14d7535222ad9fb2d8fbe100265fe7098be2d8bbd2ce0389fb, reports a final-source baseline/candidate/candidate/baseline comparison through loadAuthProfileStoreForRuntimeAsync on Linux with Node 24.19.0. All 1,336 complete stores and freshness results matched, and both candidate arms joined all 668 brokered readers. Concurrent median batch latency improved 31–32% and event-loop delay p99 improved 85–88%. The body retains serial-delay and RSS regressions and does not claim whole-Gateway or total-process CPU improvement. (src/agents/auth-profiles/runtime-read.ts:236, d6d502e051f9)
  • Focused regression coverage: The added suite covers real native and brokered readers, oversized credential transfer, fresh rows, snapshot transport, cancellation before readiness, confirmed refusal, timeout precedence, and broker-loss cleanup. The body reports 98 passing tests and five regressions failing before the repair. These tests were inspected, not executed in this read-only review. (src/infra/sqlite-readonly-worker.auth.test.ts:70, d6d502e051f9)
  • Still necessary on current main: Fetched main still creates credential-reader sessions with native spawn and has no broker selection or confirmed-refusal fallback in this path. The latest release tree lacks the reader-session and spawn-broker host paths; no shipped or merged replacement for this improvement was established. (src/infra/sqlite-readonly-worker-session.ts:30, fe7f80ddca98)

Likely related people:

  • Peter Steinberger: Raw commit 1d4202d adds src/agents/auth-profiles/sqlite-read.ts:230 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)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-18T20:24:27.548Z sha 268ce2fd4dbd4655d838339f015617f7f530d043 :: blocked before merge. :: none
  • reviewed 2026-09-18T21:00:40.598Z sha 55badde :: blocked before merge. :: none
  • reviewed 2026-09-18T21:30:39.574Z sha 0a3b02d :: blocked before merge. :: none
  • reviewed 2026-09-18T21:46:31.828Z sha 240cc11 :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 18, 2026 20:49
@steipete
steipete force-pushed the codex/perf-auth-read-spawn-broker-7006 branch from 268ce2f to 55badde Compare September 18, 2026 20:52
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L and removed size: M labels Sep 18, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 18, 2026
@steipete
steipete merged commit 71a1d0d into main Sep 18, 2026
226 of 227 checks passed
@steipete
steipete deleted the codex/perf-auth-read-spawn-broker-7006 branch September 18, 2026 22:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 18, 2026
…pr-149099-main-20260918

* commit '795e460278d4f8f41545dc8b4a66da1d12defd90': (1902 commits)
  refactor(slack): share Markdown preparation (#149129)
  fix(tooling): release completed PR operations with exited loaders (#152209)
  fix(release): allow stable npm bootstrap under an operator soak waiver (#152206)
  fix(daemon): avoid false restart timeouts during slow startup (#151387)
  feat: read agent documents from a host-owned workspace (#150584)
  improve(startup): skip redundant single-agent directory checks (#152192)
  test(ui): await board widget readiness before size reports (#152198)
  perf(browser): move dashboard event discovery to SQLite worker (#151952)
  improve(auth): reduce pauses during concurrent credential reads (#152140)
  improve(ui): load older chat history in smaller pages (#152093)
  fix(release): reject incomplete legacy npm install trees (#152186)
  refactor: share current-conversation binding row serialization (#152134)
  test(tooling): preserve Node and terminal fixture ownership under Bun (#152187)
  fix(sqlite): service worker admission through retained path aliases (#152190)
  improve: reduce CPU work for long CLI reasoning streams (#152191)
  chore(ui): refresh control ui locales (#152196)
  test(subagents): align lifecycle retries with durable completion owners (#152184)
  perf(gateway): defer participant maps for owned sessions (#152097)
  refactor(stream): share auxiliary queue overflow handling (#149282)
  fix(test): execute CLI fixture preloads on Node and Bun (#152076)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…claw#152140)

* improve(auth): reduce pauses during concurrent credential reads

* fix: preserve auth cleanup errors and broker build boundary

* fix: include broker dependencies in PR wrapper

* fix: preserve auth reads after broker nonadmission
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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. scripts Repository scripts size: L 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