Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(7A): add onApiError seam for Lane A's breaker error-storm trip

Chaitanya Giri8c1a5cddb694
diff --git a/src/main/telemetry.ts b/src/main/telemetry.ts
index df3efd61..2b71fcc3 100644
--- a/src/main/telemetry.ts
+++ b/src/main/telemetry.ts
@@ -134,6 +134,9 @@ export class TelemetryCollector {
private readonly spans = new Map<string, ToolSpan[]>();
/** Push subscribers (Lane A breaker + dashboard). */
private readonly usageSubs = new Set<(s: AgentUsageSample) => void>();
+ /** api_error subscribers — feeds Lane A's breaker error-storm trip (#6), which
+ * has no input source of its own (hook payloads don't expose api errors). */
+ private readonly apiErrorSubs = new Set<(agentId: string) => void>();
constructor(opts: TelemetryCollectorOptions = {}) {
this.host = opts.host ?? '127.0.0.1';
@@ -186,6 +189,14 @@ export class TelemetryCollector {
return () => this.usageSubs.delete(cb);
}
+ /** In-process api_error feed for Lane A's breaker (#6). At integration:
+ * `telemetry.onApiError((agentId) => breaker.recordError(agentId))`. Returns
+ * an unsubscribe fn. */
+ onApiError(cb: (agentId: string) => void): () => void {
+ this.apiErrorSubs.add(cb);
+ return () => this.apiErrorSubs.delete(cb);
+ }
+
/** Recent tool spans for the per-agent waterfall (#7B.2), oldest→newest. */
getSpans(agentId: string): ToolSpan[] {
return this.spans.get(agentId)?.slice() ?? [];
@@ -325,6 +336,7 @@ export class TelemetryCollector {
if (ring?.length) ring[ring.length - 1].decision = decision;
} else if (name === 'api_error' || (name && name.includes('error'))) {
const error = str(attrs['error']) || str(attrs['message']) || name;
+ for (const cb of this.apiErrorSubs) { try { cb(agentId); } catch { /* subscriber threw */ } }
this.emit?.('telemetry:event', { kind: 'api_error', agentId, sessionId, ts: Date.now(), error } satisfies TelemetryEvent);
}
}