fix: harden task and chat execution

Task runs now preserve real model context limits, provider usage, baseline-repair spend, commit identity, durable agent-finish telemetry, and useful timeline details without imposing a token cap. Dashboard forge links are canonical per owning GitHub or Gitea identity. Chat turn claims acquire SQLite writer intent before reading, eliminating the concurrent SQLITE_BUSY snapshot race.
This commit is contained in:
sam committed 2026-08-25 05:48:17 +10:00
1 parent 9e6f507c06
commit a825db283c
36 files changed
+874 -286

No files matched your search

+14 -23
View File
@@ -4,6 +4,7 @@ import { ago, el, empty, mount, pill, statusKind } from "../base/dom.js";
import { statTile } from "../base/statTile.js";
import { taskRowA11y } from "./task-row.js";
import { initialTaskFilter, taskMatchesStatus } from "./task-filters.js";
import { describeTimelineEvent } from "./timeline-event.js";
/**
* Plain-language status labels. One place, so "waiting_human" only ever
@@ -41,7 +42,6 @@ export function tasksPage(params = new URLSearchParams()) {
const requestedTask = Number(params.get("task"));
let expandedId = Number.isFinite(requestedTask) && requestedTask > 0 ? requestedTask : null;
let focusRequestedTask = expandedId !== null;
let forgeHost = "";
const eventCache = new Map();
// Keyed by task id. A single shared string leaked one row's failure into
// every other row's action cell.
@@ -114,10 +114,7 @@ export function tasksPage(params = new URLSearchParams()) {
async function load() {
try {
[tasks, forgeHost] = await Promise.all([
api.tasks(),
api.config().then((cfg) => cfg?.identity?.forge_host || "").catch(() => ""),
]);
tasks = await api.tasks();
renderSummary();
renderRows();
if (expandedId && tasks.some((task) => String(task.id) === String(expandedId))) {
@@ -333,9 +330,9 @@ export function tasksPage(params = new URLSearchParams()) {
`Archive the local record for "${t.title || "this task"}"?`,
);
case "open_pr":
return taskLink(t, "pulls", t.pr_number, "Open PR");
return taskLink(t, "pull_request", t.pr_number, "Open PR");
case "open_issue":
return taskLink(t, "issues", t.issue_number, "Open issue");
return taskLink(t, "issue", t.issue_number, "Open issue");
default:
return null;
}
@@ -360,16 +357,9 @@ export function tasksPage(params = new URLSearchParams()) {
}
}
// Both forge links derive from the same host so they can never drift apart:
// one place builds the base, both anchors reuse it.
function forgeBase(t) {
if (!forgeHost || !t.owner || !t.repo) return null;
return `${forgeHost.replace(/\/+$/, "")}/${encodeURIComponent(t.owner)}/${encodeURIComponent(t.repo)}`;
}
function taskLink(t, kind, number, label) {
const base = forgeBase(t);
if (!base || !number || (kind === "issues" && t.source === "chat")) {
const href = kind === "issue" ? t.issue_url : t.pr_url;
if (!href || !number || (kind === "issue" && t.source === "chat")) {
return el(
"button.btn.btn-small",
{ type: "button", disabled: true, title: `${label} is unavailable` },
@@ -379,7 +369,7 @@ export function tasksPage(params = new URLSearchParams()) {
return el(
"a.btn.btn-small",
{
href: `${base}/${kind}/${number}`,
href,
target: "_blank",
rel: "noreferrer",
onclick: (event) => event.stopPropagation(),
@@ -389,7 +379,7 @@ export function tasksPage(params = new URLSearchParams()) {
}
function repoLink(t) {
const base = forgeBase(t);
const base = t.repo_url;
if (!base) return null;
return el(
"a.task-source-link",
@@ -405,14 +395,14 @@ export function tasksPage(params = new URLSearchParams()) {
}
function issueLink(t) {
const base = forgeBase(t);
const href = t.issue_url;
// A chat-sourced task has no issue on the forge, but its repo may still
// exist -- the repo link stays, the issue link does not.
if (t.source === "chat" || !base || !t.issue_number) return null;
if (t.source === "chat" || !href || !t.issue_number) return null;
return el(
"a.task-source-link",
{
href: `${base}/issues/${t.issue_number}`,
href,
target: "_blank",
rel: "noreferrer",
title: `Open issue #${t.issue_number} on the forge`,
@@ -460,13 +450,14 @@ export function tasksPage(params = new URLSearchParams()) {
}
function timelineEntry(ev) {
const description = describeTimelineEvent(ev);
return el(
"li.task-timeline-entry",
el("span.task-timeline-dot"),
el(
"div",
el("div.task-timeline-kind", ev.kind || ev.type || "event"),
ev.detail && el("div.task-timeline-detail", ev.detail),
el("div.task-timeline-kind", description.title),
description.detail && el("div.task-timeline-detail", description.detail),
el("div.task-timeline-when", ago(ev.at)),
),
);
+78
View File
@@ -0,0 +1,78 @@
function words(value) {
return String(value || "event")
.replaceAll("_", " ")
.replace(/\b\w/g, (letter) => letter.toUpperCase());
}
function duration(milliseconds) {
const ms = Number(milliseconds);
if (!Number.isFinite(ms) || ms < 0) return "";
if (ms < 1000) return `${Math.round(ms)} ms`;
const seconds = ms / 1000;
// Under 60s: 1 dp when seconds < 10, 0 dp otherwise (40.6 s, but 41 s).
if (seconds < 60) return `${seconds.toFixed(seconds < 10 ? 1 : 0)} s`;
const roundedSeconds = Math.round(seconds);
const minutes = Math.floor(roundedSeconds / 60);
const remSec = roundedSeconds % 60;
if (minutes < 60) return remSec === 0 ? `${minutes} min` : `${minutes} min ${remSec} s`;
const hours = Math.floor(minutes / 60);
const remMin = minutes - hours * 60;
return remMin === 0 ? `${hours} h` : `${hours} h ${remMin} min`;
}
function count(value) {
const n = Number(value);
// Render only for positive counts; zero is treated as "no metric
// reported" so a partially-populated agent_finish (pre-v0.1.24 events,
// or a failed run whose result is the zero Result) does not appear as
// "0 prompt · 0 completion · 0 cached".
if (!Number.isFinite(n) || n <= 0) return "";
return n.toLocaleString("en-US");
}
export function describeTimelineEvent(ev = {}) {
const data = ev.data || {};
const stage = ev.stage || "unknown stage";
const workflow = ev.workflow ? `${ev.workflow} workflow` : "";
if (ev.kind === "stage_start") {
return { title: `Started stage: ${stage}`, detail: workflow };
}
if (ev.kind === "stage_finish") {
const elapsed = duration(data.duration_ms);
const context = [workflow, elapsed && `ran for ${elapsed}`].filter(Boolean).join(" · ");
return {
title: data.interrupted ? `Stage interrupted: ${stage}` : data.error ? `Stage failed: ${stage}` : `Finished stage: ${stage}`,
detail: [context, data.error].filter(Boolean).join(" — "),
};
}
if (ev.kind === "task_retried") {
const count = Number(data.retry_count);
const attempt = Number.isFinite(count) && count > 0 ? `Retry ${count}` : "Retry requested";
const previous = [data.previous_stage && `after ${data.previous_stage}`, data.previous_reason]
.filter(Boolean)
.join(": ");
return { title: attempt, detail: previous || ev.detail || "" };
}
if (ev.kind === "agent_finish") {
const iterations = count(data.iterations);
const total = count(data.tokens);
const prompt = count(data.prompt_tokens);
const completion = count(data.completion_tokens);
const cached = count(data.cached_tokens);
const usage = [
iterations && `${iterations} iterations`,
total && `${total} tokens`,
prompt && `${prompt} prompt`,
completion && `${completion} completion`,
cached && `${cached} cached`,
data.model,
].filter(Boolean);
return {
title: `Agent ${data.status || "finished"}: ${stage}`,
detail: usage.join(" · ") || ev.detail || "",
};
}
return { title: words(ev.kind || ev.type), detail: ev.detail || "" };
}