Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Mission board: use the #99 rework APIs for Run, workflow changes and AutoFix tries

Pixel5d4d72d5dab8
diff --git a/frontend/src/components/MissionBoardView.tsx b/frontend/src/components/MissionBoardView.tsx
index a1c36d75..5b1df9eb 100644
--- a/frontend/src/components/MissionBoardView.tsx
+++ b/frontend/src/components/MissionBoardView.tsx
@@ -770,7 +770,7 @@ export const FailureBox: React.FC<{
)}
<dl className="grid grid-cols-2 gap-3 pt-1">
<Fact label="AutoFix tries">
- {failures.filter((x) => x.autofix && x.autofix.status !== 'suggested' && x.autofix.status !== 'skipped').length || (a && a.status !== 'suggested' && a.status !== 'skipped' ? 1 : 0)}
+ {task.autofix_attempts ?? 0}
</Fact>
{recovery && <Fact label="Spent on retries">{recovery}</Fact>}
</dl>
@@ -1929,6 +1929,8 @@ export const MissionBoardPage: React.FC<{
if (pendingKey.current?.what !== what) pendingKey.current = { what, key: newIdempotencyKey() };
return pendingKey.current.key;
};
+ // Run on a held task: one key per hold, kept after success, so a second press replays the first 200.
+ const runKeys = useRef<Record<string, string>>({});
const alive = useRef(true);
const openIdRef = useRef<string | null>(null);
openIdRef.current = openId;
@@ -1966,7 +1968,7 @@ export const MissionBoardPage: React.FC<{
missionsApi.failures(id).then((f) => alive.current && openIdRef.current === id && setFailures(f), () => {});
} else setFailures([]);
if (t.needs_you.some((n) => n.kind === 'workflow_change')) {
- missionsApi.workflowChanges('proposed').then((cs) => alive.current && openIdRef.current === id && setChanges(cs.filter((c) => c.task_id === id)), () => {});
+ missionsApi.workflowChanges('proposed', id).then((cs) => alive.current && openIdRef.current === id && setChanges(cs), () => {});
} else setChanges([]);
} catch (e) {
if (alive.current && openIdRef.current === id) setDetailError(failMsg(e));
@@ -2148,14 +2150,14 @@ export const MissionBoardPage: React.FC<{
};
/** One person action on the open task: keyed, one at a time, 401 asks for the token, 409 shows what it is now. */
- const personAction = async (what: string, run: (taskId: string, key: string) => Promise<string>, errorText: (e: unknown) => string) => {
+ const personAction = async (what: string, run: (taskId: string, key: string) => Promise<string>, errorText: (e: unknown) => string, key?: string) => {
if (!openId || inFlight.current) return;
const taskId = openId;
inFlight.current = true;
setBusy(true);
setDetailNotice(null);
try {
- const text = await run(taskId, keyFor(what));
+ const text = await run(taskId, key ?? keyFor(what));
pendingKey.current = null;
if (!alive.current) return;
setDetailNotice({ text, error: false });
@@ -2174,8 +2176,10 @@ export const MissionBoardPage: React.FC<{
}
};
- const runHeld = () =>
- personAction(
+ const runHeld = () => {
+ const hold = `${openId}:${detail?.task.held_at ?? ''}`;
+ runKeys.current[hold] ??= newIdempotencyKey();
+ return personAction(
`run:${openId}`,
async (id, key) => {
const t = await missionsApi.runHeld(id, key);
@@ -2183,7 +2187,9 @@ export const MissionBoardPage: React.FC<{
return 'Off hold. A bot picks it up next.';
},
restoreErrorText,
+ runKeys.current[hold],
);
+ };
const retryAutofix = (failureId?: string) =>
personAction(
`autofix:${openId}:${failureId ?? ''}`,
diff --git a/frontend/src/missions.ts b/frontend/src/missions.ts
index 48026d2a..8b5cb942 100644
--- a/frontend/src/missions.ts
+++ b/frontend/src/missions.ts
@@ -1434,6 +1434,7 @@ export const missionsApi = {
/** Copy a task to redo it; the same key returns the same copy. */
fork: (taskId: string, reason: string, key: string) => call<Task>(`/api/tasks/${enc(taskId)}/fork`, 'POST', { reason }, { 'Idempotency-Key': key }),
/** Let a task a restore held run again (person only). */
+ /** Take a held task off hold. The same key replays the first 200, so a double press is a success. */
runHeld: (id: string, key: string) => call<{ task: Task }>(`/api/tasks/${enc(id)}/run`, 'POST', {}, { 'Idempotency-Key': key }).then((r) => r.task),
checkpoints: (id: string) => call<Checkpoint[]>(`/api/tasks/${enc(id)}/checkpoints`),
restorePreview: (id: string, cid: string) => call<RestorePreview>(`/api/tasks/${enc(id)}/checkpoints/${enc(cid)}/restore-preview`),
@@ -1444,7 +1445,8 @@ export const missionsApi = {
runAutofix: (id: string, key: string, failureId?: string) =>
call<AutofixAttempt>(`/api/tasks/${enc(id)}/autofix`, 'POST', failureId ? { failure_id: failureId } : {}, { 'Idempotency-Key': key }),
cancelAutofix: (id: string, aid: string) => call<AutofixAttempt>(`/api/tasks/${enc(id)}/autofix/${enc(aid)}/cancel`, 'POST', {}),
- workflowChanges: (status: WorkflowChangeStatus = 'proposed') => call<WorkflowChange[]>(`/api/workflow-changes?status=${status}`),
+ workflowChanges: (status: WorkflowChangeStatus = 'proposed', taskId?: string) =>
+ call<WorkflowChange[]>(`/api/workflow-changes?status=${status}${taskId ? `&task_id=${enc(taskId)}` : ''}`),
decideChange: (id: string, approve: boolean) => call<WorkflowChange>(`/api/workflow-changes/${enc(id)}/${approve ? 'approve' : 'reject'}`, 'POST', {}),
/** One person action on a task. `run_checks` answers `{checks, task}`, the others the Task. */
act: async (id: string, action: TaskAction, reason?: string): Promise<Task> => {
diff --git a/frontend/tests/missionAutofix.test.mjs b/frontend/tests/missionAutofix.test.mjs
index 987f0790..0a10450e 100644
--- a/frontend/tests/missionAutofix.test.mjs
+++ b/frontend/tests/missionAutofix.test.mjs
@@ -68,7 +68,7 @@ test('the task panel shows the failure, the AutoFix plan, its tries and its spen
{ id: 'fl0', attempt: 1, source: 'turn', class: 'transient', summary: 'the model timed out', excerpt: null, checkpoint_id: null, created_at: '2026-10-27T11:00:00Z', autofix: attempt({ id: 'af0', status: 'succeeded', strategy: 'wait_and_retry' }) },
{ id: 'fl1', attempt: 2, source: 'check', class: 'check_failed', summary: 'npm test: 2 tests failed', excerpt: 'FAIL pricing.test.js', checkpoint_id: null, created_at: '2026-10-27T11:50:00Z', autofix: attempt() },
];
- const html = ui.detail(detailProps(failed({ needs_you: [{ kind: 'autofix_suggested', id: 'af1', text: 'Retry with the check output? npm test: 2 tests failed' }] }), { failures, onRetryAutofix: noop, onSkipAutofix: noop }));
+ const html = ui.detail(detailProps(failed({ autofix_attempts: 1, needs_you: [{ kind: 'autofix_suggested', id: 'af1', text: 'Retry with the check output? npm test: 2 tests failed' }] }), { failures, onRetryAutofix: noop, onSkipAutofix: noop }));
assert.match(html, /data-failure-class="check_failed"[\s\S]*A check failed[\s\S]*npm test: 2 tests failed/);
assert.match(html, /data-autofix-status="suggested"/);
assert.match(html, /data-autofix-retry[^>]*>[\s\S]*Retry now/);
@@ -84,6 +84,57 @@ test('the task panel shows the failure, the AutoFix plan, its tries and its spen
assert.doesNotMatch(ui.detail(detailProps(task())), /data-failure/, 'nothing without a failure');
});
+test('AutoFix tries come from the server count, not from counting failures in the browser', () => {
+ const failures = [1, 2, 3].map((n) => ({ id: `fl${n}`, attempt: n, source: 'turn', class: 'transient', summary: 'timed out', excerpt: null, checkpoint_id: null, created_at: '2026-10-27T11:00:00Z', autofix: attempt({ id: `af${n}`, status: 'succeeded' }) }));
+ assert.match(ui.failure({ task: failed({ autofix_attempts: 2 }), failures, now: NOW }), />AutoFix tries<\/dt><dd[^>]*>2</);
+ assert.match(ui.failure({ task: failed({ autofix_attempts: undefined }), failures, now: NOW }), />AutoFix tries<\/dt><dd[^>]*>0</, 'an older server without the count shows 0');
+});
+
+test('a retry skipped over the retry budget shows the Needs-you card and why it stopped', () => {
+ const t = failed({
+ state: 'failed', autofix_attempts: 1, recovery_spent_tokens: 10000, recovery_budget_tokens: 10000,
+ autofix: attempt({ status: 'skipped', reason: 'over_recovery_budget: 10000 of 10000 used' }),
+ needs_you: [{ kind: 'fix_needed', id: 'fl3', text: 'Retry budget used up: raise it or retry by hand.' }],
+ });
+ const html = ui.detail(detailProps(t));
+ assert.match(html, /data-fix-needed[^>]*><span[^>]*>To fix: <\/span>Retry budget used up: raise it or retry by hand\./);
+ assert.match(html, /data-autofix-status="skipped"[\s\S]*retry budget/);
+ assert.doesNotMatch(html, /data-autofix-retry/, 'AutoFix offers no retry of its own; the person retries by hand');
+ assert.doesNotMatch(html, /data-needs-you/, 'the card is shown once, in What went wrong');
+});
+
+test('a masked value in a check spec is shown as the server sent it', () => {
+ const spec = { cmd: 'curl -H "Authorization: Bearer [redacted]" https://api.example.com/health' };
+ const c = {
+ id: 'wc2', task_id: 'a', routine_id: null, target: 'check_spec', reason: 'The check URL is wrong',
+ before: { check_id: 'c1', kind: 'command', spec, required: true }, after: { check_id: 'c1', kind: 'command', spec, required: false },
+ proposed_by: 'kwant', proposed_by_name: null, status: 'proposed', decided_at: null, created_at: '2026-10-27T11:55:00Z',
+ };
+ const html = ui.change({ item: { kind: 'workflow_change', id: 'wc2', text: 'Allow this change to a check: …' }, change: c, now: NOW, onDecide: noop });
+ assert.match(html, /Bearer \[redacted\]/);
+ assert.doesNotMatch(html, /unmask|reveal|show (the )?(key|password)/i);
+});
+
+test('the API asks for one task’s workflow changes and sends one key per Run', async () => {
+ const seen = [];
+ const prev = globalThis.fetch;
+ globalThis.fetch = async (url, init = {}) => {
+ seen.push({ url: String(url), method: init.method ?? 'GET', key: new Headers(init.headers).get('Idempotency-Key') });
+ const body = String(url).includes('/run') ? { task: task({ state: 'ready', held_at: null }) } : [];
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
+ };
+ try {
+ await m.missionsApi.workflowChanges('proposed', 'a b');
+ await m.missionsApi.runHeld('a', 'k-1');
+ await m.missionsApi.runHeld('a', 'k-1');
+ } finally {
+ globalThis.fetch = prev;
+ }
+ assert.match(seen[0].url, /\/api\/workflow-changes\?status=proposed&task_id=a%20b$/);
+ assert.deepEqual(seen.slice(1).map((x) => [x.method, x.key]), [['POST', 'k-1'], ['POST', 'k-1']]);
+ assert.match(seen[1].url, /\/api\/tasks\/a\/run$/);
+});
+
test('AutoFix retries show as AutoFix in the activity, not as the person', () => {
assert.equal(m.eventText(ev('autofix', { strategy: 'retry_with_diagnostics' })), 'AutoFix sent it back to Ready: try again with the check’s output');
assert.match(m.eventText(ev('failure', { class: 'check_failed', summary: 'npm test failed' })), /^It failed: a check failed\. npm test failed/);