Repository navigation
Commit 0957fd8
fix(tracing): address consensus review of PR #867
Addresses the consensus code review of #867 (6 reviewers, 4 of 5 successful
externals + Claude flagged the same critical bug at MAJOR/CRITICAL).
CRITICAL fix — per-session crash tracking on FileExporter
The original PR put `_crashed` as instance state on FileExporter. In the
TUI worker (worker.ts:58-74,96-97), a single FileExporter is cached and
shared across every session — the spread `[...tracingExporters]` copies
the array, not the inner objects, and `Trace.withExporters` only allocates
a fresh FileExporter when `options.maxFiles != null` (rarely set in user
config). One session's flushSync would permanently mark the shared
exporter crashed, silently suppressing endTrace exports for every
subsequent session in the worker — a worse regression than the bug the
original PR was fixing.
Refactor: `private crashedSessions = new Set<string>()` on FileExporter,
with `markCrashed(sessionId: string)`. Export checks
`crashedSessions.has(trace.sessionId)` at all three checkpoints. The
guard now scopes to the actual crashing trace, not the shared instance.
Regression test in tracing-rename-race.test.ts: shared FileExporter,
Trace A flushSync, Trace B endTrace — asserts B's file lands with
status:"completed". Would have caught the original regression.
MAJOR fix — endTrace return value after flushSync
`endTrace()` short-circuits at entry when `this.crashed` is set and
returns `getTracePath()` instead of letting export() bail and returning
undefined. Restores the API contract that endTrace returns a usable file
path whenever the canonical file exists. Adopts the "crash wins
everywhere" policy — once flushSync has fired, the crashed write is
authoritative across all exporters; no further exports run.
MAJOR fix — TraceExporter interface adds optional markCrashed
Replaces the `instanceof FileExporter` dispatch in flushSync with a
polymorphic `exp.markCrashed?.(this.sessionId)`. Adds optional
`markCrashed?(sessionId: string): void` to the TraceExporter interface.
Custom exporters with canonical-file semantics can now participate in
the crash guard without modifying Trace. Drops the brittle instanceof
check that broke if FileExporter was ever subclassed or duplicated
across module boundaries.
Minor fixes (PR-introduced issues only)
- flush() now drains M2 follow-up snapshots (bounded loop, 16 iters max)
so callers see disk == memory after it returns. The previous version
only awaited the current promise; a queued follow-up would land after
flush() resolved.
- Microtask-ordering invariant documented inline at endTrace entry —
explains why setting endTraceStarted before the await is airtight.
- Test afterEach safety guard restores fs.rename even if a prior test
panicked mid-patch, preventing cross-file leakage of the patched fn.
- Misleading comment in M2 deterministic test (claimed "no follow-up
scheduled") updated to reflect post-fix behavior.
- FileExporter naming: `_crashed` → `crashedSessions` (drops the
inconsistent underscore prefix; the bare-name style matches Trace.crashed).
- markCrashed docstring clarified: "bail at the next checkpoint" rather
than overclaiming retroactive cancellation.
Tests:
- 366 pass (added shared-FileExporter regression test); 0 fail in the
tracing suite. Full opencode suite has only pre-existing unrelated
failures (tool.registry, sql_analyze, E2E validators).
Pre-existing issue noted but NOT fixed in this commit:
- `Trace.withExporters` mutates the caller's array (tracing.ts:413-414).
GLM-5.1 surfaced this during review. It's pre-existing code (not
introduced by this PR series) and unrelated to the M2/M3 fixes. Filing
as a follow-up.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 20bfcd9 commit 0957fd8
3 files changed
Lines changed: 132 additions & 32 deletions
File tree
- packages/opencode
- src/altimate/observability
- test/altimate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
151 | 160 | | |
152 | 161 | | |
153 | 162 | | |
| |||
165 | 174 | | |
166 | 175 | | |
167 | 176 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
177 | 193 | | |
178 | 194 | | |
179 | 195 | | |
| |||
183 | 199 | | |
184 | 200 | | |
185 | 201 | | |
186 | | - | |
187 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
188 | 205 | | |
189 | 206 | | |
190 | 207 | | |
| |||
198 | 215 | | |
199 | 216 | | |
200 | 217 | | |
201 | | - | |
| 218 | + | |
202 | 219 | | |
203 | 220 | | |
204 | 221 | | |
205 | 222 | | |
206 | 223 | | |
207 | | - | |
| 224 | + | |
208 | 225 | | |
209 | 226 | | |
210 | 227 | | |
| |||
858 | 875 | | |
859 | 876 | | |
860 | 877 | | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
865 | 883 | | |
866 | 884 | | |
867 | | - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
868 | 898 | | |
869 | 899 | | |
870 | 900 | | |
| |||
939 | 969 | | |
940 | 970 | | |
941 | 971 | | |
942 | | - | |
943 | | - | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
944 | 983 | | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
945 | 990 | | |
946 | 991 | | |
947 | 992 | | |
| |||
1053 | 1098 | | |
1054 | 1099 | | |
1055 | 1100 | | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1059 | 1107 | | |
1060 | 1108 | | |
1061 | 1109 | | |
1062 | | - | |
1063 | | - | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
1064 | 1114 | | |
1065 | 1115 | | |
1066 | 1116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| |||
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
156 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
| |||
387 | 394 | | |
388 | 395 | | |
389 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
390 | 440 | | |
391 | 441 | | |
392 | 442 | | |
| |||
0 commit comments