Skip to content

Commit ecc7001

Browse files
anandgupta42claude
andcommitted
fix: address v0.8.6 release-review findings
Five-persona pre-release review of #886 (session traces in headless serve). No P0/HOLD; these are the actionable polish items: - trace-consumer.ts (flush): finalize sessions concurrently (Promise.allSettled) instead of sequentially. Each endTrace() can wait on an HttpExporter (5s timeout), so a sequential loop over N sessions could exceed a container's shutdown grace period and be SIGKILL'd mid-write. Now bounded to the slowest single trace. - trace-consumer.ts (reconnect): log the in-process stream reconnect at debug, not warn — it's automatic and not user-actionable, and warn-per-backoff spiked log aggregators during an outage. - serve.ts: comment clarifying that subscribeTraceConsumer's `directory` is the SDK workspace context, not the trace output dir (flagged by 4 reviewers). - docs: ide.md now lists session tracing as an IDE feature; trace.md crash- recovery notes that `serve` (not just `run`) finalizes traces on shutdown. Deferred (filed): #915 (container trace persistence), #916 (serve trace-dir startup log). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ed1eecd commit ecc7001

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

docs/docs/configure/trace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Traces are designed to survive process crashes:
325325

326326
2. **Incremental snapshots.** After every tool call and generation completion, the trace file is updated atomically (write to temp file, then rename). The file on disk always contains a valid, complete JSON document.
327327

328-
3. **Crash handlers.** The `run` command registers `SIGINT`/`SIGTERM`/`beforeExit` handlers that flush the trace synchronously with a `"crashed"` status.
328+
3. **Crash handlers.** The `run` and `serve` commands register `SIGINT`/`SIGTERM`/`beforeExit` handlers that finalize in-flight traces on shutdown. (`run` flushes synchronously with a `"crashed"` status; `serve` drains and finalizes its active sessions.)
329329

330330
4. **Status indicators.** Trace status tells you exactly what happened:
331331

docs/docs/usage/ide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This opens the Altimate Code chat panel where you can interact with altimate age
3939
- **Tool call results inline** — SQL analysis, lineage, dbt operations, and more displayed in the chat
4040
- **Agent mode switching** — switch between Builder (full read/write), Analyst (read-only), and Plan (minimal access) modes from the command palette
4141
- **100+ data engineering tools** — SQL validation, query optimization, column lineage, dbt model generation, FinOps analysis, schema exploration, and more
42+
- **Session tracing** — every chat session is recorded as a trace file (the IDE panel runs `altimate-code serve` under the hood, which now writes traces just like the terminal). Inspect them with `altimate-code trace list` / `altimate-code trace view <id>`. See [Traces](../configure/trace.md).
4243

4344
## Configuration
4445

packages/opencode/src/altimate/observability/trace-consumer.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,17 @@ export class TraceConsumer {
309309
this.sessionUserMsgIds.clear()
310310
}
311311

312-
/** End all in-flight traces and wait for them. Used on shutdown. */
312+
/**
313+
* End all in-flight traces and wait for them. Used on shutdown.
314+
* Finalizes sessions concurrently rather than sequentially: each
315+
* `endTrace()` can wait on an HttpExporter (5s timeout each), so a sequential
316+
* loop over N sessions could take N×5s and blow past a container's shutdown
317+
* grace period (e.g. k8s `terminationGracePeriodSeconds`) and be SIGKILL'd
318+
* mid-write. Concurrent finalization bounds the wall-clock to the slowest
319+
* single trace.
320+
*/
313321
async flush() {
314-
for (const [, trace] of this.sessionTraces) {
315-
await trace.endTrace().catch(() => {})
316-
}
322+
await Promise.allSettled([...this.sessionTraces.values()].map((trace) => trace.endTrace().catch(() => {})))
317323
this.sessionTraces.clear()
318324
this.sessionUserMsgIds.clear()
319325
}
@@ -410,7 +416,11 @@ export function subscribeTraceConsumer(
410416
}
411417
} catch (err) {
412418
if (!signal.aborted) {
413-
Log.Default.warn("[tracing] trace event stream disconnected, reconnecting", {
419+
// debug, not warn: this is the in-process event stream, reconnect is
420+
// automatic and not user-actionable. Logging at warn on every backoff
421+
// iteration (up to ~7 in the first 8s of an outage) would spike log
422+
// aggregators for something the operator can't act on.
423+
Log.Default.debug("[tracing] trace event stream ended, reconnecting", {
414424
error: err instanceof Error ? err.message : String(err),
415425
})
416426
}

packages/opencode/src/cli/cmd/serve.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export const ServeCommand = cmd({
2929
// serve mode. Subscribe the shared trace consumer to the in-process
3030
// event stream so serve sessions produce the same trace files as the
3131
// terminal entrypoints.
32+
//
33+
// `directory` is the SDK workspace/routing context, NOT the trace output
34+
// location — trace files always go to the configured tracing dir
35+
// (`tracing.dir`, default ~/.local/share/altimate-code/traces/).
3236
const traceSub = subscribeTraceConsumer({ directory: process.cwd() })
3337

3438
// Finalize traces on shutdown. `serve` blocks forever on the promise below

0 commit comments

Comments
 (0)