oc-metricboard 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/collector.ts +17 -3
- package/src/session-hydration.ts +7 -1
package/package.json
CHANGED
package/src/collector.ts
CHANGED
|
@@ -303,14 +303,28 @@ export function createCollector(
|
|
|
303
303
|
return { rootID: requestedSessionID, ids: requestedIDs }
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
function aggregateByModel(
|
|
306
|
+
function aggregateByModel(
|
|
307
|
+
ids: readonly string[],
|
|
308
|
+
now: number,
|
|
309
|
+
scope: MetricsScope,
|
|
310
|
+
rootID: string,
|
|
311
|
+
foregroundTurnStart: number,
|
|
312
|
+
): ModelMetrics[] {
|
|
307
313
|
// Group requests by (modelID, providerID) — one row per distinct model
|
|
308
|
-
// across all sub-agent sessions, with a ×N session count.
|
|
314
|
+
// across all sub-agent sessions, with a ×N session count. Apply the same
|
|
315
|
+
// foreground-turn membership filter as the token totals: a session whose
|
|
316
|
+
// last turn predates the foreground turn (e.g. a model the user switched
|
|
317
|
+
// away from hours ago) would otherwise linger as a stale zombie row that
|
|
318
|
+
// is absent from the aggregate totals.
|
|
309
319
|
const modelGroups = new Map<string, RequestMetrics[]>()
|
|
310
320
|
|
|
311
321
|
for (const id of ids) {
|
|
312
322
|
const request = state.requests.get(id)
|
|
313
323
|
if (!request) continue
|
|
324
|
+
const turn = state.turns.get(id)
|
|
325
|
+
const belongsToForegroundTurn = id === rootID
|
|
326
|
+
|| Boolean(turn && (turn.turnStartTime >= foregroundTurnStart || !turn.isComplete))
|
|
327
|
+
if (!belongsToForegroundTurn) continue
|
|
314
328
|
|
|
315
329
|
// Key: modelID|providerID (model-grouped, not per-session)
|
|
316
330
|
const key = `${request.modelID}|${request.providerID}`
|
|
@@ -557,7 +571,7 @@ export function createCollector(
|
|
|
557
571
|
}
|
|
558
572
|
|
|
559
573
|
// NEW: Build per-model breakdown for tree scope
|
|
560
|
-
const modelBreakdown = scope === "tree" ? aggregateByModel(ids, now, scope) : []
|
|
574
|
+
const modelBreakdown = scope === "tree" ? aggregateByModel(ids, now, scope, rootID, foregroundTurnStart) : []
|
|
561
575
|
// Turn-level TTFT: opencode stamps step.started at the first token, so
|
|
562
576
|
// intra-turn steps cannot measure their own request start (they would
|
|
563
577
|
// collapse to ~0). Anchor TTFT to the turn's user message instead —
|
package/src/session-hydration.ts
CHANGED
|
@@ -235,6 +235,7 @@ export async function hydrateSession(input: HydrateSessionInput): Promise<boolea
|
|
|
235
235
|
await input.api.client.session.status({ id: input.sessionID }),
|
|
236
236
|
input.sessionID,
|
|
237
237
|
))
|
|
238
|
+
log(`hydrate session=${input.sessionID.slice(0, 8)} status='${sessionStatus}'`)
|
|
238
239
|
const shouldReuseExisting = existing?.messageID === assistant.messageID
|
|
239
240
|
|
|
240
241
|
const current = shouldReuseExisting ? existing : createFreshMetrics(
|
|
@@ -287,7 +288,12 @@ export async function hydrateSession(input: HydrateSessionInput): Promise<boolea
|
|
|
287
288
|
applyAssistantTokens(stepMetrics, step.tokens)
|
|
288
289
|
retireRequestIntoTurn(turn, stepMetrics)
|
|
289
290
|
}
|
|
290
|
-
|
|
291
|
+
// Turn completion: the session-status lookup is unreliable across host SDK
|
|
292
|
+
// dialects (may resolve to an unrecognizable shape → status ''). The last
|
|
293
|
+
// assistant message's own completed flag is authoritative: if it finished,
|
|
294
|
+
// its turn is over. An in-flight resumed message (completed=false) keeps
|
|
295
|
+
// the turn open.
|
|
296
|
+
if (sessionStatus === "idle" || current.isComplete) completeTurn(turn, completedTime ?? input.now)
|
|
291
297
|
input.state.turns.set(input.sessionID, turn)
|
|
292
298
|
|
|
293
299
|
// Write-point race guard: the checks above ran before several awaits. By
|