Skip to content

Commit c708ed0

Browse files
anandgupta42claude
andcommitted
fix: address PR review comments
- Keep `traceViewerTracesDir` in sync on every URL request, not just on first server creation (app.tsx) - Reset per-session trace state (`sessionTraces`, `sessionUserMsgIds`) when restarting the event stream in worker.ts - Fix "traceFile" variable-style wording in test file comments to use natural language ("trace file", "trace viewer", "trace list") Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8c150f commit c708ed0

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ import fsAsync from "fs/promises"
4040
let traceViewerServer: ReturnType<typeof Bun.serve> | undefined
4141
let traceViewerTracesDir: string | undefined
4242
function getTraceViewerUrl(sessionID: string, tracesDir?: string): string {
43+
// Always update the traces dir so subsequent calls with a new tracesDir
44+
// don't serve stale paths from the initial server creation.
45+
traceViewerTracesDir = Trace.getTracesDir(tracesDir)
46+
4347
if (!traceViewerServer) {
44-
traceViewerTracesDir = Trace.getTracesDir(tracesDir)
4548
traceViewerServer = Bun.serve({
4649
port: 0, // random available port
4750
hostname: "127.0.0.1",

packages/opencode/src/cli/cmd/tui/worker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ function getOrCreateTrace(sessionID: string): Trace | null {
108108

109109
const startEventStream = (input: { directory: string; workspaceID?: string }) => {
110110
if (eventStream.abort) eventStream.abort.abort()
111+
// Clear stale per-stream trace state before starting a new stream instance
112+
for (const [, trace] of sessionTraces) {
113+
void trace.endTrace().catch(() => {})
114+
}
115+
sessionTraces.clear()
116+
sessionUserMsgIds.clear()
117+
111118
const abort = new AbortController()
112119
eventStream.abort = abort
113120
const signal = abort.signal

packages/opencode/test/altimate/tracing-adversarial-snapshot.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Each test targets a specific code path or race condition found during
66
* line-by-line audit of snapshot(), buildTraceFile(), worker.ts tracing,
7-
* and the live traceFile viewer.
7+
* and the live trace viewer.
88
*/
99

1010
import { describe, expect, test, beforeEach, afterEach } from "bun:test"

packages/opencode/test/altimate/tracing-de-attributes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Tests for data engineering domain-specific traceFile attributes.
2+
* Tests for data engineering domain-specific trace file attributes.
33
*
44
* Verifies that:
55
* 1. Domain attributes are purely optional — traces work without them

packages/opencode/test/altimate/tracing-display-crash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Tests for traceFile list display, title handling, formatting utilities,
2+
* Tests for trace list display, title handling, formatting utilities,
33
* flushSync crash recovery, initial snapshot, and sorting.
44
*
55
* These test the latest additions that were previously uncovered.

packages/opencode/test/altimate/tracing-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*
44
* These tests simulate real agent sessions — not mocked — to verify:
55
* 1. Incremental snapshots are written during a session (partial traces)
6-
* 2. The traceFile file is valid and complete at every point
6+
* 2. The trace file is valid and complete at every point
77
* 3. Concurrent sessions don't interfere with each other
88
* 4. Performance: tracing adds negligible overhead (<5ms per operation)
99
* 5. The TUI worker's tracing code doesn't crash on malformed events
10-
* 6. The traceFile viewer server works correctly
10+
* 6. The trace viewer server works correctly
1111
* 7. The full write→snapshot→read→render pipeline works end-to-end
1212
*/
1313

0 commit comments

Comments
 (0)