fix(tracing): harden operation scene request lifecycle
Problem
The operation detail scene relies only on kea breakpoints to discard stale results — superseded ClickHouse queries keep running server-side (unlike tracingDataLogic, which aborts them). It also transfers span attribute maps it never renders, refetches a trace the pager already has when adjacent samples share one, leaves a permanently blank waterfall when a samples refetch fails, fires queries for links missing the service param, and leaves clear-selection buttons clickable while the refetch they trigger is in flight.
Changes
- Each loader carries a tracked
AbortController(via the disposables plugin, withpauseOnPageHidden: false) that aborts the superseded request on re-issue and whatever is in flight on unmount; abort-driven failures are excluded from error toasts via the sharedisUserInitiatedError. - The samples query passes
excludeAttributes— the scene reads only scalar span fields; the waterfall loads the full trace separately. - A shared
loadCurrentSampleTraceaction reuses the loaded waterfall when the target sample lives in the same trace, and reloads it after a failed samples refetch so the scene stays usable. - Links missing the service param render the missing-params fallback without firing the mount queries.
- Clear-selection buttons disable while a samples fetch is in flight, per the double-submission rule.
api.tracing.getTraceaccepts anAbortSignal;listSpansgains the (already backend-supported)excludeAttributesparam.
How did you test this code?
tracingOperationSceneLogic.test.ts and tracingDataLogic.test.ts pass locally (29 tests), including the drag-selection refetch and sample-paging regressions, with assertions updated for the new signal argument.
Automatic notifications
- [ ] Publish to changelog?
- [ ] Alert Sales and Marketing teams?
Docs update
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Built with PostHog Code (Claude); /using-kea-disposables invoked for the AbortController pattern, /writing-tests for the assertion updates. Part of a set of small PRs split from the too-broad #71484 (now closed). This is the largest of the set because the abort, reuse, and failure-recovery paths all rewrite the same loader/listener blocks and can't be separated without conflicts.
Created with PostHog Code
🤖 CI report
✅ Bundle size — 🟢 -12.8 KiB (-0.0%)
Uncompressed size of every built .js bundle, compared against the base branch.
Total: 64.78 MiB · 🟢 -12.8 KiB (-0.0%)
| File | Size | Δ vs base |
|---|---|---|
posthog-app/_parent/products/tracing/frontend/TracingScene.js |
84.7 KiB | 🟢 -13.4 KiB (-13.7%) |
Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report
✅ Eager graph — within budget
How much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy import() / React.lazy chunks are not counted.
| Root | Eager (shipped) | Δ vs base | Budget |
|---|---|---|---|
entry (logged-out pages, app bootstrap)src/index.tsx |
1.22 MiB · 22 files | no change | ███░░░░░░░ 28.4% of 4.29 MiB |
authenticated shell (every logged-in page)src/scenes/AuthenticatedShell.tsx |
8.14 MiB · 2,981 files | 🔺 +11 B (+0.0%) | █████████░ 87.9% of 9.25 MiB |
🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
Largest files eagerly shipped from src/index.tsx
| Size | File |
|---|---|
| 126.8 KiB | ../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.production.min.js |
| 24.6 KiB | ../node_modules/.pnpm/[email protected]/node_modules/buffer/index.js |
| 6.3 KiB | ../node_modules/.pnpm/[email protected]/node_modules/react/cjs/react.production.min.js |
| 4.5 KiB | ../node_modules/.pnpm/@[email protected]/node_modules/@jspm/core/nodelibs/browser/process.js |
| 3.9 KiB | ../node_modules/.pnpm/[email protected]/node_modules/scheduler/cjs/scheduler.production.min.js |
| 1.4 KiB | ../node_modules/.pnpm/[email protected]/node_modules/base64-js/index.js |
| 1.3 KiB | src/RootErrorBoundary.tsx |
| 912 B | ../node_modules/.pnpm/[email protected]/node_modules/ieee754/index.js |
| 789 B | src/scenes/ChunkLoadErrorBoundary.tsx |
| 762 B | src/index.tsx |
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
| Size | File |
|---|---|
| 281.3 KiB | ../node_modules/.pnpm/[email protected]/node_modules/posthog-js/dist/rrweb.js |
| 267.7 KiB | ../node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@posthog/icons/dist/posthog-icons.es.js |
| 235.5 KiB | src/taxonomy/core-filter-definitions-by-group.json |
| 222.9 KiB | ../node_modules/.pnpm/[email protected]/node_modules/posthog-js/dist/module.js |
| 164.0 KiB | src/queries/validators.js |
| 154.3 KiB | ../node_modules/.pnpm/[email protected]/node_modules/re2js/build/index.esm.js |
| 126.8 KiB | ../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.production.min.js |
| 105.8 KiB | src/lib/api.ts |
| 93.3 KiB | ../node_modules/.pnpm/[email protected]/node_modules/prosemirror-view/dist/index.js |
| 92.7 KiB | ../packages/quill/packages/quill/dist/index.js |
Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479
✅ Dist folder size — 🔺 +6.5 KiB (+0.0%)
Total size of the built frontend/dist folder (all assets), compared against the base branch.
Total: 1316.42 MiB · 🔺 +6.5 KiB (+0.0%)
🦔 Hogbox preview · ✅ ready
▶ Open the preview
| 🔑 Login | [email protected] / 12345678 (demo data) |
| 🧩 Running | this PR's backend and frontend, on the PostHog :master base |
| 🔗 Link | stable across rebuilds — a re-push swaps the box underneath, the URL stays |
| 🔒 Access | tailnet only (PostHog VPN) |
| 🛠️ Admin | inspect & debug state in hogland |
| 💤 Idle | sleeps after ~30 min idle (snapshot to S3, zero node cost) and wakes on your next visit in ~30s, behind a brief "waking up" screen |
commit 566a35f · box box-e6c0c5ef0a2c · ready in 834s (push → usable) · build log · rebuilds on every push, torn down on close
Reviews (1): Last reviewed commit: "fix(tracing): harden operation scene req..." | Re-trigger Greptile
[!NOTE] 🤖 stamphog reviewed
e1b3f4a748537a351eeb8875c4355230840579b4— verdict: REFUSED
Two unresolved P1 Greptile findings on tracingOperationSceneLogic.ts describe real correctness gaps this diff doesn't cover: a failed samples refetch can leave the waterfall blank when the restored sample index falls outside the retained set, and the trace-reuse shortcut can match on trace_id alone and select a span not actually present in the cached trace data.
- Author wrote 96% of the modified lines and has 95 merged PRs in these paths (familiarity STRONG).
- greptile-apps[bot] reviewed the current head.
- Unresolved @greptile-apps P1 comment on tracingOperationSceneLogic.ts: failed samples refetch can leave the waterfall blank because loadCurrentSampleTrace no-ops if the restored sampleIndex resolves to a null currentSample.
- Unresolved @greptile-apps P1 comment on tracingOperationSceneLogic.ts: the trace-reuse check (matching sampleTraceSpans[0].trace_id) can select a span absent from the loaded trace when two same-trace samples are more than an hour apart, since traceLookupDateRange's window may not cover both.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 175L, 5F substantive, 180L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1c-medium (180L, 6F, two-areas, fix) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ 800cd6f · reviewed head e1b3f4a |
Looking at the full file, both P1 findings are real. Here's the diagnosis and concrete fixes:
P1 #1 — Invalid index after failed refetch (line ~231)
When fetchSamples fails, kea retains the old samples value, but the sampleTraceSpans reducer resets to [] (line 159: sampleTraceSpans: { fetchSamples: () => [] }). Browser navigation via urlToAction can update sampleIndex to any value even while loading is in flight (because the setSampleIndex listener correctly defers to fetchSamplesSuccess/fetchSamplesFailure when samplesLoading is true). So after a failure, sampleIndex could be 5 while samples still has 3 items → currentSample is null → loadCurrentSampleTrace no-ops → waterfall stays blank despite valid retained samples.
Fix — clamp the index before delegating:
fetchSamplesFailure: ({ error }) => {
if (isUserInitiatedError(error)) {
return
}
lemonToast.error(`Failed to load sample traces: ${error}`)
// The failed refetch already blanked the waterfall (see the sampleTraceSpans reducer);
// reload the trace for the retained samples so the scene stays usable.
// If the index is now out of range (e.g. browser-nav changed it while the
// doomed request was in flight), reset to 0 so currentSample is never null.
if (values.samples.length > 0 && values.sampleIndex >= values.samples.length) {
actions.setSampleIndex(0)
} else {
actions.loadCurrentSampleTrace()
}
},
(setSampleIndex will call loadCurrentSampleTrace from its own listener once samplesLoading is false, which it will be by the time fetchSamplesFailure runs.)
P1 #2 — Trace-ID reuse selects absent span (line ~191)
traceLookupDateRange(sample.timestamp) builds a ±1 h window around one sample's timestamp. If a second same-trace sample is >1 h away, the cached sampleTraceSpans was fetched with a window that doesn't cover it — the span simply isn't in the array. Matching sampleTraceSpans[0]?.trace_id === sample.trace_id then skips the reload and calls selectSpan for a span ID that doesn't exist in the loaded data.
The Greptile suggestion in the inline thread is the right fix — check span presence, not trace membership:
if (values.sampleTraceSpans.some((span) => span.span_id === sample.span_id)) {
actions.selectSpan(sample.span_id)
return
}
This is strictly correct: if the span is already in the loaded trace, reuse it; otherwise refetch. The common case (adjacent samples in a short-lived trace) still avoids the network round-trip.
👋 Visual changes detected for this PR.
Review and approve in PostHog Visual Review
If these changes are unexpected, they may be caused by a flaky test or a broken snapshot on master. Don't approve — rerun the job or wait for a fix.