From 7b1405e10454b4d34d69352eb63807b8752dc9b3 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 01:48:50 +0200 Subject: [PATCH 1/5] Time-skip: view-in-browser steps never hang or fail a version (no-window rule, skip with a plain note); steps carry the unattended note --- apps/host/server/agent/agent-bridge.mjs | 5 ++++- apps/host/server/agent/plan.mjs | 4 ++++ apps/host/server/timeskip-fork.mjs | 20 +++++++++++++++----- apps/host/tests/timeskip-fork.test.mjs | 10 +++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/apps/host/server/agent/agent-bridge.mjs b/apps/host/server/agent/agent-bridge.mjs index ed1cd29f..07ceed36 100644 --- a/apps/host/server/agent/agent-bridge.mjs +++ b/apps/host/server/agent/agent-bridge.mjs @@ -944,6 +944,9 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir = /** A paused plan becomes open again (a step that did not finish is tried again in a fresh session). */ function reopenPlan(chatId) { const p = plans.get(chatId); if (p && p.state === 'paused') { plans.update(chatId, x => { x.state = 'approved'; }); onPlan(chatId, 'approved', planView(plans.get(chatId))); } } + /** Give up on one step with a plain note (a check that cannot be done here) so the rest of the plan can go on. */ + function skipStep(chatId, index, note) { plans.update(chatId, p => { const st = p.steps[index]; if (st) { st.state = 'skipped'; st.summary = String(note ?? 'Skipped.').slice(0, 140); } if (p.state === 'paused') p.state = 'approved'; }); onPlan(chatId, 'step', planView(plans.get(chatId))); } + /** Forget the chat's agent session (not its plan): the next turn starts a fresh one in the same folder. */ function resetSession(chatId) { if (chats.get(chatId)?.turn || chats.get(chatId)?.starting) throw new AgentUnavailable('This chat is still working.', 'turn-active'); @@ -1086,7 +1089,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir = /** Let go of a chat's Harness session mapping (a task starts every run in a session of its own). */ function forget(chatId) { if (chats.get(chatId)?.turn) return; delete sessionMap[chatId]; chats.delete(chatId); persist(); } - return { goalState, goalControl, harnessDir, status, runTurn, goalCommand, planCommand, researchCommand, llmTarget, setPlanBriefing, resetSession, reopenPlan, planGoal, planControl, planState, queueMessage, cancelQueued, takeQueue, forget, approve, setMode, stop, pendingFor, close, sessionOf: chatId => sessionMap[chatId]?.sessionId ?? null, isRunning: chatId => !!chats.get(chatId)?.turn, _debug: () => ({ rt, sessionMap }) }; + return { goalState, goalControl, harnessDir, status, runTurn, goalCommand, planCommand, researchCommand, llmTarget, setPlanBriefing, resetSession, reopenPlan, skipStep, planGoal, planControl, planState, queueMessage, cancelQueued, takeQueue, forget, approve, setMode, stop, pendingFor, close, sessionOf: chatId => sessionMap[chatId]?.sessionId ?? null, isRunning: chatId => !!chats.get(chatId)?.turn, _debug: () => ({ rt, sessionMap }) }; } /** A goal that stopped by itself, in words. */ diff --git a/apps/host/server/agent/plan.mjs b/apps/host/server/agent/plan.mjs index 27db8b9e..06639107 100644 --- a/apps/host/server/agent/plan.mjs +++ b/apps/host/server/agent/plan.mjs @@ -105,6 +105,9 @@ export function parsePoints(objective) { return { title: clip(aim || steps[0].text, 80), steps }; } +/** A step that is about looking at the result in a browser or window: it must never hang or fail a whole run on a machine with no screen. */ +export const isViewStep = text => /\b(open|view|launch|preview|look at|check|confirm|verify)\b[^\n]{0,60}\b(browser|in chrome|in edge|in firefox|window|on screen)\b/i.test(String(text ?? '')); + /** The goal the Harness runs for step `index` (0-based): one step, with the aim and the steps around it named. */ export function stepObjective(plan, index) { const n = plan.steps.length; const s = plan.steps[index]; @@ -114,6 +117,7 @@ export function stepObjective(plan, index) { `You are on step ${index + 1} of ${n}: ${s.text}${s.detail ? ` (${s.detail})` : ''}.`, done ? `Already done: ${done}.` : '', plan.briefing ? String(plan.briefing) : '', + isViewStep(s.text) ? 'This step is about seeing the result in a browser. Never wait for a program to close. If a person is at this computer, start the browser so the command returns at once (Windows: Start-Process; macOS: open; Linux: xdg-open) and say it is open. If there is no screen, check the page without a visible window: use the headless browser tool if you have one, otherwise read the file and its script for mistakes, and say in one plain sentence what you could and could not check. Then finish the step.' : '', 'Do only this step, check that it worked, and then finish the goal.', index + 1 < n ? 'The next steps are handled separately: do not start them.' : '', ].filter(Boolean).join(' '); diff --git a/apps/host/server/timeskip-fork.mjs b/apps/host/server/timeskip-fork.mjs index 87ade9cd..e7e44668 100644 --- a/apps/host/server/timeskip-fork.mjs +++ b/apps/host/server/timeskip-fork.mjs @@ -16,6 +16,10 @@ import { randomUUID } from 'node:crypto'; import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'; import { dirname, join, relative, resolve, sep } from 'node:path'; import { diffRun, runImagePath, isNoisePath } from './timeskip.mjs'; +import { isViewStep } from './agent/plan.mjs'; + +/** The note both agents carry on every step: the work is in a copy, unattended, on whatever machine this is. */ +export const UNATTENDED = 'This work runs in a copy of the folder with nobody watching. Never open a visible window and never wait for a program to close. To check a web page use the headless browser tool if you have one; otherwise read the file and say plainly what you could not check. A check that cannot be done here is noted in one sentence and the step is finished.'; const SKIP = new Set(['.git', '.strata', '.timeskip', 'node_modules', '__pycache__']); const TERMINAL = new Set(['completed', 'failed', 'cancelled', 'interrupted']); @@ -118,6 +122,7 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n if (stopped()) return; const plan = agent.planState(aChat); if (!plan || plan.steps.length < 2) throw new Error('The assistant could not split this request into steps. Describe the steps you want, or use /goal instead.'); + agent.setPlanBriefing(aChat, UNATTENDED); agent.planControl({ chatId: aChat, planId: plan.id, action: 'approve' }); r.plan = { id: plan.id, title: plan.title, steps: plan.steps.map(s => ({ id: s.id, text: s.text, detail: s.detail })) }; announce(r); @@ -142,7 +147,7 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n if (stopped()) return; const bp = agent.planState(bChat); if (!bp || bp.steps.length < 2) { r.b.state = 'failed'; r.b.note = 'The improvement plan could not be written, so only A is shown.'; announce(r); return; } - agent.setPlanBriefing(bChat, 'This work continues from a first attempt that is already in this folder; its notes are in .timeskip/context.md (read them first). Improve on it where it is weak instead of starting over.'); + agent.setPlanBriefing(bChat, UNATTENDED + ' This work continues from a first attempt that is already in this folder; its notes are in .timeskip/context.md (read them first). Improve on it where it is weak instead of starting over.'); agent.planControl({ chatId: bChat, planId: bp.id, action: 'approve' }); r.b.plan = bp.steps.map(s => ({ id: s.id, text: s.text })); r.b.state = 'running'; r.b.total = bp.steps.length; announce(r); @@ -160,10 +165,11 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n if (stopped()) return; finished = agent.planState(bChat)?.steps[at]?.state === 'done'; } - if (agent.planState(bChat)?.steps[at]?.state !== 'done') break; + if (agent.planState(bChat)?.steps[at]?.state !== 'done' && isViewStep(bp.steps[at].text)) { agent.skipStep(bChat, at, 'Could not look at the page here; the files were checked instead.'); say(r, 'b-skip', `B, step ${at + 1} (viewing the page) was skipped on this machine.`, { step: at + 1 }); } + if (!['done', 'skipped'].includes(agent.planState(bChat)?.steps[at]?.state)) break; } const end = agent.planState(bChat); - r.b.state = end?.steps.every(x => x.state === 'done') ? 'done' : 'failed'; + r.b.state = end?.steps.every(x => ['done', 'skipped'].includes(x.state)) ? 'done' : 'failed'; if (r.b.state === 'failed') r.b.note = stopped() ? 'Stopped.' : 'B did not finish, so only A is shown.'; announce(r); }; @@ -205,13 +211,17 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n if (stopped()) return; finished = agent.planState(aChat)?.steps[at]?.state === 'done'; } + if (agent.planState(aChat)?.steps[at]?.state !== 'done' && isViewStep(plan.steps[at].text)) { + // a look-in-a-browser step must not fail the whole version + agent.skipStep(aChat, at, 'Could not look at the page here; the files were checked instead.'); say(r, 'a-skip', `A, step ${at + 1} (viewing the page) was skipped on this machine.`, { step: at + 1 }); + } const now = agent.planState(aChat); - if (!now || now.steps[at]?.state !== 'done') break; + if (!now || !['done', 'skipped'].includes(now.steps[at]?.state)) break; if (r.lever && at + 1 === r.lever.step - 1) { try { forkNow(); } catch (e) { r.b = { ...r.b, state: 'failed', note: 'B could not be prepared, so only A is shown.' }; } } } if (stopped()) return; const aEnd = agent.planState(aChat); - r.a.state = aEnd?.state === 'done' || aEnd?.steps.every(x => x.state === 'done') ? 'done' : 'failed'; + r.a.state = aEnd?.steps.every(x => ['done', 'skipped'].includes(x.state)) ? 'done' : 'failed'; announce(r); if (r.a.state !== 'done') throw new Error('A did not finish the plan' + (r.a.note ? ' (' + r.a.note + ')' : r.a.goal?.blocked ? ' (' + r.a.goal.blocked + ')' : '') + ', so there is nothing to compare. Your files were not changed.'); if (r.lever && !forked) { forkNow(); } diff --git a/apps/host/tests/timeskip-fork.test.mjs b/apps/host/tests/timeskip-fork.test.mjs index b84431a4..59c7ab96 100644 --- a/apps/host/tests/timeskip-fork.test.mjs +++ b/apps/host/tests/timeskip-fork.test.mjs @@ -7,7 +7,8 @@ import { join } from 'node:path'; import { startScriptedWorker } from './helpers/scripted-worker.mjs'; import { createAgentBridge } from '../server/agent/agent-bridge.mjs'; import { resolveHarness } from '../server/agent/harness-runtime.mjs'; -import { createForkTimeskip, leverPrompt, parseLever, defaultLever, improvementPrompt, copyProject } from '../server/timeskip-fork.mjs'; +import { isViewStep, stepObjective } from '../server/agent/plan.mjs'; +import { UNATTENDED, createForkTimeskip, leverPrompt, parseLever, defaultLever, improvementPrompt, copyProject } from '../server/timeskip-fork.mjs'; const HARNESS = process.env.STRATA_HARNESS_DIR; const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false; @@ -102,3 +103,10 @@ test('Stop ends both agents, removes the copies and leaves the folder alone', { assert.equal(readFileSync(join(r.project, 'keep.txt'), 'utf8'), 'original'); assert.equal(r.ts.files(run.id), null); }); + +test('a step about looking at the page in a browser is recognised, carries the no-hang rule, and the unattended note forbids windows', () => { + assert.ok(isViewStep('Open goku.html in a browser to confirm rendering')); assert.ok(isViewStep('Preview the page in a window')); assert.ok(!isViewStep('Write the HTML file')); assert.ok(!isViewStep('Count the voxels')); + const plan = { title: 'T', steps: [{ text: 'Write it' }, { text: 'Open it in a browser to check', detail: '' }] }; + assert.match(stepObjective(plan, 1), /Never wait for a program to close/); assert.match(stepObjective(plan, 1), /Start-Process/); assert.ok(!/Start-Process/.test(stepObjective(plan, 0))); + assert.match(UNATTENDED, /Never open a visible window/); +}); From f548cfd8438f525862e55776f172d926cd7eac4c Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 02:41:20 +0200 Subject: [PATCH 2/5] Time-skip: a step that runs longer than 20 minutes is stopped and left as it is with a plain note; one shared step runner for A and B --- apps/host/server/timeskip-fork.mjs | 61 ++++++++++++--------- apps/host/tests/helpers/scripted-worker.mjs | 1 + apps/host/tests/timeskip-fork.test.mjs | 13 ++++- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/apps/host/server/timeskip-fork.mjs b/apps/host/server/timeskip-fork.mjs index e7e44668..578f65d4 100644 --- a/apps/host/server/timeskip-fork.mjs +++ b/apps/host/server/timeskip-fork.mjs @@ -82,7 +82,7 @@ export function improvementPrompt({ request, steps, lever, doneSummaries }) { const stepObjectiveBriefing = ctx => ctx; -export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.now }) { +export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.now, stepTimeoutMs = 20 * 60_000 }) { mkdirSync(dir, { recursive: true }); const runs = new Map(); // id -> internal run @@ -110,6 +110,34 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n return text; } + /** + * One plan step in its own session: tried twice if it ends early; stopped when it takes longer than `stepTimeoutMs` (a small model that keeps + * debugging one step must not hold the whole version for an hour). A step that cannot finish (too long, or a look-in-a-browser step on a machine + * with no screen) is left as it is with a plain note and the next step goes on; any other step that fails ends the version. + * Returns 'done' | 'skipped' | 'failed' | 'stopped'. + */ + async function runOneStep(r, { tag, chat, planId, plan, at, root, choice, thinking, onFrame }) { + let finished = false, timedOut = false; + for (let attempt = 0; attempt < 2 && !finished && !timedOut && !r.stopping; attempt++) { + if (attempt) { agent.reopenPlan(chat); say(r, tag + '-retry', `${tag.toUpperCase()}, trying step ${at + 1} again…`, { step: at + 1 }); } + agent.resetSession(chat); + const turn = agent.planGoal({ chatId: chat, planId, once: true, workspacePath: root, mode: 'bypass', choice, thinking, onFrame }); + let timer; + const raced = await Promise.race([turn.then(() => 'ended'), new Promise(res => { timer = setTimeout(() => res('timeout'), stepTimeoutMs); timer.unref?.(); })]); + clearTimeout(timer); + if (raced === 'timeout') { timedOut = true; try { await agent.stop(chat, { waitMs: 15_000 }); } catch { /* ending anyway */ } await turn.catch(() => {}); } + if (r.stopping) return 'stopped'; + finished = agent.planState(chat)?.steps[at]?.state === 'done'; + } + if (finished) return 'done'; + if (timedOut || isViewStep(plan.steps[at].text)) { + agent.skipStep(chat, at, timedOut ? 'This step took too long, so it was left as it is.' : 'Could not look at the page here; the files were checked instead.'); + say(r, tag + '-skip', timedOut ? `${tag.toUpperCase()}, step ${at + 1} took too long and was left as it is.` : `${tag.toUpperCase()}, step ${at + 1} (viewing the page) was skipped on this machine.`, { step: at + 1 }); + return 'skipped'; + } + return 'failed'; + } + async function runFlow(r, { choice, thinking, slots }) { const aChat = `ts:${r.id}:A`, bChat = `ts:${r.id}:B`, leverChat = `ts:${r.id}:lever`; r.chats = [aChat, bChat, leverChat]; @@ -152,21 +180,14 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n r.b.plan = bp.steps.map(s => ({ id: s.id, text: s.text })); r.b.state = 'running'; r.b.total = bp.steps.length; announce(r); for (let at = 0; at < bp.steps.length && !stopped(); at++) { - let finished = false; - for (let attempt = 0; attempt < 2 && !finished && !stopped(); attempt++) { - if (attempt) { agent.reopenPlan(bChat); say(r, 'b-retry', `B, trying step ${at + 1} again…`, { step: at + 1 }); } - agent.resetSession(bChat); - await agent.planGoal({ chatId: bChat, planId: bp.id, once: true, workspacePath: r.b.root, mode: 'bypass', choice, thinking, + const res = await runOneStep(r, { tag: 'b', chat: bChat, planId: bp.id, plan: bp, at, root: r.b.root, choice, thinking, onFrame: f => { if (f.type === 'error') r.b.note = String(f.message ?? '').slice(0, 240); if (f.type === 'goal' && f.goal?.blocked) r.b.note = String(f.goal.blocked).slice(0, 240); if (f.type === 'plan-step') { r.b.step = f.index; r.b.total = f.total; r.b.text = f.text; r.b.line = f.line; say(r, 'b-step', `B, ${f.line}`, { step: f.index, steps: f.total }); } } }); - if (stopped()) return; - finished = agent.planState(bChat)?.steps[at]?.state === 'done'; - } - if (agent.planState(bChat)?.steps[at]?.state !== 'done' && isViewStep(bp.steps[at].text)) { agent.skipStep(bChat, at, 'Could not look at the page here; the files were checked instead.'); say(r, 'b-skip', `B, step ${at + 1} (viewing the page) was skipped on this machine.`, { step: at + 1 }); } - if (!['done', 'skipped'].includes(agent.planState(bChat)?.steps[at]?.state)) break; + if (res === 'stopped') return; + if (res === 'failed') break; } const end = agent.planState(bChat); r.b.state = end?.steps.every(x => ['done', 'skipped'].includes(x.state)) ? 'done' : 'failed'; @@ -193,12 +214,7 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n // Each step is its own turn in its own agent session (the folder carries the work from step to step): a small model window never fills up // across a long plan. The fork happens between two steps, so B gets exactly the files of the finished steps. for (let at = 0; at < plan.steps.length && !stopped(); at++) { - let finished = false; - // A step that does not finish (the model stopped, a program never returned) is tried once more in a fresh session before the run gives up. - for (let attempt = 0; attempt < 2 && !finished && !stopped(); attempt++) { - if (attempt) { agent.reopenPlan(aChat); say(r, 'a-retry', `A, trying step ${at + 1} again…`, { step: at + 1 }); } - agent.resetSession(aChat); - await agent.planGoal({ chatId: aChat, planId: plan.id, once: true, workspacePath: r.a.root, mode: 'bypass', choice, thinking, + const res = await runOneStep(r, { tag: 'a', chat: aChat, planId: plan.id, plan, at, root: r.a.root, choice, thinking, onFrame: f => { if (f.type === 'error') r.a.note = String(f.message ?? '').slice(0, 240); if (f.type === 'goal' && f.goal) r.a.goal = { phase: f.goal.phase, blocked: f.goal.blocked ?? null, round: f.goal.round }; @@ -208,15 +224,8 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n say(r, 'a-step', `A, ${f.line}`, { step: f.index, steps: f.total }); } } }); - if (stopped()) return; - finished = agent.planState(aChat)?.steps[at]?.state === 'done'; - } - if (agent.planState(aChat)?.steps[at]?.state !== 'done' && isViewStep(plan.steps[at].text)) { - // a look-in-a-browser step must not fail the whole version - agent.skipStep(aChat, at, 'Could not look at the page here; the files were checked instead.'); say(r, 'a-skip', `A, step ${at + 1} (viewing the page) was skipped on this machine.`, { step: at + 1 }); - } - const now = agent.planState(aChat); - if (!now || !['done', 'skipped'].includes(now.steps[at]?.state)) break; + if (res === 'stopped') return; + if (res === 'failed') break; if (r.lever && at + 1 === r.lever.step - 1) { try { forkNow(); } catch (e) { r.b = { ...r.b, state: 'failed', note: 'B could not be prepared, so only A is shown.' }; } } } if (stopped()) return; diff --git a/apps/host/tests/helpers/scripted-worker.mjs b/apps/host/tests/helpers/scripted-worker.mjs index 17437752..73c7c5de 100644 --- a/apps/host/tests/helpers/scripted-worker.mjs +++ b/apps/host/tests/helpers/scripted-worker.mjs @@ -124,6 +124,7 @@ export async function startScriptedWorker({ port = 0, chunkDelayMs = 40, model = } return say(['Step finished. The result is checked.']); } + if (directive?.[1] === 'planslow') return say(['## Slow plan\n\n', '1. First thing SCRIPT:goalstep\n', '2. A step that never finishes SCRIPT:slow 4000\n', '3. Third thing SCRIPT:goalstep\n']); if (directive?.[1] === 'planreply') return say(['I looked around the folder first.\n\n## The pagoda plan\n\n', '1. First thing SCRIPT:goalstep\n', '2. Second thing SCRIPT:goalstep\n', '3. Third thing SCRIPT:goalstep\n']); if (last.role === 'tool') { const result = text(last).replace(/\s+/g, ' ').slice(0, 120); diff --git a/apps/host/tests/timeskip-fork.test.mjs b/apps/host/tests/timeskip-fork.test.mjs index 59c7ab96..ea091fad 100644 --- a/apps/host/tests/timeskip-fork.test.mjs +++ b/apps/host/tests/timeskip-fork.test.mjs @@ -38,13 +38,13 @@ test('copyProject leaves out dependency and VCS folders', () => { } finally { rmSync(dir, { recursive: true, force: true }); } }); -async function rig(t, slots) { +async function rig(t, slots, opts = {}) { const worker = await startScriptedWorker({}); const dir = mkdtempSync(join(tmpdir(), 'strata-tsf-')); const project = join(dir, 'project'); mkdirSync(project); writeFileSync(join(project, 'keep.txt'), 'original'); const bridge = createAgentBridge({ dataDir: join(dir, 'data'), localInstances: () => [{ id: 'i', label: 'S', baseUrl: worker.url, modelId: 'scripted-model', context: 32768, slots }], connections: () => [], env: process.env, startTimeoutMs: 90_000 }); const events = []; - const ts = createForkTimeskip({ agent: bridge, dir: join(dir, 'ts'), notify: (type, data) => events.push(data) }); + const ts = createForkTimeskip({ agent: bridge, dir: join(dir, 'ts'), notify: (type, data) => events.push(data), ...opts }); t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } }); return { ts, events, project, dir, worker }; } @@ -110,3 +110,12 @@ test('a step about looking at the page in a browser is recognised, carries the n assert.match(stepObjective(plan, 1), /Never wait for a program to close/); assert.match(stepObjective(plan, 1), /Start-Process/); assert.ok(!/Start-Process/.test(stepObjective(plan, 0))); assert.match(UNATTENDED, /Never open a visible window/); }); + +test('a step that never finishes is stopped after the time limit and left as it is with a plain note; the version still completes', { skip }, async (t) => { + const r = await rig(t, 2, { stepTimeoutMs: 4000 }); + const run = r.ts.start({ prompt: 'SCRIPT:planslow', workspace: r.project, choice: { instanceId: 'i' }, slots: 2 }); + const done = await until(() => { const s = r.ts.status(run.id); return ['completed', 'failed'].includes(s.phase) ? s : null; }, 150_000); + assert.equal(done.phase, 'completed', done.error); + assert.ok(r.events.some(e => /step 2 took too long and was left as it is/.test(e.activity?.text ?? '')), 'the person was told which step was left'); + assert.equal(done.a.state, 'done'); +}); From 7ce4b6df379cd55cbeedcaf998e0a5d6f8f77699 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 02:41:28 +0200 Subject: [PATCH 3/5] Time-skip step limit 15 minutes --- apps/host/server/timeskip-fork.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/host/server/timeskip-fork.mjs b/apps/host/server/timeskip-fork.mjs index 578f65d4..94deb33b 100644 --- a/apps/host/server/timeskip-fork.mjs +++ b/apps/host/server/timeskip-fork.mjs @@ -82,7 +82,7 @@ export function improvementPrompt({ request, steps, lever, doneSummaries }) { const stepObjectiveBriefing = ctx => ctx; -export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.now, stepTimeoutMs = 20 * 60_000 }) { +export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.now, stepTimeoutMs = 15 * 60_000 }) { mkdirSync(dir, { recursive: true }); const runs = new Map(); // id -> internal run From 1fe683e951c5cd331b8bf52fed14ca09a5cd9aa5 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 02:53:59 +0200 Subject: [PATCH 4/5] Picture input for a server on this network only when its own model list says it reads pictures (a server without a vision encoder refused whole requests) --- apps/host/server/agent/profile.mjs | 3 ++- apps/host/server/index.mjs | 14 ++++++++++--- apps/host/server/vision-probe.mjs | 31 ++++++++++++++++++++++++++++ apps/host/tests/agent-shape.test.mjs | 14 +++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 apps/host/server/vision-probe.mjs diff --git a/apps/host/server/agent/profile.mjs b/apps/host/server/agent/profile.mjs index 8879aff8..768bf0f2 100644 --- a/apps/host/server/agent/profile.mjs +++ b/apps/host/server/agent/profile.mjs @@ -233,7 +233,8 @@ export function buildProfile({ local = [], connections = [], gate = true, tools models: conn.models.map(m => ({ id: m.id, name: m.name || m.id, contextWindow: m.contextMax ?? ASSUMED_API_CONTEXT, maxTokens: reply(m), - input: ownServer ? ['text', 'image'] : ['text'], + // Pictures only when the server itself says it reads them (the host asks its model list): a server started without a vision encoder refuses the whole request when a picture is in it. + input: ownServer && m.vision === true ? ['text', 'image'] : ['text'], ...(ownServer ? { reasoning: true, reasoningEfforts: LOCAL_EFFORTS } : {}), })), }; diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs index e9377f29..0cb65c2f 100644 --- a/apps/host/server/index.mjs +++ b/apps/host/server/index.mjs @@ -48,6 +48,7 @@ import { CONTEXT_TOKENS, VARIANTS, localModels, variant } from './catalog.mjs'; import { browseLocalModels, inspectLocalModel } from './local-models.mjs'; import { EventHub, error, json, readBody, readRaw, uid } from './util.mjs'; import { createUploads } from './chat-uploads.mjs'; +import { createVisionProbe } from './vision-probe.mjs'; import { isPrivateHost } from './agent/llm-shape.mjs'; import { RequestQueue } from './request-queue.mjs'; import { selectSkills, skillInstructions } from './skill-selection.mjs'; @@ -118,6 +119,7 @@ const native=createNativeControl({control,appUpdater,hardwareProbe:()=>(hardware const llmProxy = createLlmProxy({ targetOf: key => agent.llmTarget(key), samplingNow: () => samplingFromExpert(store.get().expert) }); const agentTools = createAgentTools({ read: () => store.get().agentTools, write: value => store.update({ agentTools: value }), dataDir: store.DATA_DIR, browser: () => ({ ...findBrowser(), cli: findPlaywrightMcp(agent.harnessDir()) }) }); agentTools.ensureFile(); +const visionProbe = createVisionProbe(); const agent = createAgentBridge({ tools: () => agentTools.profileView(), skillsDir: () => AGENT_SKILLS, @@ -139,7 +141,7 @@ const agent = createAgentBridge({ // The tool servers set up for this model (Settings, Tools): the agent connects to the same ones. mcpServers: i.mcpServers, })), - connections: () => modelProviders.withSecrets(), + connections: () => modelProviders.withSecrets().map(c => ({ ...c, models: c.models.map(m => ({ ...m, vision: visionProbe.known(c, m.id) })) })), log: line => console.log(line), }); let storageChanging = false; @@ -523,7 +525,12 @@ async function runAgentTurn({ res, controller, chatId, body, message, workspaceI const write = frame => { if (!res.writableEnded && !res.destroyed) res.write(`${JSON.stringify(frame)}\n`); }; const cwd = chatFolders.get(chatId) ?? (workspaceId ? workspaces.find(w => w.id === workspaceId)?.path : null) ?? WORKSPACE; let choice, instance = null; - if (body.remoteModel) choice = { connectionId: String(body.remoteModel.connectionId), modelId: String(body.remoteModel.modelId) }; + if (body.remoteModel) { + choice = { connectionId: String(body.remoteModel.connectionId), modelId: String(body.remoteModel.modelId) }; + // Does this server read pictures? Asked before the agent is built, so a picture is never sent to one that cannot. + const own = modelProviders.withSecrets().find(c => c.id === choice.connectionId); + if (own && own.protocol === 'openai-chat' && isPrivateHost(own.baseUrl)) await visionProbe.check(own, choice.modelId); + } else { try { instance = native.resolveInstance(body.nativeModelId ?? native.state().defaultId); } catch (e) { write({ type: 'error', message: e.message }); return; } @@ -1031,7 +1038,8 @@ async function api(req, res, path, method, url) { if (resolve(cwd) === resolve(ROOT) || resolve(cwd).startsWith(resolve(ROOT) + sep)) return error(res, 400, 'Time-skip works on a folder of your own. Choose a workspace folder for this chat, then try again.'); if (measureFolder(cwd).tooBig) return error(res, 400, 'This folder is too big to try a change on a copy. Open a smaller folder for this chat, then try again.'); let choice, slots = 1; - if (body.remoteModel?.connectionId && body.remoteModel?.modelId) { choice = { connectionId: String(body.remoteModel.connectionId), modelId: String(body.remoteModel.modelId) }; slots = Number(body.slots) >= 1 ? Math.floor(Number(body.slots)) : 1; } + if (body.remoteModel?.connectionId && body.remoteModel?.modelId) { choice = { connectionId: String(body.remoteModel.connectionId), modelId: String(body.remoteModel.modelId) }; + { const own = modelProviders.withSecrets().find(c => c.id === choice.connectionId); if (own && own.protocol === 'openai-chat' && isPrivateHost(own.baseUrl)) await visionProbe.check(own, choice.modelId); } slots = Number(body.slots) >= 1 ? Math.floor(Number(body.slots)) : 1; } else { try { const inst = native.resolveInstance(native.state().defaultId); choice = { instanceId: inst.id }; slots = inst.metrics?.live?.slots?.length || inst.parallel || 1; } catch { return error(res, 503, 'Load a model first, then try Time-skip again.'); } } const chatId = typeof body.sessionId === 'string' && body.sessionId ? body.sessionId : null; if (chatId && forkTs.byChat(chatId)) return error(res, 409, 'A Time-skip is already running in this chat.'); diff --git a/apps/host/server/vision-probe.mjs b/apps/host/server/vision-probe.mjs new file mode 100644 index 00000000..9d66a51b --- /dev/null +++ b/apps/host/server/vision-probe.mjs @@ -0,0 +1,31 @@ +/** + * Does a model server on this network read pictures? Asked of its own model list (`/models`, `architecture.input_modalities`), cached for a + * few minutes. Unknown or unreachable counts as "no": a picture sent to a server without a vision encoder makes the whole request fail. + */ +const TTL_MS = 5 * 60_000; + +export function createVisionProbe({ fetcher = fetch, now = Date.now } = {}) { + const cache = new Map(); // key -> { at, value } + const keyOf = (conn, modelId) => `${conn.id}|${modelId}`; + return { + /** Last known answer for a model (true / false), or undefined when never asked. */ + known: (conn, modelId) => { const e = cache.get(keyOf(conn, modelId)); return e ? e.value : undefined; }, + /** Ask now (at most once per TTL per model). */ + async check(conn, modelId) { + const k = keyOf(conn, modelId); const hit = cache.get(k); + if (hit && now() - hit.at < TTL_MS) return hit.value; + let value = false; + try { + const res = await fetcher(String(conn.baseUrl).replace(/\/+$/, '') + '/models', { headers: conn.apiKey ? { authorization: `Bearer ${conn.apiKey}` } : {}, signal: AbortSignal.timeout(4000) }); + if (res.ok) { + const list = (await res.json())?.data ?? []; + const row = list.find(m => m?.id === modelId) ?? (list.length === 1 ? list[0] : null); + const modes = row?.architecture?.input_modalities ?? row?.input_modalities ?? []; + value = Array.isArray(modes) && modes.includes('image'); + } + } catch { value = false; } + cache.set(k, { at: now(), value }); + return value; + }, + }; +} diff --git a/apps/host/tests/agent-shape.test.mjs b/apps/host/tests/agent-shape.test.mjs index 0094aa93..37d81862 100644 --- a/apps/host/tests/agent-shape.test.mjs +++ b/apps/host/tests/agent-shape.test.mjs @@ -7,6 +7,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { BUDGETS, createLlmProxy, isPrivateHost, nearestBudget, samplingFromExpert, shapeBody } from '../server/agent/llm-shape.mjs'; import { buildProfile } from '../server/agent/profile.mjs'; +import { createVisionProbe } from '../server/vision-probe.mjs'; import { startScriptedWorker } from './helpers/scripted-worker.mjs'; import { createAgentBridge } from '../server/agent/agent-bridge.mjs'; import { resolveHarness } from '../server/agent/harness-runtime.mjs'; @@ -126,3 +127,16 @@ test('a turn uses the response-settings route only when a setting is changed: th await run('s8', { thinking: 'Medium' }); assert.equal(last().temperature, undefined, 'back to defaults: straight to the model again'); }); + +test('a model server on this network gets picture input only when its own model list says it reads pictures', async () => { + const lists = { yes: { data: [{ id: 'm', architecture: { input_modalities: ['text', 'image'] } }] }, no: { data: [{ id: 'm', architecture: { input_modalities: ['text'] } }] } }; + let which = 'yes'; + const probe = createVisionProbe({ fetcher: async () => ({ ok: true, json: async () => lists[which] }) }); + const conn = { id: 'c', baseUrl: 'http://127.0.0.1:1/v1', apiKey: '' }; + assert.equal(probe.known(conn, 'm'), undefined); + assert.equal(await probe.check(conn, 'm'), true); assert.equal(probe.known(conn, 'm'), true); + which = 'no'; assert.equal(await probe.check(conn, 'm'), true, 'cached for a few minutes'); + assert.equal(await createVisionProbe({ fetcher: async () => { throw new Error('down'); } }).check(conn, 'm'), false, 'unreachable counts as no'); + const build = vision => JSON.parse(buildProfile({ local: [], connections: [{ id: 'own', name: 'Own', baseUrl: 'http://127.0.0.1:18798/v1', protocol: 'openai-chat', apiKey: '', models: [{ id: 'm', contextMax: 32768, vision }] }] }).patch.slice(buildProfile({ local: [], connections: [] }).patch.indexOf('['))).find(e => e.id === 'llm-pi-ai').config.providers['api-own'].models[0].input; + assert.deepEqual(build(true), ['text', 'image']); assert.deepEqual(build(false), ['text']); assert.deepEqual(build(undefined), ['text']); +}); From e3bf0ad04d4e72c50a09e3036a9a81dddaf9e35f Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 05:02:30 +0200 Subject: [PATCH 5/5] Time-skip: final 'Both versions are ready' line, no stale warning after B finished --- apps/host/server/timeskip-fork.mjs | 5 ++++- apps/host/tests/timeskip-fork.test.mjs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/host/server/timeskip-fork.mjs b/apps/host/server/timeskip-fork.mjs index 94deb33b..f3c0ea37 100644 --- a/apps/host/server/timeskip-fork.mjs +++ b/apps/host/server/timeskip-fork.mjs @@ -191,6 +191,7 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n } const end = agent.planState(bChat); r.b.state = end?.steps.every(x => ['done', 'skipped'].includes(x.state)) ? 'done' : 'failed'; + if (r.b.state === 'done') r.b.note = end.steps.some(x => x.state === 'skipped') ? 'A step that could not finish was left as it is.' : null; if (r.b.state === 'failed') r.b.note = stopped() ? 'Stopped.' : 'B did not finish, so only A is shown.'; announce(r); }; @@ -238,7 +239,9 @@ export function createForkTimeskip({ agent, dir, notify = () => {}, now = Date.n if (bDone) await bDone.catch(e => { r.b.state = 'failed'; r.b.note = 'B stopped: ' + String(e.message ?? e).slice(0, 160); }); if (stopped()) return; setPhase(r, 'checking'); say(r, 'comparing', 'Comparing A and B…'); - r.finishedAt = now(); r.activity = null; setPhase(r, 'completed'); + r.finishedAt = now(); + r.activity = r.b?.state === 'done' ? { code: 'ready', text: 'Both versions are ready. Compare A and B, then keep the one you like.', args: {} } : { code: 'ready', text: 'The result is ready.' + (r.b?.note ? ' ' + r.b.note : ''), args: {} }; + setPhase(r, 'completed'); } catch (e) { if (stopped()) return; r.error = String(e.message ?? e).slice(0, 400); r.finishedAt = now(); r.activity = null; setPhase(r, 'failed'); diff --git a/apps/host/tests/timeskip-fork.test.mjs b/apps/host/tests/timeskip-fork.test.mjs index ea091fad..10d783db 100644 --- a/apps/host/tests/timeskip-fork.test.mjs +++ b/apps/host/tests/timeskip-fork.test.mjs @@ -61,6 +61,7 @@ test('plan -> lever (with its why) -> A runs every step -> B forks after step 1 assert.deepEqual([done.a.state, done.a.step, done.a.total], ['done', 3, 3]); assert.equal(done.b.state, 'done'); assert.equal(done.b.plan.length, 2); assert.equal(done.needsUserReview, true); + assert.match(done.activity.text, /^Both versions are ready/); assert.equal(done.b.note ?? null, null, 'no stale warning when B finished'); assert.deepEqual(done.labels, { original: 'A', updated: 'B' }); // events told the story in order const phases = r.events.map(e => e.phase);