Skip to content

perf(agents): reduce repeated turn setup latency - #105220

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-turn-performance
Jul 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-turn-performance

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #105207

What Problem This Solves

Repeated Gateway agent turns materialized the same prepared OpenAI route twice during auth setup. On a warm process, duplicate provider/model discovery accounted for roughly half of the local pre-model latency measured in the live path.

Why This Change Was Made

The runner now carries the exact materialized model forward for the same immutable auth-plan object. Unscoped direct-auth routes also reuse an already matching runtime model tuple, while credential-scoped, profile, mismatch, and fallback routes continue to resolve independently. Trace-only auth substages make future regressions attributable without adding normal-path logging.

AI-assisted: yes. The implementation, route invariants, tests, live provider runs, and benchmark measurements were reviewed and verified by the maintainer agent.

User Impact

In repeated live openai/gpt-5.6 Gateway turns, warm median local pre-model setup fell from 441.5 ms to 206.5 ms (53.2%). Warm auth setup fell from 236 ms to 8 ms, and cold pre-model setup fell from 1169 ms to 983 ms. Provider response and tool execution time are unchanged.

Evidence

  • Live baseline: run_05d253dc5e45; warm pre-model 455 ms / 428 ms, auth 235 ms / 237 ms.
  • Live final: run_68ba04715c1a; warm pre-model 187 ms / 226 ms, auth 7 ms / 9 ms.
  • Live Node CPU profile: run_0eae5386bbe1; local samples identified repeated module/package resolution in the duplicated materialization path.
  • Live build: run_86d623a9d822 passed on fresh AWS Crabbox.
  • Focused Testbox proof: 67/67 tests passed on the rebased patch.
  • check:changed passed formatting, lint, typecheck, cycle, and guard lanes before the final clean rebase.
  • Fresh autoreview: clean, no accepted or actionable findings.

@steipete steipete self-assigned this Jul 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for the repeated-turn performance fix:

  • Live OpenAI baseline (run_05d253dc5e45): warm local pre-model setup 455 ms / 428 ms; auth 235 ms / 237 ms.
  • Live OpenAI final (run_68ba04715c1a): warm local pre-model setup 187 ms / 226 ms; auth 7 ms / 9 ms. Warm median pre-model setup improved 441.5 ms to 206.5 ms (53.2%).
  • Live Node CPU profile (run_0eae5386bbe1) isolated repeated module/package resolution in the duplicated route-materialization path.
  • Fresh AWS Crabbox build (run_86d623a9d822) passed.
  • Blacksmith Testbox: corepack pnpm test src/agents/embedded-agent-runner/run.overflow-compaction.test.ts passed 67/67.
  • Patch-scoped repository guards and formatting passed; the only direct Testbox gate failure was the independently reproducible current-main Plugin SDK baseline hash drift.
  • Fresh autoreview: clean, zero accepted or actionable findings.
  • Review artifacts: validated, READY FOR /prepare-pr, zero findings; same-plan reuse, direct matching route, credential-scoped route, native-owned route, and distinct fallback route branches reviewed.
  • Exact-head hosted CI: run 29187135235 passed on 9446f13f414faff76893336e97d8a3feef81d794 with zero failed jobs.
  • Repo-native prepare gate: passed in hosted_exact_or_recent_rebase mode; prepared head and PR head both 9446f13f414faff76893336e97d8a3feef81d794.

Known proof gaps: none in the changed runtime/test surface. The direct path-scoped Testbox check exposed an unrelated current-main Plugin SDK baseline drift, while the exact-head authoritative hosted CI and repo-native prepare gate passed.

@steipete
steipete merged commit b4a0fc5 into main Jul 12, 2026
114 of 116 checks passed
@steipete
steipete deleted the codex/gateway-turn-performance branch July 12, 2026 09:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
* perf(agents): reuse prepared auth route models

* chore: leave release notes to release automation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agent turns rematerialize the same auth route twice

1 participant