Skip to content

fix(gateway): expose recovery startup timing breakdown - #174357

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-subagent-recovery-variance-20260919
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-subagent-recovery-variance-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restart recovery can spend seconds waiting after Gateway readiness, but normal startup logs show only the total sidecars.subagent-recovery duration. The existing child spans require enabling verbose startup tracing, so an ordinary production boot cannot identify the slow stage.

User Impact

Operators get one bounded completion summary at normal info level, with reader preparation, delivery recovery, blocked-notice work, retry backoff, exec recovery, registry loading, and registry activation timings. The line includes no session identities, message content, paths, or error payloads.

Why This Change Was Made

Reuse the startup trace owner and existing spans. Include dynamic imports in their stage timing, accumulate repeated notice/backoff spans, and retain the existing recovery order, reader-readiness barrier, cancellation, and shutdown custody. Nested notice and retry durations belong within delivery duration and must not be added to the outer total.

Current main now includes #174278, which saves a blocked-delivery notice and cancels replay of replaced-endpoint inputs. This branch is rebased onto that fix, preserving its durable second-restart regression. The production measurements below predate that change; repeated stale-input work is already addressed by that owner.

The prior reader barrier protects restored admission budgets; moving activation earlier would not remove a shared database queue stall. This PR supplies the missing attribution before changing that ordering. Related: #174134.

Evidence

Read-only analysis of five consecutive production boots found recovery durations of 21.683 / 13.562 / 24.360 / 10.508 / 23.753 seconds. Authenticated connections in the first 30 seconds were 15 / 15 / 12 / 15 / 19, so connection count alone does not explain variance. Named sidecar startup spans had already completed, although background work could continue.

In the two slow recent boots, 16.611 / 16.134-second gaps between delivery rejections coincide with board.get calls taking 16.540 / 16.657 seconds. Both paths use agent-database FIFO admission. All eleven retained deliveries on those boots failed once with replaced endpoints; no retry-backoff warnings occurred. Blocked-notice selection scans the active transcript under writer admission even when the notice is unchanged, making it a concrete candidate for the next measurement. Existing journal and scrape-aligned Prometheus counters cannot prove which operation held the queue.

Before: one opaque outer phase line. After: the same completion line carries seven numeric subspan totals and outcome; detailed per-span logs remain opt-in. No production speedup or before/after latency improvement is claimed. The next deployed boot is required to attribute the production wait. This change does not alter scheduling or database behavior.

Focused local proof: 42 tests passed across server-startup-trace.test.ts, session-send-recovery.test.ts, and server-startup-observers.test.ts (60.71 seconds Vitest wall time; 67.25 seconds including wrapper preparation). New timing cases use controlled clocks, exercise actual recovery-to-log wiring, cover repeated notices, trace on/off, failure, phase reset, and post-ready reporting. Changed-file formatting and scoped core/test lint passed. Independent autoreview was clean through P2. All three summary regressions fail against the original trace implementation because no breakdown is emitted (1.95 seconds Vitest wall time); the reviewed implementation was restored byte-for-byte afterward. After resolving the overlap with #174278, the complete 25-test delivery recovery file passed again (38.02 seconds Vitest wall time, 41.28 seconds including preparation; 1.05 seconds test time), including durable stale-input cancellation and our timing case. A fresh review of the merged source was clean through P2, and scoped lint passed again. Broad validation belongs to PR CI; no remote validation leases or production mutations were used.

Production delta: +42 lines. Growth is required for the explicitly requested bounded timing summary and two nested measurements; there is no new cache, worker, scheduler, schema, configuration, or competing recovery path.

@clawsweeper

clawsweeper Bot commented Oct 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 Oct 16, 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-16T15:20:52.447698Z e62b412 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 16, 2026
Include bounded reader, delivery, blocked-notice, retry-wait, exec, registry-load and activation durations in the normal recovery completion line. Preserve recovery ordering and reader readiness while making production startup waits attributable without verbose tracing.
@steipete
steipete force-pushed the steipete/perf-micro-subagent-recovery-variance-20260919 branch from c26c030 to e62b412 Compare October 16, 2026 15:18
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds seven recovery-stage timing totals and an outcome to the normal Gateway startup completion log.

Example: Recovery takes 1790 ms, including 500 ms recording blocked notices and 1000 ms waiting before retries.

  • Before: The normal log reports only the 1790 ms outer recovery duration.
  • After: The completion line includes deliveryMs=1600.0, deliveryNoticesMs=500.0, retryWaitMs=1000.0, the remaining stage totals, and outcome=success.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful patch with meaningful timing-contract coverage and no identified defects; evidence remains limited to tests rather than a shipped Gateway run.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied after-change evidence uses controlled clocks and mocked I/O around the trace and recovery owners, while the production boot observations predate this instrumentation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot identify which recovery stage accounts for a slow post-ready startup from normal logs.
Reason: The maintainer-authored direction addresses a concrete diagnostic gap with bounded output and no additional configuration or recovery mechanism.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides useful, owner-directed recovery diagnostics that current main lacks, with no actionable correctness or security findings.

Priority: P3
Reviewed head: e62b412867ab76e6595cf0294b2366b243064302

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Gateway boot showing the new completion summary is supplied; baseline failures are reported for the summary tests.
Agent review details

How this fits together

Gateway startup observers join reader preparation, recover saved deliveries and exec notifications, and activate the subagent registry; the existing startup trace owner turns those measurements into operator logs.

flowchart TD
  A[Post-ready startup observers] --> B[Reader preparation]
  B --> C[Saved delivery recovery]
  C --> D[Exec recovery]
  D --> E[Registry loading and activation]
  C --> F[Startup trace owner]
  B --> F
  E --> F
  F --> G[Recovery completion log]
Loading

Technical review

Best possible solution:

Keep the bounded summary in the existing startup trace owner while preserving recovery ordering, cancellation, and delivery authority checks.

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

Current-main source confirms that normal logs expose only the outer recovery duration; the individual stages require verbose tracing, and no target code was executed during this review.

Is this the best way to solve the issue?

The implementation fits the problem: it extends the existing measurement owner, accumulates repeated spans, and documents that nested totals must not be added to the outer duration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Recovery ordering and reader-readiness barrier keeps the original intent (b4ce369: Restoration must settle before requester recovery, with reader maintenance joined before restored admission budgets start.)
  • Delivery retry and blocked-notice operations keeps the original intent (0ffb90a: Retry transient recovery failures within a bounded window while retaining endpoint and communication checks.)
  • Durable replaced-endpoint settlement keeps the original intent (7593d68: Save a durable explanation before cancelling automatic replay of undeliverable inputs.)
  • Normal-level startup diagnostics keeps the original intent (3d05374: Expose useful bounded startup attribution without requiring verbose tracing or changing scheduling.)
  • Startup trace lifecycle keeps the original intent (dbac2c1: Close the event-loop monitor at terminal lifecycle points without losing recoverable startup diagnostics.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

  • Introduced change: The pinned introduction adds timing aggregation, includes dependency loading inside measured stages, and wraps existing notice and retry-wait operations without changing their arguments or recovery decisions. (src/gateway/server-startup-trace.ts:172, e62b412867ab)
  • Current-main behavior: The three affected production modules on fetched main match the introduction base; normal recovery completion logging still lacks the proposed breakdown. (src/gateway/server-startup-trace.ts:172, 9151847f12e0)
  • Timing contracts: Controlled-clock tests cover repeated spans, failure propagation, trace enabled and disabled, post-ready reporting, and reset between recovery phases; a recovery-owner test connects notice and backoff measurements to the completion summary. (src/gateway/server-startup-trace.test.ts:49, e62b412867ab)
  • Recorded scope and evidence: The full PR body explicitly preserves reader readiness and recovery ordering, distinguishes earlier production measurements from this patch, and makes no speedup claim; discussion contains no additional runtime demonstration. (e62b412867ab)
  • Exact-head validation state: Production types, lint, builds, and changed-boundary checks passed; several type checks and PostgreSQL conformance were still running, with the aggregate CI gate pending and no observed diff-caused failure. (e62b412867ab)
  • Policy applied: Read the complete root, Gateway, and docs AGENTS.md files and applied the test-value guidance; no additional ancestor policy or maintainer-notes directory exists for these paths. (AGENTS.md:1, e62b412867ab)

Likely related people:

  • Peter Steinberger: Raw commit 6ffbf91 adds src/gateway/server-startup-observers.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6ffbf9102e59; files: src/gateway/server-startup-observers.ts)
  • Vincent Koc: Raw commit dbac2c1 adds src/gateway/server-startup-trace.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: dbac2c10809f; files: src/gateway/server-startup-trace.ts)

PR surface

Source +42, Tests +97, Docs +7. Total +146 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 72 30 +42
Tests 2 97 0 +97
Docs 1 11 4 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 180 34 +146

Labels

Label changes:

  • add P3: This is a bounded operator-diagnostics improvement without a change to recovery scheduling or user-data behavior.
  • 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:

  • P3: This is a bounded operator-diagnostics improvement without a change to recovery scheduling or user-data behavior.
  • 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 16, 2026, 11:33 AM ET / 15:33 UTC.

@steipete
steipete merged commit ed06da1 into main Oct 16, 2026
135 of 137 checks passed
@steipete
steipete deleted the steipete/perf-micro-subagent-recovery-variance-20260919 branch October 16, 2026 15:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Include bounded reader, delivery, blocked-notice, retry-wait, exec, registry-load and activation durations in the normal recovery completion line. Preserve recovery ordering and reader readiness while making production startup waits attributable without verbose tracing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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