Skip to content

perf(agent): trace local startup stages - #117653

Merged
vincentkoc merged 1 commit into
mainfrom
perf/agent-local-startup-trace
Aug 1, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/agent-local-startup-trace

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Local agent startup time before the existing agent.prepare spans could not be
attributed to command loading, config/secrets setup, session state, model
selection, or attempt-runtime loading.

Why This Change Was Made

Adds opt-in agent.startup diagnostics timeline spans around the existing owner
boundaries. The spans reuse the canonical diagnostics timeline, preserve the
original direct execution path when diagnostics are disabled, and do not change
provider, model, config, session, or error policy.

Maintainer Decision

Land the observability seam separately from any optimization. The exact Kova
evidence shows that most pre-provider time remains outside these new spans, so
combining speculative startup changes with the instrumentation would obscure
the baseline. Follow-up performance work should target the measured owners.

User Impact

No user-visible runtime change. Maintainers get stage-level data for local agent
startup when diagnostics are explicitly enabled.

Exact-Head Evidence

Stage p50 max
command-prepare 125.1 ms 148.9 ms
attempt-runtime-import 48.8 ms 55.2 ms
session-state 41.5 ms 58.6 ms
config-source 8.8 ms 17.9 ms
model-selection 6.3 ms 7.9 ms
secrets-runtime-import 5.0 ms 5.3 ms
command-import 3.8 ms 12.8 ms
secrets-snapshot 2.6 ms 3.0 ms
command-dependencies 1.1 ms 8.0 ms
  • Normal Kova:
    • agent RSS median/p95/max: 852/858/859 MB
    • cold/warm agent turn median: 3275/3292 ms
    • pre-provider p95 median: 3175 ms
    • agent.startup was the slowest new span at 125-149 ms
    • no open spans or liveness warnings
  • Near-contemporaneous control run 30722795395, without this instrumentation:
    • agent RSS median/p95/max: 837/847/849 MB
    • cold/warm agent turn median: 3267/3304 ms
    • pre-provider p95 median: 3183 ms
    • latency is effectively flat; diagnostics-mode RSS is +15 MB median
      (+1.8%). This is not a strict same-SHA A/B because current main advanced
      between runs, but the intervening changes did not touch this agent surface.
  • Live OpenAI passed: cold/warm 5847/5582 ms, pre-provider 4345 ms.
  • Deep profile reproduced all nine stages. Its agent RSS threshold remained the
    known profiler-overhead diagnostic (1053 MB over 1000 MB); the workflow
    classified it as profiling-only and passed.
  • Source readiness passed on the post-fix(perf): wait for gateway WebSocket readiness #117655 baseline; connected health p50/p95
    was 691/698 ms.

Local Verification

  • node scripts/run-vitest.mjs src/agents/startup-timing.test.ts src/commands/agent-via-gateway.test.ts src/agents/agent-command.ingress-diagnostics.test.ts
    • 94 passed, 1 skipped.
  • Focused oxfmt --check, oxlint, and git diff --check passed.
  • P2-wide autoreview completed clean with no accepted/actionable findings.
  • The rebased patch is equivalent to the previously reviewed patch.
  • Current main at b2278f3d10591d9eec4c091c82a4077d777143a6
    has not changed the six touched files, and git merge-tree --write-tree is
    clean.

Findings And Next Work

The new spans explain roughly 230-250 ms of a roughly 3.2-second normal
pre-provider path. The largest remaining bucket is still about 2.9 seconds of
unattributed process/module bootstrap. Repeated plugin metadata scans account
for another roughly 175-190 ms per cold/warm pair. Optimize those owners in
separate PRs using this timeline as the baseline.

Storage And Compatibility

No persisted state, schema, config, protocol, or public API changes. Timeline
events are written only through the existing opt-in diagnostics contract.

@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 1, 2026
@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 7:40 PM ET / 23:40 UTC.

ClawSweeper review

What this changes

Adds nine opt-in agent.startup timeline stages around local agent command loading, dependency/config/secrets setup, session state, model selection, and attempt-runtime loading.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The patch appears correct and remains necessary: current main has the generic diagnostics timeline but not this local agent-startup attribution. The implementation preserves the existing disabled path, has supplied exact-head runtime evidence, and needs normal human acceptance because this maintainer-owned, maintainer-labeled PR adds a new core diagnostics taxonomy.

Priority: P3
Reviewed head: 6ccc8e439da7ace01aa4429190612f0fe7860eb1
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, contract-aligned instrumentation change with strong exact-head runtime evidence and no supported correctness finding.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body supplies exact-head workflow evidence from normal mock traces, deep profiling, and a live OpenAI run that observed all intended stages and reported no open spans or liveness warnings.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body supplies exact-head workflow evidence from normal mock traces, deep profiling, and a live OpenAI run that observed all intended stages and reported no open spans or liveness warnings.
Evidence reviewed 7 items Canonical disabled-path contract: The existing diagnostics wrapper returns directly to the supplied operation when timeline diagnostics are disabled, so the new helper reuses the established no-event execution behavior rather than adding a separate telemetry path.
Patch uses the canonical timeline: The proposed helper delegates every startup stage to measureDiagnosticsTimelineSpan with the existing agent.startup phase and a bounded, static stage attribute; it does not add configuration, persistence, provider routing, or a new output mechanism.
All intended owner boundaries are instrumented: The exact PR head instruments command dependency and preparation work, config and secrets resolution, session and model setup, attempt-runtime import, and the local CLI command import; these are the pre-provider boundaries described in the PR.
Findings None None.
Security None None.

How this fits together

Local agent execution resolves command dependencies, runtime configuration, session/model state, and the attempt runtime before provider preparation begins. This PR feeds those existing owner boundaries into the opt-in diagnostics timeline so performance work can identify which startup stage consumed time.

flowchart LR
  A[Local agent CLI or ingress] --> B[Command and dependency setup]
  B --> C[Config and secrets resolution]
  C --> D[Session and model preparation]
  D --> E[Attempt runtime loading]
  E --> F[Provider preparation]
  B --> G[Opt-in diagnostics timeline]
  C --> G
  D --> G
  E --> G
Loading

Decision needed

Question Recommendation
Should OpenClaw accept this nine-stage core diagnostics taxonomy now as a standalone observability baseline before deciding on startup optimizations? Accept the standalone baseline: Merge the opt-in instrumentation now and use measured stage data to scope later performance work.

Why: The patch is mechanically sound, but adding a durable core trace taxonomy is a maintainer-owned observability direction rather than a bug fix with a pre-existing public contract.

Before merge

None.

Agent review details

Security

None.

PR surface

Source +58, Tests +45. Total +103 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 124 66 +58
Tests 1 45 0 +45
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 169 66 +103

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/agents/startup-timing.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Accept the small, opt-in agent.startup instrumentation seam as the baseline, then use its stage data to pursue separate owner-specific startup optimizations rather than combining speculative performance changes into this PR.

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

Not applicable: this PR adds observability rather than repairing a reported end-user failure. The supplied exact-head workflow evidence does, however, show the new stages in real agent runs.

Is this the best way to solve the issue?

Yes: reusing the canonical diagnostics timeline at existing owner boundaries is the narrowest maintainable approach, and it preserves the direct execution path when diagnostics are disabled.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2f06ed30d8b1.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies exact-head workflow evidence from normal mock traces, deep profiling, and a live OpenAI run that observed all intended stages and reported no open spans or liveness warnings.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This is opt-in internal performance instrumentation with no config, persistence, routing, or end-user runtime behavior change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body supplies exact-head workflow evidence from normal mock traces, deep profiling, and a live OpenAI run that observed all intended stages and reported no open spans or liveness warnings.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies exact-head workflow evidence from normal mock traces, deep profiling, and a live OpenAI run that observed all intended stages and reported no open spans or liveness warnings.

Evidence

What I checked:

  • Canonical disabled-path contract: The existing diagnostics wrapper returns directly to the supplied operation when timeline diagnostics are disabled, so the new helper reuses the established no-event execution behavior rather than adding a separate telemetry path. (src/infra/diagnostics-timeline.ts:302, 2f06ed30d8b1)
  • Patch uses the canonical timeline: The proposed helper delegates every startup stage to measureDiagnosticsTimelineSpan with the existing agent.startup phase and a bounded, static stage attribute; it does not add configuration, persistence, provider routing, or a new output mechanism. (src/agents/startup-timing.ts:12, 6ccc8e439da7)
  • All intended owner boundaries are instrumented: The exact PR head instruments command dependency and preparation work, config and secrets resolution, session and model setup, attempt-runtime import, and the local CLI command import; these are the pre-provider boundaries described in the PR. (src/agents/agent-command.ts:560, 6ccc8e439da7)
  • Focused regression coverage: The added test verifies that an enabled timeline emits a matched start/end pair with the expected agent.startup phase and command-import stage while preserving the wrapped result. (src/agents/startup-timing.test.ts:15, 6ccc8e439da7)
  • Current-main necessity and merge integration: Current main does not contain either new startup-timing file, while the PR commit is a direct child of its recorded base and the read-only three-way merge inspection produced no conflict markers; intervening main changes did not modify the touched paths. (src/agents/startup-timing.ts:1, 2f06ed30d8b1)
  • Feature provenance and likely owner: The canonical diagnostics span implementation and adjacent agent startup flow were introduced on current main by Peter Steinberger in the same diagnostics/agent ownership change; the line-level blame ties the wrapper behavior to that implementation. (src/infra/diagnostics-timeline.ts:297, 17eafa716248)

Likely related people:

  • Peter Steinberger: Current-main blame attributes the generic async timeline-span contract and nearby agent startup flow to this author; the PR deliberately builds on that contract. (role: canonical diagnostics and adjacent agent-flow author; confidence: high; commits: 17eafa716248, b7f0df0ac2e2; files: src/infra/diagnostics-timeline.ts, src/agents/agent-command.ts, src/agents/agent-runtime-config.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-08-01T22:00:06.776Z sha 0ecdf7b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T23:16:28.927Z sha 6ccc8e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T23:24:35.480Z sha 6ccc8e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T23:32:44.722Z sha 6ccc8e4 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf/agent-local-startup-trace branch from 0ecdf7b to 6ccc8e4 Compare August 1, 2026 23:12
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Aug 1, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 1, 2026 23:20
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

All prior before-merge and rank-up items are resolved on
6ccc8e439da7ace01aa4429190612f0fe7860eb1:

  • exact run 30722860302 passes source, normal mock, deep profile, and live
    OpenAI;
  • all nine intended agent.startup stages appear across 10 normal traces;
  • timing and RSS are recorded, including a near-contemporaneous control;
  • no open spans or liveness warnings were observed;
  • the maintainer decision is explicit: land observability separately, then
    optimize the measured owners;
  • current-main merge-tree is clean and none of the touched files changed;
  • no persisted state, migration, config, protocol, or public API surface
    changed.

Please refresh the durable review against this exact head.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Final exact-head landing gate for
6ccc8e439da7ace01aa4429190612f0fe7860eb1:

  • every current-head GitHub check is complete and successful;
  • exact Kova run 30722860302 passes source, normal mock, deep profile, and live
    OpenAI;
  • all nine intended agent.startup stages appear across 10 normal traces;
  • timing, RSS, chronological ordering, and the near-contemporaneous control are
    documented in the PR body;
  • the maintainer decision is to land observability separately before measured
    optimizations;
  • the merge result against current main is clean and touched files have no
    main-side drift;
  • no persisted state, migration, config, protocol, or public API surface
    changed.

Please close every remaining before-merge item in the durable review if this
evidence is sufficient.

@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Current-base landing refresh is complete for
6ccc8e439da7ace01aa4429190612f0fe7860eb1:

  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 117653 completed successfully;
  • the prepare head and remote PR head remained exactly
    6ccc8e439da7ace01aa4429190612f0fe7860eb1;
  • hosted exact-or-recent-parent gates passed at 2026-08-01T23:35:14Z;
  • the exact three-way merge tree against current main
    2f06ed30d8b1a9ffe9493030e4d553ee4093c745 is clean;
  • no touched file changed between the previously reviewed main and that current
    main;
  • every exact-head GitHub check remains complete and successful.

Maintainer decision remains to land this observability-only seam separately.
Please close the remaining current-base before-merge item.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: accept the standalone nine-stage agent.startup
diagnostics taxonomy as the baseline for subsequent measured optimization work.
The taxonomy is opt-in, bounded, and uses the existing diagnostics timeline
contract. This resolves the remaining human decision in the latest ClawSweeper
review.

@vincentkoc
vincentkoc merged commit 4153451 into main Aug 1, 2026
203 of 222 checks passed
@vincentkoc
vincentkoc deleted the perf/agent-local-startup-trace branch August 1, 2026 23:43
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

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 maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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