Python
merge(observability): OB-7 into Phase 2 (OB-3, OB-6, OB-13, OB-14)
Devika Verma16705681383e
diff --cc coworker/observability/engine_hooks.pyindex ca044980,47e0287b..8ba8a63a--- a/coworker/observability/engine_hooks.py+++ b/coworker/observability/engine_hooks.py@@@ -53,13 -54,7 +54,14 @@@ class TurnRecordingself._reserved: dict[str, dict[str, Any]] = {} # summary steps written at their end (E4)self._tokens_after_for: Optional[str] = None # a summary waiting for the next main callself._child_usage: dict[str, bool] = {} # parent step -> its model call reported usage+ self._explore_calls: dict[str, int] = {} # call_id -> 1st, 2nd… explore call of this turn (E6b)+ # Conditions on now (OB-14): name -> (since ms, attrs). They outlive turns; each turn+ # gets its own gap notice, cut at its start and end.+ self._conditions: dict[str, tuple[int, dict[str, Any]]] = {}+ self._turn_started_ms = self._turn_started_mono = 0+ from . import gaps++ gaps.register(self) # the recorder may be set later; conditions are kept meanwhile@propertydef enabled(self) -> bool:@@@ -103,8 -98,8 +105,9 @@@self._tool_ends.clear()self._reply_end = Noneself._waits.clear()+ self._explore_calls.clear()ev = self._base("turn_started", self.turn_id, self._turn_session)+ self._turn_started_ms, self._turn_started_mono = ev["at_ms"], ev["mono_ms"]ev.update({"kind": kind, "trigger": trigger, "first_message_id": first_message_id,"attrs": copy.deepcopy(attrs), "stamp": copy.deepcopy(stamp)})if wait_for_first_message:diff --cc surfaces/gui/src/components/StepsPanel.tsxindex 238ee0d5,76b8401f..ec30215b--- a/surfaces/gui/src/components/StepsPanel.tsx+++ b/surfaces/gui/src/components/StepsPanel.tsx@@@ -200,68 -186,59 +201,117 @@@ function nest(steps: RecordedStep[]):return out;}+ /** What the timeline draws (OB-7): a step; under an explore step, the summary row its+ * helper's steps fold behind; or a team worker's turn this turn woke. */+ export type TimelineRow =+ | { type: "step"; step: RecordedStep; depth: number }+ | { type: "helper"; step: RecordedStep; depth: number; open: boolean; children: RecordedStep[] }+ | { type: "worker"; worker: RecordedWorkerRow };++ /** The helper's summary line, "Helper 1 · 6 steps · 12.3k tokens · ok": from the explore step's+ * `attrs.helper` (1.2), or, while it runs or in an older recording, from its nested steps. */+ export function helperSummary(step: RecordedStep, children: RecordedStep[], t: T): string {+ const h = step.attrs?.helper;+ const count = h ? (h.model_calls || 0) + (h.tool_calls || 0) : children.filter((c) => c.kind === "model" || c.kind === "tool").length;+ const tokens = h ? h.tokens || 0 : children.reduce((n, c) => {+ const u = c.kind === "model" ? c.attrs?.usage : null;+ return u?.reported ? n + (u.input_fresh || 0) + (u.cache_read || 0) + (u.cache_write || 0) + (u.output || 0) : n;+ }, 0);+ const status = h?.status || step.status;+ return t("steps.helper.summary", {+ index: h?.index ?? 1, count, tokens: formatTokens(tokens),+ status: t(`steps.helper.status.${status}`, { defaultValue: status }),+ });+ }++ /** The timeline's rows: each explore step's helper steps folded behind a summary row unless+ * opened (TD2-19), and the turn's worker rows placed among the top-level steps by start. */+ export function timelineRows(steps: RecordedStep[], workers: RecordedWorkerRow[], open: Set<string>): TimelineRow[] {+ const nested = nest(steps);+ const out: TimelineRow[] = [];+ for (let i = 0; i < nested.length; i++) {+ const { step, depth } = nested[i];+ out.push({ type: "step", step, depth });+ if (step.kind !== "tool" || step.name !== "explore") continue;+ let j = i + 1;+ while (j < nested.length && nested[j].depth > depth) j++;+ const children = nested.slice(i + 1, j);+ if (!children.length && !step.attrs?.helper) continue;+ const isOpen = open.has(step.step_id);+ out.push({ type: "helper", step, depth: depth + 1, open: isOpen, children: children.map((c) => c.step) });+ if (isOpen) for (const c of children) out.push({ type: "step", step: c.step, depth: c.depth + 1 });+ i = j - 1;+ }+ for (const w of [...workers].sort((a, b) => a.started_at - b.started_at)) {+ // Before the first top-level step that started after the worker turn did.+ const at = out.findIndex((r) => r.type === "step" && r.depth === 0 && r.step.started_at > w.started_at);+ out.splice(at < 0 ? out.length : at, 0, { type: "worker", worker: w });+ }+ return out;+ }+const KIND_CLASS: Record<string, string> = {context: "ctx", model: "model", tool: "tool", wait: "wait", auto_approver: "review", summary: "sum", notice: "ctx",+ sandbox: "sbx",};+const GAPS = ["controller_offline", "nobody_watching", "clock_jump"];++/** A gap notice with a duration (OB-14): drawn as a dashed band, not a point. */+function isGap(step: RecordedStep): boolean {+ return step.kind === "notice" && GAPS.includes(step.name) && !!step.duration_ms;+}++/** The class of a row: a sandbox restart notice is drawn in the sandbox colour (mock ob13),+ * a gap as a dashed band (mock ob14). */+function kindClass(step: RecordedStep): string {+ if (step.kind === "notice" && step.name === "sandbox_restarted") return "sbx";+ if (isGap(step)) return "gap";+ return KIND_CLASS[step.kind] || "ctx";+}++/** A moment as the clock on the wall shows it, "14:02". */+function clockTime(ms: number): string {+ return new Date(ms).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });+}++/** How long the turn spent with the machine offline, or with nobody watching (mock ob14). */+function gapTotal(steps: RecordedStep[], name: string): number {+ return steps.filter((s) => s.kind === "notice" && s.name === name).reduce((n, s) => n + (s.duration_ms || 0), 0);+}++type SandboxStage = { name: string; started_at: number; duration_ms: number | null; status: string; uncertain?: boolean };++/** A sandbox setup step's stages as rows under it, in the order run (OB-13). An image pull+ * the provider cannot time is not a row of its own: it is said on the Create row. */+function StageRows({ step, depth, turn, total }: { step: RecordedStep; depth: number; turn: RecordedTurn; total: number }) {+ const { t } = useTranslation();+ const stages: SandboxStage[] = Array.isArray(step.attrs?.stages) ? step.attrs.stages : [];+ const pulled = stages.some((s) => s.name === "download_image" && s.uncertain);+ return (+ <>+ {stages.filter((s) => !(s.name === "download_image" && s.uncertain)).map((s, i) => {+ const left = Math.min(100, Math.max(0, ((s.started_at - turn.started_at) / total) * 100));+ const width = s.duration_ms ? Math.min(100 - left, (s.duration_ms / total) * 100) : 0;+ const name = t(`steps.sbx_stage.${s.name}`, { defaultValue: s.name }) + (s.name === "create" && pulled ? ` · ${t("steps.sbx_stage.image_maybe")}` : "");+ return (+ <div key={`${s.name}-${i}`} className="steps-row steps-stage k-sbx" data-testid="steps-stage">+ <span className="steps-label" style={{ paddingLeft: (depth + 1) * 16 }}>+ <span className="steps-kind" />+ <span className="steps-name">{name}</span>+ {s.status === "error" && <span className="steps-badge err">{t("steps.status.error")}</span>}+ </span>+ <span className="steps-track">+ <span className="steps-bar" style={{ left: `${left}%`, width: width ? `${width}%` : undefined }} />+ </span>+ <span className="steps-time">{formatDuration(s.duration_ms)}</span>+ </div>+ );+ })}+ </>+ );+}+export function StepsPanel({sessionId,refreshKey = 0,@@@ -362,20 -352,22 +425,24 @@@<span className="steps-ticks">{ticks(total).map((x, i) => <span key={i}>{x}</span>)}</span><span className="steps-axis-time">{t("steps.axis.time")}</span></div>- {rows.map(({ step, depth }) => (- <Fragment key={step.step_id}>+ {rows.map((row) => row.type === "helper" ? (+ <HelperRow key={`helper-${row.step.step_id}`} row={row} turn={turn} total={total} onToggle={() => toggleHelper(row.step.step_id)} />+ ) : row.type === "worker" ? (+ <WorkerRow key={`worker-${row.worker.turn_id}`} worker={row.worker} turn={turn} total={total} onOpen={onOpenSession} />+ ) : (- <StepRow- key={row.step.step_id}- step={row.step}- depth={row.depth}- turn={turn}- total={total}- label={stepLabel(row.step, t)}- selected={selected === row.step.step_id}- issue={flagged.has(row.step.step_id)}- onSelect={() => setSelected(selected === row.step.step_id ? null : row.step.step_id)}- />++ <Fragment key={row.step.step_id}>+ <StepRow- step={step}- depth={depth}++ step={row.step}++ depth={row.depth}+ turn={turn}+ total={total}- label={stepLabel(step, t)}- selected={selected === step.step_id}- issue={flagged.has(step.step_id)}- onSelect={() => setSelected(selected === step.step_id ? null : step.step_id)}++ label={stepLabel(row.step, t)}++ selected={selected === row.step.step_id}++ issue={flagged.has(row.step.step_id)}++ onSelect={() => setSelected(selected === row.step.step_id ? null : row.step.step_id)}+ />- {step.kind === "sandbox" && <StageRows step={step} depth={depth} turn={turn} total={total} />}++ {row.step.kind === "sandbox" && <StageRows step={row.step} depth={row.depth} turn={turn} total={total} />}+ </Fragment>))}</div>);