Skip to content

Commit 87562bf

Browse files
VJ-yadavanandgupta42
authored andcommitted
fix: address coderabbit + cubic review comments
- trace.ts:172-173 (coderabbit): switch pagination fallbacks from || to ?? so an explicit --offset 0 / --limit 0 reaches listTracesPaginated() for clamping, rather than being swallowed as falsy and replaced with defaults. The API already clamps limit<1 to 1, so --limit 0 now routes through that clamp path correctly. - tracing.test.ts:746 (cubic): create a fresh Trace instance per iteration inside seedTraces() rather than reusing a single tracer. Reusing a tracer across startTrace/endTrace cycles accumulates spans in memory across iterations. Matches the pattern used by the maxFiles test.
1 parent fb93606 commit 87562bf

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎packages/opencode/src/cli/cmd/trace.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ export const TraceCommand = cmd({
168168
const tracesDir = (cfg as any).tracing?.dir as string | undefined
169169

170170
if (action === "list") {
171+
// Use nullish coalescing so an explicit 0 is preserved and reaches
172+
// listTracesPaginated() for clamping. `args.offset || 0` would
173+
// treat `--offset 0` as unset (no semantic change, harmless), but
174+
// `args.limit || 20` would promote `--limit 0` to 20 instead of
175+
// letting the API clamp it to 1.
171176
const page = await Trace.listTracesPaginated(tracesDir, {
172-
offset: args.offset || 0,
173-
limit: args.limit || 20,
177+
offset: args.offset ?? 0,
178+
limit: args.limit ?? 20,
174179
})
175180
listTraces(page.traces, page, tracesDir)
176181
return

‎packages/opencode/test/altimate/tracing.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,16 @@ describe("Recap — static helpers", () => {
742742
// ---------------------------------------------------------------------------
743743

744744
describe("Recap.listTracesPaginated", () => {
745-
// Seed a known set of traces in a fresh directory for each test
745+
// Seed a known set of traces in a fresh directory for each test.
746+
// A fresh tracer is created per iteration so spans don't accumulate
747+
// across startTrace/endTrace cycles — matches the pattern used
748+
// elsewhere in this file (see the maxFiles test above).
746749
async function seedTraces(count: number, dir: string): Promise<void> {
747-
const exporter = new FileExporter(dir)
748-
const tracer = Recap.withExporters([exporter])
749750
for (let i = 0; i < count; i++) {
751+
const tracer = Recap.withExporters([new FileExporter(dir)])
750752
tracer.startTrace(`session-${String(i).padStart(4, "0")}`, {
751753
prompt: `prompt-${i}`,
752754
})
753-
// Tiny delay to guarantee distinct mtimes where relevant
754755
await tracer.endTrace()
755756
}
756757
}

0 commit comments

Comments
 (0)