Repository navigation
perf(logging): reuse prepared diagnostic facts - #133659
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:27 PM ET / August 31, 2026, 00:27 UTC. ClawSweeper reviewWhat this changesThe PR removes avoidable diagnostic bookkeeping by reusing direct session matches, delaying bounded-label formatting, and iterating registered owners without temporary arrays. Merge readinessKeep open. The three introduced optimizations preserve the diagnostic alias, owner-identity, and exact-run checks; no blocking correctness or security defect was found. This fresh maintainer-owned PR still contributes behavior-neutral performance work not present on current main. Priority: P3 Review scores
Verification
How this fits togetherDiagnostic logging receives session and run lifecycle events and maintains process-local activity state for liveness warnings and stuck-session recovery. The changed code turns that state into bounded operator-facing work labels while retaining owner and alias reconciliation. flowchart LR
A[Session and run events] --> B[Diagnostic activity owner]
A --> C[Session state registry]
B --> D[Activity snapshot]
C --> E[Diagnostic snapshot builder]
D --> E
E --> F[Bounded labels and counts]
F --> G[Liveness and recovery diagnostics]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1. Total +1 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain the direct-owner and bounded-formatting optimizations, with the existing alias and shared-owner lifecycle coverage guarding semantic equivalence. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes internal diagnostic bookkeeping rather than reporting a user-facing failure; source and existing tests expose the relevant state transitions. Is this the best way to solve the issue? Yes. The patch removes repeated temporary work at the owning diagnostic paths while preserving the existing alias reconciliation and exact-owner/run predicates. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cf25af4699bf. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Diagnostic bookkeeping repeated work even when its owner already had the needed facts: an exact session key/id match still scanned all states, bounded labels formatted strings that were discarded, and model/run handlers copied every owner registration before looking for a match.
This keeps preparation at the existing owners. Exact canonical identity hits reuse the direct lookup; changed-id and alias paths retain the existing merge flow. Label construction moves behind the five-label cap, while every activity lookup still runs in the original order because it reconciles aliases. Owner checks iterate the authoritative Map directly, and run completion still requires the exact run id as well as activity identity. There is no new cache, index, configuration, public API, protocol, storage, or authorization policy. The old formatting helper and temporary owner arrays are removed.
These are three measured mechanisms. Production is +33/−32 lines (net +1); tests are unchanged. The final production ASTs match the measured proposals after formatting. The one-line increase retains an explicit canonical-identity invariant and ordinary loops compatible with the repository's TypeScript target.
All 130 existing diagnostic, activity, core model-request, loop-admission, and command-poll tests passed on baseline and candidate. Full
pnpm check:changedpassed, including production/test typechecks, lint, Knip, database guards and zero runtime import cycles. Independent source review and managed review found no actionable defects. The first baseline invocation named a nonexistent test path; that failed invocation is retained separately from the corrected successful run.The saved complete-owner differential corpus passed 1,208 scenarios and 4,832 comparisons, plus 180,000 producer-invariant checks. A reviewer-requested supplement adds 24 shared-owner/alias scenarios and 96 comparisons, covering different run ids sharing one activity, exact-owner closure and later completion. Existing shared-activity completion behavior is preserved; this does not claim to repair broader completion cleanup.
Ten fresh forward/reverse timing processes cover 73 fixed workloads, 6,570 raw samples and 730 independently recomputed medians. At 64/512 states, a last exact identity lookup drops from roughly 0.34/2.67 µs to 0.015 µs by avoiding the scan. ID-only lookup retains its existing scan. Larger bounded-label snapshots take roughly 9–17% less elapsed time; owner event processing improves at 64/512 registrations. All empty, small, ID-only and completion-miss costs remain in the evidence rather than being omitted.
Measurements cover the complete local state, snapshot and event owners with declared unrelated configuration/logger/runtime boundaries, not whole-Gateway, live-provider, heartbeat, recovery or memory performance. Current-main source checks find the same relevant owners and dependencies; the only broad manifest drift is the already-reviewed fast-uri lockfile update, which is outside this compiled graph. Existing documentation and operator-visible behavior remain unchanged.