Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/opencode/src/altimate/observability/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,25 @@ export class FileExporter implements TraceExporter {
}

async export(trace: TraceFile): Promise<string | undefined> {
let tmpPath: string | undefined
try {
await fs.mkdir(this.dir, { recursive: true })
// Sanitize sessionId for safe file name (defense-in-depth — also sanitized in Trace)
const safeId = (trace.sessionId ?? "unknown").replace(/[/\\.:]/g, "_") || "unknown"
const filePath = path.join(this.dir, `${safeId}.json`)
await fs.writeFile(filePath, JSON.stringify(trace, null, 2))
// Atomic write: write to temp file, then rename — prevents partial reads
// when concurrent snapshots or exports target the same file
tmpPath = filePath + `.tmp.${Date.now()}.${Math.random().toString(36).slice(2, 8)}`
await fs.writeFile(tmpPath, JSON.stringify(trace, null, 2))
await fs.rename(tmpPath, filePath)

if (this.maxFiles > 0) {
this.pruneOldTraces().catch(() => {})
}

return filePath
} catch {
if (tmpPath) fs.unlink(tmpPath).catch(() => {})
return undefined
}
}
Expand Down
Loading