mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-08 03:10:26 +00:00
## Summary
Replaces the ambiguous `runtime_secs`, `elapsed_secs`, and `duration_ms`
timing fields on run/stage public API surfaces with explicit
`wall_time_ms` (elapsed clock time) and a `StageTiming` value object
that also carries `inference_time_ms`, `tool_time_ms`, and
`active_time_ms`.
This is a greenfield breaking change — no compatibility shims are
preserved.
### What changed
**API shape**
- `RunBillingStage.runtime_secs` → `RunBillingStage.timing: StageTiming`
- `RunBillingTotals.runtime_secs` → `RunBillingTotals.timing:
StageTiming`
- `RunSummary.timestamps.duration_ms` / `elapsed_secs` removed; a
top-level `timing: StageTiming | null` field added
- Stage list item `duration_secs` → `wall_time_ms`
**Web app (`apps/fabro-web`)**
- `run-billing.tsx`: `liveRuntimeSecs` → `liveWallTimeMs`; live ticking
now returns milliseconds and the footer total sums `wallTimeMs` across
rows
- `stage-sidebar.ts`: `duration_secs` → `wall_time_ms` for the per-stage
duration display
- `runs.ts`: `elapsed_secs` lookup replaced with `timing.wall_time_ms`
- `formatElapsedSecs` / `formatDurationSecs` call sites replaced with
`formatDurationMs`
**Lockfile / tooling**
- `@openapitools/openapi-generator-cli@2.20.2` added as a dev dependency
to `@qltysh/fabro-api-client` to support regenerating the TypeScript
client after schema edits; several transitive deps pulled in alongside
it.
### Design notes
- **Units are now consistent**: every timing value on run/stage surfaces
is in milliseconds; the old API mixed seconds (`runtime_secs`,
`elapsed_secs`) with milliseconds (`duration_ms`).
- **Live ticking** still works correctly: the in-flight billing row
computes `now - startedAt` in ms and sums across rows for the footer,
avoiding a server round-trip during a running stage.
- **`StageTiming.active_time_ms = inference_time_ms + tool_time_ms`** —
parallel work is summed, so run active time can exceed wall time.
- Subsystem-internal `duration_ms` fields (sandbox setup, devcontainer
lifecycle, hooks) are intentionally left unchanged; only public
run/stage timing surfaces are affected.
### Fabro Details
<details>
<summary>Ran 9 stages in 115m 53s for $108.50</summary>
| Stage | Duration | Cost | Retries |
|---|---|---|---|
| start | 0s | – | 0 |
| toolchain | 1s | – | 0 |
| preflight_compile | 2m 6s | – | 0 |
| preflight_lint | 2m 18s | – | 0 |
| implement | 80m 53s | $101.97 | 0 |
| simplify_opus | 21m 35s | $4.09 | 0 |
| simplify_gpt | 5m 1s | $2.44 | 0 |
| verify | 3m 11s | – | 0 |
| fmt | 3s | – | 0 |
| **Total** | **115m 53s** | **$108.50** | **0** |
</details>
<details>
<summary>Ran <code>ImplementPlan.fabro</code> (12 nodes and 15
edges)</summary>
```dot
digraph ImplementPlan {
graph [
goal="Implement and simplify",
model_stylesheet="
* { model: claude-opus-4-7; }
"
]
rankdir=LR
start [shape=Mdiamond, label="Start"]
exit [shape=Msquare, label="Exit"]
toolchain [label="Toolchain", shape=parallelogram, script="command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1", max_retries=0]
preflight_compile [label="Preflight Compile", shape=parallelogram, script="cargo check -q --workspace 2>&1", max_retries=0]
preflight_lint [label="Preflight Lint", shape=parallelogram, script="cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1", max_retries=0]
fix_lints [label="Fix Lints", prompt="The preflight lint step failed. Read the build output from context and fix all clippy lint warnings.", max_visits=3]
implement [label="Implement", prompt="Read the plan file referenced in the goal and implement every step. Make all the code changes described in the plan. Use red/green TDD."]
simplify_opus [label="Simplify (Opus)", prompt="@prompts/simplify.md"]
simplify_gpt [label="Simplify (GPT-55)", prompt="@prompts/simplify.md", model="gpt-55"]
verify [label="Verify", shape=parallelogram, script="cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1 && cargo nextest run --cargo-quiet --workspace --status-level fail 2>&1 && cargo dev docs refresh 2>&1 && cargo dev docs check 2>&1", goal_gate=true, retry_target="fixup"]
fixup [label="Fixup", prompt="The verify step failed. Read the build output from context and fix all clippy lint warnings, test failures, and generated docs errors.", max_visits=3]
fmt [label="Format", shape=parallelogram, script="cargo +nightly-2026-04-14 fmt --all 2>&1", max_retries=0]
start -> toolchain
toolchain -> preflight_compile [condition="outcome=succeeded"]
toolchain -> exit
preflight_compile -> preflight_lint [condition="outcome=succeeded"]
preflight_compile -> exit
preflight_lint -> implement [condition="outcome=succeeded"]
preflight_lint -> fix_lints
fix_lints -> preflight_lint
implement -> simplify_opus -> simplify_gpt -> verify
verify -> fmt [condition="outcome=succeeded"]
verify -> fixup
fixup -> verify
fmt -> exit
}
```
</details>
⚒️ Generated with [Fabro](https://fabro.sh)
---------
Co-authored-by: Fabro <noreply@fabro.sh>
Co-authored-by: Bryan Helmkamp <bryan@brynary.com>
205 lines
No EOL
6.6 KiB
TypeScript
205 lines
No EOL
6.6 KiB
TypeScript
import { formatDurationMs } from "../lib/format";
|
|
import {
|
|
BoardColumn,
|
|
type Run,
|
|
type RunStatus as ApiRunStatus,
|
|
} from "@qltysh/fabro-api-client";
|
|
|
|
export type CiStatus = "passing" | "failing" | "pending";
|
|
|
|
export type CheckStatus = "success" | "failure" | "skipped" | "pending" | "queued";
|
|
|
|
export interface CheckRun {
|
|
name: string;
|
|
status: CheckStatus;
|
|
duration?: string;
|
|
}
|
|
|
|
export interface RunItem {
|
|
id: string;
|
|
repo: string;
|
|
title: string;
|
|
workflow: string;
|
|
column?: BoardColumn;
|
|
lifecycleStatus?: RunStatus | null;
|
|
lifecycleStatusLabel?: string;
|
|
number?: number;
|
|
pullRequestUrl?: string;
|
|
additions?: number;
|
|
deletions?: number;
|
|
checks?: CheckRun[];
|
|
elapsed?: string;
|
|
resources?: string;
|
|
actionDisabled?: boolean;
|
|
comments?: number;
|
|
question?: string;
|
|
sandboxId?: string;
|
|
sandboxWorkingDirectory?: string;
|
|
sourceDirectory?: string;
|
|
createdAt?: string;
|
|
lastEventAt?: string;
|
|
}
|
|
|
|
export const columnStatuses = [
|
|
BoardColumn.QUEUED,
|
|
BoardColumn.INITIALIZING,
|
|
BoardColumn.RUNNING,
|
|
BoardColumn.BLOCKED,
|
|
BoardColumn.SUCCEEDED,
|
|
BoardColumn.FAILED,
|
|
BoardColumn.ARCHIVED,
|
|
] as const satisfies readonly BoardColumn[];
|
|
|
|
export const columnStatusDisplay: Record<BoardColumn, { label: string; dot: string; text: string }> = {
|
|
queued: { label: "Queued", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
initializing: { label: "Initializing", dot: "bg-amber", text: "text-amber" },
|
|
running: { label: "Running", dot: "bg-teal-500", text: "text-teal-500" },
|
|
blocked: { label: "Blocked", dot: "bg-amber", text: "text-amber" },
|
|
succeeded: { label: "Succeeded", dot: "bg-teal-300", text: "text-teal-300" },
|
|
failed: { label: "Failed", dot: "bg-coral", text: "text-coral" },
|
|
archived: { label: "Archived", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
};
|
|
|
|
export interface RunWithStatus extends RunItem {
|
|
status: BoardColumn;
|
|
statusLabel: string;
|
|
}
|
|
|
|
function displayRunTitle(title: string | null | undefined): string {
|
|
return title?.trim() ? title : "Untitled run";
|
|
}
|
|
|
|
function displayRepoName(name: string): string {
|
|
const slash = name.lastIndexOf("/");
|
|
return slash >= 0 ? name.slice(slash + 1) : name;
|
|
}
|
|
|
|
function runStatusKind(status: ApiRunStatus | null | undefined): RunStatus | null {
|
|
return status?.kind ?? null;
|
|
}
|
|
|
|
export function mapRunListItem(item: Run): RunItem {
|
|
const lifecycleStatus = item.lifecycle.archived ? "archived" : runStatusKind(item.lifecycle.status);
|
|
const runtime = item.sandbox?.runtime;
|
|
return {
|
|
id: item.id,
|
|
repo: displayRepoName(item.repository?.name ?? "unknown"),
|
|
title: displayRunTitle(item.title),
|
|
workflow: item.workflow.name ?? item.workflow.graph_name ?? item.workflow.slug ?? "unknown",
|
|
column: columnForRun(item) ?? undefined,
|
|
lifecycleStatus,
|
|
lifecycleStatusLabel: lifecycleStatusLabel(item.lifecycle.status, item.lifecycle.archived),
|
|
number: item.pull_request?.number,
|
|
pullRequestUrl: item.pull_request?.html_url,
|
|
elapsed: item.timing != null ? formatDurationMs(item.timing.wall_time_ms) : undefined,
|
|
resources: undefined,
|
|
question: item.current_question?.text,
|
|
sandboxId: runtime?.id ?? undefined,
|
|
sandboxWorkingDirectory: runtime?.working_directory ?? undefined,
|
|
sourceDirectory: item.source_directory ?? undefined,
|
|
createdAt: item.timestamps.created_at,
|
|
lastEventAt: item.timestamps.last_event_at ?? undefined,
|
|
};
|
|
}
|
|
|
|
export type { Run };
|
|
|
|
export function mapRunToRunItem(run: Run): RunItem {
|
|
return mapRunListItem(run);
|
|
}
|
|
|
|
export function columnForStatus(status: ApiRunStatus | null | undefined): BoardColumn | null {
|
|
switch (status?.kind) {
|
|
case "submitted":
|
|
case "queued":
|
|
return "queued";
|
|
case "starting":
|
|
return "initializing";
|
|
case "running":
|
|
case "paused":
|
|
return "running";
|
|
case "blocked":
|
|
return "blocked";
|
|
case "succeeded":
|
|
return "succeeded";
|
|
case "failed":
|
|
case "dead":
|
|
return "failed";
|
|
case "removing":
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function columnForRun(run: Run): BoardColumn | null {
|
|
if (run.lifecycle.archived) return "archived";
|
|
return columnForStatus(run.lifecycle.status);
|
|
}
|
|
|
|
export function toRunWithStatus(run: Run): RunWithStatus {
|
|
const item = mapRunListItem(run);
|
|
const column = columnForRun(run) ?? "queued";
|
|
return {
|
|
...item,
|
|
status: column,
|
|
statusLabel: columnStatusDisplay[column].label,
|
|
};
|
|
}
|
|
|
|
export function deriveCiStatus(checks: CheckRun[]): CiStatus {
|
|
if (checks.some((c) => c.status === "failure")) return "failing";
|
|
if (checks.some((c) => c.status === "pending" || c.status === "queued")) return "pending";
|
|
return "passing";
|
|
}
|
|
|
|
export type RunStatus =
|
|
| "submitted"
|
|
| "queued"
|
|
| "starting"
|
|
| "running"
|
|
| "blocked"
|
|
| "paused"
|
|
| "removing"
|
|
| "succeeded"
|
|
| "failed"
|
|
| "dead"
|
|
| "archived";
|
|
|
|
export const runStatusDisplay: Record<RunStatus, { label: string; dot: string; text: string }> = {
|
|
submitted: { label: "Submitted", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
queued: { label: "Queued", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
starting: { label: "Starting", dot: "bg-amber", text: "text-amber" },
|
|
running: { label: "Running", dot: "bg-teal-500", text: "text-teal-500" },
|
|
blocked: { label: "Blocked", dot: "bg-amber", text: "text-amber" },
|
|
paused: { label: "Paused", dot: "bg-amber", text: "text-amber" },
|
|
removing: { label: "Removing", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
succeeded: { label: "Succeeded", dot: "bg-mint", text: "text-mint" },
|
|
failed: { label: "Failed", dot: "bg-coral", text: "text-coral" },
|
|
dead: { label: "Dead", dot: "bg-coral", text: "text-coral" },
|
|
archived: { label: "Archived", dot: "bg-fg-muted", text: "text-fg-muted" },
|
|
};
|
|
|
|
const knownRunStatuses = new Set<string>(Object.keys(runStatusDisplay));
|
|
|
|
export function isRunStatus(s: string): s is RunStatus {
|
|
return knownRunStatuses.has(s);
|
|
}
|
|
|
|
function lifecycleStatusLabel(status: ApiRunStatus | null | undefined, archived = false): string | undefined {
|
|
const kind = archived ? "archived" : runStatusKind(status);
|
|
if (!kind) return undefined;
|
|
return runStatusDisplay[kind].label;
|
|
}
|
|
|
|
/** Graph control nodes hidden from stage lists in the UI. */
|
|
const hiddenStageIds = new Set(["start", "exit"]);
|
|
|
|
export function isVisibleStage(id: string): boolean {
|
|
return !hiddenStageIds.has(id);
|
|
}
|
|
|
|
export const ciConfig: Record<CiStatus, { label: string; dot: string; text: string }> = {
|
|
passing: { label: "Passing", dot: "bg-mint", text: "text-mint" },
|
|
failing: { label: "Changes needed", dot: "bg-coral", text: "text-coral" },
|
|
pending: { label: "Pending", dot: "bg-amber", text: "text-amber" },
|
|
}; |