Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

fix(portal): a build that published a preview ends calmly when the tool limit stops it (#8198)

Mike Bradley99c48a5b9af3
diff --git a/ods/extensions/services/dashboard/src/lib/portalDeliveryNotes.js b/ods/extensions/services/dashboard/src/lib/portalDeliveryNotes.js
index cf5d24806..07857c257 100644
--- a/ods/extensions/services/dashboard/src/lib/portalDeliveryNotes.js
+++ b/ods/extensions/services/dashboard/src/lib/portalDeliveryNotes.js
@@ -1,9 +1,10 @@
// Portal's own one-line notes about a reply's preview: what its checks could
-// not confirm, a page that broke while it tested it, an earlier version, a
-// step that has not started, or a preview it could not publish. Each is a
-// paragraph of its own after the reply, shown muted and never as an alert.
-// The pixel-agent plugin writes them (plugin/preview-explanation.mjs and
-// tool-loop-guard.mjs); its tests keep this list equal to the plugin's.
+// not confirm or finish, a page that broke while it tested it, an earlier
+// version, a step that has not started, or a preview it could not publish or
+// a build that stopped first. Each is a paragraph of its own after the reply,
+// shown muted and never as an alert. The pixel-agent plugin writes them
+// (plugin/preview-explanation.mjs and tool-loop-guard.mjs); its tests keep
+// this list equal to the plugin's.
export const DELIVERY_NOTES = Object.freeze([
"Portal couldn't test every control automatically. Try it, and tell Portal if something isn't right.",
"Portal couldn't confirm everything automatically. Have a look, and tell Portal if something isn't right.",
@@ -12,7 +13,10 @@ export const DELIVERY_NOTES = Object.freeze([
"The page doesn't match everything you asked for yet. Ask Portal to fix it.",
"This preview shows the version from before Portal's latest changes. Ask Portal to publish the current files.",
'Portal stopped before it finished, so this preview shows an earlier version. Send a message to continue.',
+ "Portal published your page but couldn't finish checking it automatically. Try it, and tell Portal if something isn't right.",
+ 'Portal stopped before it finished, so this page may not have everything you asked for yet. Send a message to continue.',
"The next step above hasn't started yet. Send a message to continue.",
"Portal saved the website files in your workspace but couldn't publish a preview of them, so they haven't been checked and there is no preview to open yet. Ask Portal to publish the preview.",
"Portal didn't create the website files for this request, so there is no preview to open yet. Ask Portal to try the build again.",
+ "Portal stopped before it finished because it wasn't making progress.",
])
diff --git a/ods/extensions/services/pixel-agent/COMPLETION-RELIABILITY.md b/ods/extensions/services/pixel-agent/COMPLETION-RELIABILITY.md
index c9a694811..e4badb051 100644
--- a/ods/extensions/services/pixel-agent/COMPLETION-RELIABILITY.md
+++ b/ods/extensions/services/pixel-agent/COMPLETION-RELIABILITY.md
@@ -501,14 +501,25 @@ web-loop terminal (a web tool requested again after two research-budget
refusals) stops a response, the limits are unchanged and every tool stays
blocked. `progress-finalization.mjs`
grants one tool-free answer turn instead of discarding the gathered evidence.
-OpenClaw applies `tool_result_persist` to the saved transcript only, so the
-model learns of the stop through the refusal of its next tool call, whose text
-is one fixed instruction: answer from evidence already returned, keep the
-requested format, and mark missing or unverified items. The following model
+The model learns of the stop from one fixed instruction: answer from evidence
+already returned, keep the requested format, and mark missing or unverified
+items. On ODS's Pixel runtime the result persisted for a call is what the next
+model request carries (`host/openclaw-compaction-budget.json`), so while the
+answer turn is still ahead every result persisted after the stop carries that
+instruction, starting with the result that stopped the run, and the refusal of
+the next tool call carries it too. Before 2026-10-25 those results, the refusal
+included, were persisted as the stop text, which says to continue "with a
+corrected approach": the model never read the instruction, and on the RTX Spark
+it kept calling tools and forfeited the turn. The model call after a refused
call is the answer turn. Parallel siblings in the refused call's model round
receive the same instruction; with no observed model round, the next tool call
ends the run. A model that answers without another tool call is treated the
-same way. OpenClaw's in-session auto-compaction summarizes through the run's own
+same way. Once the turn is spent, persisted results carry the stop text. When
+a failed preview check of the current publication is what stopped the run, the
+instruction is `PREVIEW_CHECK_FINALIZATION_INSTRUCTION`: stop checking, the page
+is published and the owner sees its preview, say briefly what was built and
+plainly what could not be verified, claim no check that did not pass, and add no
+preview link. OpenClaw's in-session auto-compaction summarizes through the run's own
model stream; the summarization calls it starts (at most two, bracketed by
`before_compaction`) are not counted as turns, so a compaction after the answer
cannot forfeit it. Any other further model call still does.
@@ -518,7 +529,9 @@ the tool-limit note, a failed or pending test result, cited links that were
never read (when the owner asked for sources to be opened), and the last
verified preview (with any owner-requested text the published page lacks) or an
explicit statement that none was verified. The outcome stays `failed`; a
-research-loop stop also notes that the web research allowance was used up.
+research-loop stop also notes that the web research allowance was used up. In a
+website build these facts stay the record, and the owner reads Portal's wording
+of them instead ("A tool-limit stop after a preview" below).
Plugins cannot remove tools from a single model call, so some models still
call a tool in the answer turn. That call is refused and the run is aborted at
@@ -543,8 +556,10 @@ current-run `web_fetch` and targeted-extraction read receipts plus host
citation verifications, deduplicated, at most eight with a count of the rest,
each with its page-reported title reduced to plain words when one is known.
Only the list varies. Operations, exact downloads, managed extension requests
-and team coordination keep the strict stop text, with no list. The instruction
-is constant text at the end of the conversation, never system-prompt content.
+and team coordination keep the strict stop text, with no list. In a website
+build the owner reads Portal's wording of that fallback (below). Both
+instructions are constant text at the end of the conversation, never
+system-prompt content.
### Stop synthesis
@@ -867,9 +882,11 @@ Portal's text in the owner's wording (next section).
holds exactly that visible text. When that turn has none, OpenClaw 2026.6.33
fills `lastAssistantMessage` with the joined narration of earlier tool-call
turns, which is no reply. Any later model call, and an owner cancel, clear it.
-- The ingress verification schema is unchanged. A tool-limit,
- recursive-delete or clarification delivery keeps its own text; a run
- deadline or output limit quotes the preview outcome in the owner's wording.
+- The ingress verification schema is unchanged. A recursive-delete or
+ clarification delivery keeps its own text; a run deadline or output limit
+ quotes the preview outcome in the owner's wording. A tool-limit stop in a
+ website build reads in the owner's wording too, with only the answer that stop
+ accepts ("A tool-limit stop after a preview").
- The reply is filtered like a tool-limit answer, not scrubbed: a path or other
text the agent quotes is delivered as in any passing reply. It is never
evidence, and no wording heuristic reads it: a claim of success in any
@@ -929,6 +946,60 @@ imitated notes, passing, pending, page-error and stale checks, local links,
code fences), and checks that no line after a published preview reads as an
error.
+## A tool-limit stop after a preview
+
+On the RTX Spark (2026-10-25, "Make me a simple stopwatch web page with start,
+stop and lap buttons", seen twice), the model wrote and published the page,
+and the preview card worked. Its next three preview checks failed on its own
+plan mistakes ("Step 4 matched the element but did not observe its requested
+visibility", "Step 7 (assert-text) matched 2 elements", then a generic
+failure), which used up the run-progress budget. The model never read the
+answer instruction (see "Tool-limit finalization"), so every later call was
+refused, and the owner read under the working card: "This response was stopped
+after repeated tool failures or attempts without progress. ... The full request
+was not completed ... This is the last verified publication, not proof that all
+requested work completed."
+
+The budget, the refusals and the stop are unchanged; the third failed check now
+carries the wrap-up instruction to the model. The stop's text stays the record,
+and in a website build the owner reads Portal's wording instead
+(`progressStopPresentation` in `tool-loop-guard.mjs`, through the same
+`previewPresentations` as above):
+
+- The answer the stop accepts, if any, comes first: the model's tool-free
+ answer, a partial answer, or the stop synthesis with its note and pages. Links
+ it cites that no read receipt covers are still listed. A partial answer (its
+ calls were refused) or one that announces more work ("Now let me add the Stop
+ and Lap buttons.") is followed by "The next step above hasn't started yet.
+ Send a message to continue." in place of the lines below.
+- With the current publication: one muted line, then the receipt, which the
+ dashboard shows as the preview card. The line is the page's own known gap (a
+ script problem, requested text missing). Otherwise, when failed preview checks
+ stopped the run, it is "Portal published your page but couldn't finish
+ checking it automatically. Try it, and tell Portal if something isn't
+ right."; for any other stop (edits that kept failing, say) the build itself
+ may be unfinished: "Portal stopped before it finished, so this page may not
+ have everything you asked for yet. Send a message to continue."
+- With only an earlier publication (files changed since): "Portal stopped before
+ it finished, so this preview shows an earlier version. Send a message to
+ continue.", then the link to that publication.
+- With no publication, the stop is a real failure and says so plainly: "Portal
+ stopped before it finished because it wasn't making progress.", the line that
+ says what there is and what to do next ("Portal saved the website files ...
+ Ask Portal to publish the preview." or "Portal didn't create the website files
+ ... Ask Portal to try the build again."), and "If it keeps happening, get help
+ on Discord" with the invite link.
+
+Research and coding runs keep their stop texts, and so does every run that
+keeps the strict stop (finalization unavailable), a website build included when
+it also asked for a managed installation: its stop text says the request was not
+completed. When the runtime itself rejects a call made after the stop (before
+`before_tool_call` runs), the persisted result that carries the instruction
+counts as the instruction's delivery, so the next model call is the answer turn
+rather than a second uninstructed call that forfeits it.
+`tests/preview_check_stop_delivery.test.mjs` replays the stopwatch run and the
+review's four stops through the real guard and inspection tool.
+
## Passing checks that do not count
On the RTX Spark (stopwatch), the first interaction check failed at step 2.
diff --git a/ods/extensions/services/pixel-agent/plugin/preview-explanation.mjs b/ods/extensions/services/pixel-agent/plugin/preview-explanation.mjs
index ce9da1bda..2faffed66 100644
--- a/ods/extensions/services/pixel-agent/plugin/preview-explanation.mjs
+++ b/ods/extensions/services/pixel-agent/plugin/preview-explanation.mjs
@@ -9,7 +9,9 @@
// (2026-10-25) two of four builds ended with only that fact text under a
// preview that worked. The outcome keeps its status and its preview receipt,
// and nothing here certifies anything: each line says what Portal could not
-// confirm, or what is wrong, and what the owner can do next.
+// confirm, or what is wrong, and what the owner can do next. A tool-limit stop
+// in a website build reads the same way (tool-loop-guard.mjs,
+// progressStopPresentation).
//
// The agent's explanation. A failed or still-running preview outcome (a
// browser or interaction check that did not pass, requested text missing, a
@@ -47,10 +49,20 @@ export const PREVIEW_EARLIER_NOTE =
"This preview shows the version from before Portal's latest changes. Ask Portal to publish the current files.";
export const PREVIEW_STOPPED_NOTE =
'Portal stopped before it finished, so this preview shows an earlier version. Send a message to continue.';
+// The tool limit stopped the run after the page was published: the page is
+// current and up, and failed checks of it are what stopped the run (RTX Spark,
+// 2026-10-25: the model's own check plans kept failing under a working page).
+export const PREVIEW_UNFINISHED_NOTE =
+ "Portal published your page but couldn't finish checking it automatically. Try it, and tell Portal if something isn't right.";
+// The tool limit stopped the run for any other reason after the page was
+// published: the build itself may be unfinished (edits that kept failing).
+export const PREVIEW_INCOMPLETE_NOTE =
+ 'Portal stopped before it finished, so this page may not have everything you asked for yet. Send a message to continue.';
// The run has ended: a step the reply announces will not start on its own.
export const PREVIEW_CONTINUE_NOTE = "The next step above hasn't started yet. Send a message to continue.";
export const PREVIEW_NOTES = Object.freeze([PREVIEW_CONTROLS_NOTE, PREVIEW_UNCONFIRMED_NOTE, PREVIEW_RUNNING_NOTE,
- PREVIEW_SCRIPT_NOTE, PREVIEW_MISSING_NOTE, PREVIEW_EARLIER_NOTE, PREVIEW_STOPPED_NOTE, PREVIEW_CONTINUE_NOTE]);
+ PREVIEW_SCRIPT_NOTE, PREVIEW_MISSING_NOTE, PREVIEW_EARLIER_NOTE, PREVIEW_STOPPED_NOTE, PREVIEW_UNFINISHED_NOTE,
+ PREVIEW_INCOMPLETE_NOTE, PREVIEW_CONTINUE_NOTE]);
// The combined reply is host verification text (ingress limit: 32 KiB). Leave
// room for the extension and progress-lane notes that can follow it.
@@ -91,7 +103,7 @@ export function openFence(text) {
// The reply announces more work: a first-person promise anywhere, or a last
// sentence that narrates the next action ("Now let me republish the preview.").
-function announcesMoreWork(answer) {
+export function announcesMoreWork(answer) {
const line = answer.split('\n').map(value => value.trim()).filter(Boolean).at(-1) ?? '';
const sentence = line.split(/(?<=[.!?])\s+(?=\S)/).at(-1).replace(/^[\s>#*_`|~+\-–—•]*(?:\d{1,3}[.)]\s*)?[\s*_`]*/u, '');
return promisesExecution(answer) || NARRATION.test(sentence);
@@ -112,9 +124,11 @@ export function previewCheckNote({pending = false, pageErrors = false, missing =
// preview outcome's own host text, the part of it the owner keeps (its preview
// receipt or link) and Portal's line. Within `text`, which can carry other
// host lines around that host text (a missing download, a stopped lane), the
-// host text becomes `line` and the kept part. Without it, `line` leads.
+// host text becomes `line` and the kept part. Without it, `line` leads. Host
+// text follows any answer in `text` (a tool-limit stop's answer comes first),
+// so its last occurrence is the one replaced.
export function ownerPreviewText(text, presentation, line = presentation?.note) {
- const at = presentation ? text.indexOf(presentation.text) : -1;
+ const at = presentation ? text.lastIndexOf(presentation.text) : -1;
if (at < 0) return line ? `${line}\n\n${text}` : text;
return text.slice(0, at) + [line, presentation.rest].filter(Boolean).join('\n\n') +
text.slice(at + presentation.text.length);
diff --git a/ods/extensions/services/pixel-agent/plugin/progress-finalization.mjs b/ods/extensions/services/pixel-agent/plugin/progress-finalization.mjs
index f4128a5b6..4457944bc 100644
--- a/ods/extensions/services/pixel-agent/plugin/progress-finalization.mjs
+++ b/ods/extensions/services/pixel-agent/plugin/progress-finalization.mjs
@@ -1,16 +1,19 @@
// Graceful finalization after the run-progress budget stops a response.
//
// The budget is unchanged. Once it is exhausted every tool stays blocked. The
-// next refused tool call carries one fixed instruction (OpenClaw's
-// before_tool_call blockReason is the only text that reaches the live model:
-// tool_result_persist rewrites the saved transcript only), and the model then
+// next refused tool call carries one fixed instruction, and the model then
// gets exactly one tool-free turn to answer from evidence the run already
-// returned. A tool call in that turn still ends the run at that boundary, but
-// substantive answer text in the same message is kept as a partial answer (the
-// calls are refused and never run). Any further model call, or an empty or
-// degenerate answer, falls back to the canned stop text, followed by the
-// host's list of pages read successfully in the response, unless the stop
-// synthesis (stop-synthesis.mjs) answers from those pages first.
+// returned. On ODS's Pixel runtime the result persisted for a call is what the
+// next model request carries (host/openclaw-compaction-budget.json), so while
+// that turn is open the results persisted after the stop carry the same
+// instruction, beginning with the result that stopped the run
+// (tool-loop-guard.mjs toolResultPersist). A tool call in that turn still ends
+// the run at that boundary, but substantive answer text in the same message is
+// kept as a partial answer (the calls are refused and never run). Any further
+// model call, or an empty or degenerate answer, falls back to the canned stop
+// text, followed by the host's list of pages read successfully in the
+// response, unless the stop synthesis (stop-synthesis.mjs) answers from those
+// pages first.
import { RUN_PROGRESS_STOP_REASON } from './run-progress-budget.mjs';
import { promisesExecution } from './completion-assurance.mjs';
@@ -25,6 +28,17 @@ export const PROGRESS_FINALIZATION_INSTRUCTION =
'(use null where the format needs a value) and briefly say why. Do not invent values, sources or results. ' +
'Do not claim a publication, preview URL, passing test or saved file that a tool result above did not confirm.';
+// The same stop when failed preview checks used up the budget after the page
+// was published (RTX Spark, 2026-10-25: three checks failed on the model's own
+// plans under a working preview). The page is there and the owner sees it, so
+// the answer says what was built and plainly what could not be verified.
+export const PREVIEW_CHECK_FINALIZATION_INSTRUCTION =
+ '[ODS Pixel tool limit] Stop checking the preview now: tools are disabled for the rest of this response, ' +
+ 'and calling one discards your answer. Your page is published, and Portal shows the owner its preview. ' +
+ 'Give your final answer now from the tool results above: say briefly what you built, and say plainly which ' +
+ 'requested behavior you could not verify. Do not claim that a check passed unless a tool result above shows it ' +
+ 'passed, and do not add a preview link or embed: Portal shows the preview.';
+
export const PROGRESS_FINALIZATION_NOTE =
'**Partial answer: Portal reached its tool limit.** This response was stopped after repeated tool failures ' +
'or attempts without progress. The answer above was written from evidence gathered before the stop and may be ' +
@@ -129,23 +143,33 @@ export function composeReadPages(pages) {
return `${PROGRESS_READ_PAGES_HEADING}\n\n${lines.join('\n')}`;
}
+// The answer as composed ahead of the host facts: an open code fence closed.
+export function progressFinalizationHead(answer) {
+ const fences = [...answer.matchAll(/^[ \t]{0,3}(`{3,}|~{3,})/gm)].map(match => match[1]);
+ return fences.length % 2 ? `${answer}\n${fences.at(-1)}` : answer;
+}
+
+// The answer's own links that no read receipt covers, or '' when none.
+export function unverifiedLinksNote(unverifiedLinks = []) {
+ const links = unverifiedLinks.filter(url => typeof url === 'string' && url.length <= 2048).slice(0, 5);
+ return links.length ? 'These linked pages were not read successfully in this response and remain unverified: ' +
+ links.map(url => `<${url}>`).join(', ') + '.' : '';
+}
+
// Model answer first (the requested format stays intact), then host facts.
// `synthesis` marks a stop synthesis (stop-synthesis.mjs): its note, and the
// pages it was given, listed last.
export function composeProgressFinalization(answer, {preview, previewExpected = false,
verificationStatus, researchLimit = false, unverifiedLinks = [], refusedToolCalls = false,
requestedTextMissing, synthesis} = {}) {
- const fences = [...answer.matchAll(/^[ \t]{0,3}(`{3,}|~{3,})/gm)].map(match => match[1]);
- const closing = fences.length % 2 ? `\n${fences.at(-1)}` : '';
const facts = [PROGRESS_FINALIZATION_NOTE];
if (refusedToolCalls) facts.push(PROGRESS_FINALIZATION_REFUSED_CALLS_NOTE);
if (typeof synthesis?.note === 'string' && synthesis.note) facts.push(synthesis.note);
if (researchLimit) facts.push("This response's web research allowance was used up, so no further sources could be read.");
if (verificationStatus === 'failed') facts.push('The latest recognized test or verification command failed.');
else if (verificationStatus === 'pending') facts.push('A recognized test or verification command had not finished, so its result is unverified.');
- const links = unverifiedLinks.filter(url => typeof url === 'string' && url.length <= 2048).slice(0, 5);
- if (links.length) facts.push('These linked pages were not read successfully in this response and remain unverified: ' +
- links.map(url => `<${url}>`).join(', ') + '.');
+ const links = unverifiedLinksNote(unverifiedLinks);
+ if (links) facts.push(links);
if (preview?.url) {
facts.push(`[Open last published preview](${preview.url})`,
'This is the last verified publication, not proof that all requested work completed.');
@@ -153,7 +177,7 @@ export function composeProgressFinalization(answer, {preview, previewExpected =
} else if (previewExpected) facts.push('ODS did not verify a preview in this response. No localhost URL is live or claimed.');
const pages = synthesis ? composeReadPages(synthesis.pages) : '';
if (pages) facts.push(pages);
- return `${answer}${closing}\n\n${facts.join('\n\n')}`;
+ return `${progressFinalizationHead(answer)}\n\n${facts.join('\n\n')}`;
}
// Per-run state. Phases:
diff --git a/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs b/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs
index bf3205648..1a663a3f3 100644
--- a/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs
+++ b/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs
@@ -33,7 +33,8 @@ import { parseQuestions, questionsText, requestsChoiceQuestion, choiceQuestionFr
import { answersClarification, clarificationAnswerContext } from "./pending-clarification.mjs";
import { createRunProgressBudget, failedToolOutcome, isLiteralEcho, lookupFoundNothing, nodeReportedFailure, progressLaneStopReason, RUN_PROGRESS_STOP_REASON } from "./run-progress-budget.mjs";
import { assistantMessageText, composeProgressFinalization, composeReadPages, createProgressFinalization, partialFinalizationAnswer,
- PROGRESS_FINALIZATION_INSTRUCTION } from "./progress-finalization.mjs";
+ PREVIEW_CHECK_FINALIZATION_INSTRUCTION, PROGRESS_FINALIZATION_INSTRUCTION, progressFinalizationHead,
+ unverifiedLinksNote } from "./progress-finalization.mjs";
import { STOP_SYNTHESIS_LIMITS, STOP_SYNTHESIS_NOTE, synthesisAnswer, synthesisRequest } from "./stop-synthesis.mjs";
import { createRunDeadline, runDeadlineReached, runDeadlineStopText, takeRunDeadlineNotice } from "./run-deadline.mjs";
import { outputLimitContext, outputLimitCut, outputLimitNotice, outputLimitStopText } from "./output-limit.mjs";
@@ -51,7 +52,8 @@ import { PREVIEW_INSPECTION_TOOL, requestsVisibilityInteraction, requestsBehavio
attemptedPreviewBehavior, boundPreviewBehavior, previewBehaviorInstruction, unassertedBehaviorStep } from './preview-interaction-assurance.mjs';
import { workspaceRevalidationCandidate, workspaceReadOnlyCall, settledRevalidationReceipt, boundedPreviewVerification } from "./preview-revalidation.mjs";
import { boundedPreviewDelivery } from './preview-delivery-recovery.mjs';
-import { PREVIEW_EARLIER_NOTE, PREVIEW_STOPPED_NOTE, explainedPreviewDelivery, ownerPreviewText,
+import { PREVIEW_CONTINUE_NOTE, PREVIEW_EARLIER_NOTE, PREVIEW_INCOMPLETE_NOTE, PREVIEW_MISSING_NOTE, PREVIEW_SCRIPT_NOTE,
+ PREVIEW_STOPPED_NOTE, PREVIEW_UNFINISHED_NOTE, announcesMoreWork, explainedPreviewDelivery, ownerPreviewText,
previewCheckNote } from './preview-explanation.mjs';
import { extractRequestedLiterals, requestedTextCheck, requestedTextInstruction, requestedTextRevisionInstruction,
requestedTextDeliveryNote, publishedElementOutline, extractRequestedControlNames, requestedControlSources,
@@ -334,6 +336,13 @@ export const WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX =
export const WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX =
"Portal didn't create the website files for this request, so there is no preview to open yet. Ask Portal to try the build again.";
+// A tool-limit stop in a website build before any preview was published: this
+// line, then one of the two above with what there is and what to do next, then
+// PROGRESS_STOP_HELP (a link, so not one of the muted lines).
+export const PROGRESS_STOPPED_DELIVERY_PREFIX =
+ "Portal stopped before it finished because it wasn't making progress.";
+export const PROGRESS_STOP_HELP = "If it keeps happening, [get help on Discord](https://discord.gg/4ntNp9MAwC).";
+
export const WORKSPACE_PREVIEW_PUBLISHED_DELIVERY_PREFIX =
"Your preview is ready.";
@@ -8496,6 +8505,40 @@ export function createToolLoopGuard({
return finalization;
}
+ // The one fixed answer instruction. When a failed preview check of the
+ // current publication is what stopped the run, it tells the model to stop
+ // checking and say what it built and could not verify.
+ function finalizationInstruction(state) {
+ return state.progressStoppedByPreviewCheck && state.workspacePreview
+ ? PREVIEW_CHECK_FINALIZATION_INSTRUCTION : PROGRESS_FINALIZATION_INSTRUCTION;
+ }
+
+ // Charges one tool result to the progress budget and remembers a failed
+ // preview check that stopped the run (finalizationInstruction).
+ function observeProgress(state, outcome, tool) {
+ const running = !state.progressBudget.exhausted;
+ state.progressBudget.observeResult(outcome);
+ if (!running || !state.progressBudget.exhausted) return;
+ // The calls of this model round were made before the stop (deliverInstruction).
+ state.progressStopRound = state.operationsPromptRound;
+ if (outcome.failed && tool === PREVIEW_INSPECTION_TOOL && state.workspacePreview) state.progressStoppedByPreviewCheck = true;
+ }
+
+ // A result persisted for a call made after the stop, that no refusal
+ // instructed (the runtime rejected it before before_tool_call), hands the
+ // model the instruction just as a refusal does: the next model call is the
+ // single answer turn, not a second uninstructed call that forfeits it. The
+ // result of a call made before the stop changes no phase, so the model call
+ // that reads it may still answer or be refused with the instruction.
+ function deliverInstruction(state, toolCallId) {
+ const finalization = progressFinalization(state);
+ if (finalization.phase === 'pending' && state.progressStopRound !== undefined &&
+ state.operationsPromptRound > state.progressStopRound) {
+ finalization.toolBoundary(state.operationsPromptRound, toolCallId);
+ }
+ return finalization;
+ }
+
// Session history can contain an unrelated publication. Preserve it for
// current preview work, but do not attach it to a later research failure.
function progressStopPreview(state) {
@@ -8613,7 +8656,7 @@ export function createToolLoopGuard({
if (state?.progressBudget.exhausted && progressFinalization(state).phase !== 'unavailable') {
const callId = context?.toolCallId ?? event?.toolCallId;
if (state.progressFinalization.toolBoundary(state.operationsPromptRound, callId) === 'instruct') {
- return {block:true, blockReason:PROGRESS_FINALIZATION_INSTRUCTION};
+ return {block:true, blockReason:finalizationInstruction(state)};
}
if (state.progressFinalization.partial) verifyPartialAnswer(state, runId, agentId);
stopExhaustedRun(state, runId);
@@ -11073,7 +11116,10 @@ export function createToolLoopGuard({
state.compactionWindow = undefined;
}
state.operationsPromptRound += 1;
+ const running = !state.progressBudget.exhausted;
state.progressBudget.beginModelRound();
+ // The round fuse stops the run as this call starts: its calls come after the stop.
+ if (running && state.progressBudget.exhausted) state.progressStopRound = state.operationsPromptRound - 1;
if (state.progressBudget.exhausted && !compactionCall) progressFinalization(state).modelCallStarted();
// A further agent turn means the reply seen at finalization was not final.
if (!compactionCall) state.finalReplyText = undefined;
@@ -11381,11 +11427,12 @@ export function createToolLoopGuard({
recordFreeCorrection(state, 'empty-lookup', toolCallId, toolName, FREE_EMPTY_LOOKUPS_PER_RUN)) ||
(nodeReportedFailure(answeredCommand, answerReceipt.result) &&
recordFreeCorrection(state, 'node-result', toolCallId, toolName, FREE_NODE_RESULTS_PER_RUN)));
- if (!answered) state.progressBudget.observeResult({callId: toolCallId, tool: toolName,
+ if (!answered) observeProgress(state, {callId: toolCallId, tool: toolName,
params: event.params, failed: failedToolOutcome(event), pending: running,
discovery:state.workspaceLaneRequested && (EXTENSION_METADATA_TOOLS.has(effectiveProgressTool) ||
effectiveProgressTool === 'pixel_ops_inventory'),
- lane:toolProgressLane(state, effectiveProgressTool,toolName === 'tool_call' ? event.params?.id : undefined)});
+ lane:toolProgressLane(state, effectiveProgressTool,toolName === 'tool_call' ? event.params?.id : undefined)},
+ effectiveProgressTool);
}
if (
toolName === "tool_call" &&
@@ -12853,14 +12900,20 @@ export function createToolLoopGuard({
// Native loop blocks can bypass before/after_tool_call entirely. Count
// their persisted error receipt too; call IDs prevent double accounting.
if (state && message.isError === true) {
- state.progressBudget.observeResult({callId: toolCallId, tool: message.toolName,
- failed: true, lane:progressLane});
+ observeProgress(state, {callId: toolCallId, tool: message.toolName,
+ failed: true, lane:progressLane}, pending?.selectedToolName ?? message.toolName);
}
// The ODS-repaired Pixel runtime projects persisted feedback into the next
// provider request (openclaw-compaction-budget.json). Other SDK agents keep
// storage-only semantics. before_tool_call still enforces the stop itself.
+ // While the single answer turn is still to come, the persisted result is
+ // the answer instruction, as the refusal that carries it: the stop text
+ // says to continue "with a corrected approach", and on the RTX Spark
+ // (2026-10-25) the model then kept calling tools and forfeited the turn.
if (state?.progressBudget.exhausted) {
- return {message: {...message, content: [{type: 'text', text: RUN_PROGRESS_STOP_REASON}]}};
+ const answerTurnAhead = ['pending', 'instructed'].includes(deliverInstruction(state, toolCallId).phase);
+ return {message: {...message, content: [{type: 'text',
+ text: answerTurnAhead ? finalizationInstruction(state) : RUN_PROGRESS_STOP_REASON}]}};
}
if (message.isError === true && state?.progressBudget.laneExhausted(progressLane)) {
return {message:{...message,content:[...(message.content ?? []),{type:'text',text:progressLaneStopReason(progressLane)}]}};
@@ -13771,6 +13824,32 @@ export function createToolLoopGuard({
? previewOutcome(result, previewPresentations.get(from)) : result;
// A preview outcome's text as the owner reads it, where a stop text quotes it.
const ownerOutcomeText = result => ownerPreviewText(result.text, previewPresentations.get(result));
+ // The owner's wording of a tool-limit stop in a website build ({note, rest};
+ // the stop text stays the record, as the model read it). An answer that
+ // ends unfinished (a partial answer, or one that announces more work) gets
+ // the line that its next step has not started. Otherwise the current
+ // publication gets one plain line and its receipt, which becomes the preview
+ // card: the page's own known gap (a script problem, missing requested text),
+ // else that its checks did not finish when failed checks stopped the run,
+ // else that the page may be unfinished. An earlier publication keeps its
+ // link and the line that it is earlier. With none, the stop is said plainly
+ // with what there is, what to do next and where to get help. `facts` are
+ // other owner lines that stay. Undefined for every other run, and for a run
+ // that keeps the strict stop text (a mixed request with a managed
+ // installation, Operations): its record says what was not done.
+ function progressStopPresentation(state, verification, facts = [], {continues = false} = {}) {
+ if (!previewOutcomes.has(verification) || progressFinalization(state).phase === 'unavailable') return undefined;
+ // Only an outcome with a publication has a presentation (its receipt or link).
+ const shown = previewPresentations.get(verification);
+ const continued = note => continues ? PREVIEW_CONTINUE_NOTE : note;
+ if (shown && state.workspacePreview) return {
+ note: continued([PREVIEW_SCRIPT_NOTE, PREVIEW_MISSING_NOTE].includes(shown.note) ? shown.note
+ : state.progressStoppedByPreviewCheck ? PREVIEW_UNFINISHED_NOTE : PREVIEW_INCOMPLETE_NOTE),
+ rest: [...facts, shown.rest].filter(Boolean).join('\n\n')};
+ if (shown) return {note: continued(PREVIEW_STOPPED_NOTE), rest: [...facts, shown.rest].filter(Boolean).join('\n\n')};
+ return {note: continued(PROGRESS_STOPPED_DELIVERY_PREFIX),
+ rest: [verification.text, ...facts, PROGRESS_STOP_HELP].filter(Boolean).join('\n\n')};
+ }
function verificationForRun(runId) {
const verification = mixedTaskVerificationForRun(runId);
@@ -14221,9 +14300,11 @@ export function createToolLoopGuard({
const artifacts=state?.workspaceArtifacts;
// A preview outcome delivered as is (no stop, deadline or question text
// replaced it) reads in the owner's wording, with the agent's final reply
- // ahead of Portal's text unless the owner cancelled.
+ // ahead of Portal's text unless the owner cancelled. A tool-limit stop in a
+ // website build reads in the owner's wording too; its text already starts
+ // with the one answer that stop accepts, if any.
const owner=previewOutcomes.has(result) ? {presentation: previewPresentations.get(result),
- reply: state.clientCancelled ? undefined : state.finalReplyText} : undefined;
+ reply: state.clientCancelled || state.progressBudget.exhausted ? undefined : state.finalReplyText} : undefined;
// Passing tests or creating an archive cannot stand in for its download
// receipt. Keep pending questions, cancellation and existing failure facts.
if (state?.workspaceDocumentDeliveryRequested && state.artifactOwnerInteractive &&
@@ -14303,14 +14384,25 @@ export function createToolLoopGuard({
if (answer) {
const unverified = [...new Set([...state.completionAssurance.unverifiedCitations(answer),
...(modelAnswer ? [] : synthesized.unlisted)])];
- return {status: 'failed', text: composeProgressFinalization(answer, {preview,
+ const text = composeProgressFinalization(answer, {preview,
previewExpected: Boolean(state.workspacePreviewRequired && !state.workspacePreviewForbidden),
verificationStatus: state.latestVerificationStatus, researchLimit: state.researchStopped,
unverifiedLinks: unverified,
refusedToolCalls: state.progressFinalization.partial,
requestedTextMissing: requestedTextDeliveryNote(preview, state.workspaceRequestedTextCheck,
state.workspaceControlNameCheck),
- ...(modelAnswer ? {} : {synthesis: {note: STOP_SYNTHESIS_NOTE, pages: synthesized.pages}})}), ...receipt};
+ ...(modelAnswer ? {} : {synthesis: {note: STOP_SYNTHESIS_NOTE, pages: synthesized.pages}})});
+ // A website build's owner reads the answer, then Portal's line in
+ // place of the stop facts after it; links the answer cites without a
+ // read receipt, and a host synthesis's source, stay said. A partial
+ // answer (its calls were refused) or one that announces more work
+ // ends unfinished.
+ const stop = progressStopPresentation(state, verification, [unverifiedLinksNote(unverified),
+ ...(modelAnswer ? [] : [STOP_SYNTHESIS_NOTE, composeReadPages(synthesized.pages)])],
+ {continues: state.progressFinalization.partial || announcesMoreWork(answer)});
+ const result = {status: 'failed', text, ...receipt};
+ return stop ? previewOutcome(result, {...stop, text: text.slice(progressFinalizationHead(answer).length + 2)})
+ : result;
}
// Without an answer, the fixed stop text is followed by the host's list
// of pages read successfully, when this run could have been finalized
@@ -14320,9 +14412,14 @@ export function createToolLoopGuard({
const pages = readPages ? `\n\n${readPages}` : '';
// Without an answer, a research-loop stop keeps its specific text.
if (state.researchStopped) return {status: 'failed', text: WEB_LOOP_DELIVERY_REASON + pages, ...receipt};
- return {status: 'failed', text: RUN_PROGRESS_STOP_REASON + (preview
+ const text = RUN_PROGRESS_STOP_REASON + (preview
? `\n\n[Open last published preview](${preview.url})\n\nThis is the last verified publication, not proof that all requested work completed.` : '') +
- pages, ...receipt};
+ pages;
+ // A website build's owner reads Portal's line and the preview card, or
+ // what there is and what to do next, in place of this stop text.
+ const stop = progressStopPresentation(state, verification, [readPages]);
+ return stop ? previewOutcome({status: 'failed', text, ...receipt}, {...stop, text})
+ : {status: 'failed', text, ...receipt};
}
// An acknowledged harness abort can end the model without a final token.
// Preserve existing artifact/evidence delivery; for an otherwise empty
diff --git a/ods/extensions/services/pixel-agent/tests/output_limit_delivery.test.mjs b/ods/extensions/services/pixel-agent/tests/output_limit_delivery.test.mjs
index e60c72729..04aaa7187 100644
--- a/ods/extensions/services/pixel-agent/tests/output_limit_delivery.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/output_limit_delivery.test.mjs
@@ -9,9 +9,9 @@ import http from 'node:http';
import {createHash} from 'node:crypto';
import {readFileSync} from 'node:fs';
import {createIngressServer, parseVerificationResponse} from '../host/pixel_ingress.mjs';
-import {createToolLoopGuard} from '../plugin/tool-loop-guard.mjs';
+import {createToolLoopGuard, PROGRESS_STOPPED_DELIVERY_PREFIX} from '../plugin/tool-loop-guard.mjs';
import {outputLimitCut} from '../plugin/output-limit.mjs';
-import {RUN_PROGRESS_LIMITS, RUN_PROGRESS_STOP_REASON} from '../plugin/run-progress-budget.mjs';
+import {RUN_PROGRESS_LIMITS} from '../plugin/run-progress-budget.mjs';
const RUN_ID = 'chatcmpl_8b0f4f8e-7f6d-4c1a-9f3e-6d2a1c5b7e90';
const NEXT_RUN_ID = 'chatcmpl_0c6e2d3b-1a4f-4e8d-b2c7-5f9a8e7d6c41';
@@ -223,7 +223,8 @@ test('a budget stop keeps its own text', () => {
}
f.end([CUT_WRITE]);
const verification = f.guard.deliveryVerificationForRun(RUN_ID);
- assert.match(verification.text, new RegExp('^' + RUN_PROGRESS_STOP_REASON.slice(0, 40)));
+ // A website build: the stop in the owner's wording, never the output-limit copy.
+ assert.ok(verification.text.startsWith(`${PROGRESS_STOPPED_DELIVERY_PREFIX}\n\n`), verification.text);
assert.doesNotMatch(verification.text, /output limit/);
});
diff --git a/ods/extensions/services/pixel-agent/tests/playground_guidance.test.mjs b/ods/extensions/services/pixel-agent/tests/playground_guidance.test.mjs
index 89e3cdc29..37d505e53 100644
--- a/ods/extensions/services/pixel-agent/tests/playground_guidance.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/playground_guidance.test.mjs
@@ -124,8 +124,12 @@ test('mac-mini d4a61f33 replay: refusals name the exact next path and the unchan
// created, so the listing fails: the fourth consecutive failure.
const listing = h.exec(list.args, 'Playground/photo-renamer-test', list.id);
assert.notEqual(listing.decision?.block, true, listing.decision?.blockReason);
- assert.equal(listing.text, RUN_PROGRESS_STOP_REASON, 'charged exactly as recorded: the fuse trips at call 4');
- assert.ok(listing.text.startsWith(list.recorded.resultHead));
+ // The fuse trips at call 4, as recorded. The model read the stop text there
+ // (the recorded result head), and the refusal of call 5 was recorded the same
+ // way, so it never read the answer instruction; both now carry it.
+ assert.ok(RUN_PROGRESS_STOP_REASON.startsWith(list.recorded.resultHead));
+ assert.ok(RUN_PROGRESS_STOP_REASON.startsWith(listLong.recorded.resultHead));
+ assert.equal(listing.text, PROGRESS_FINALIZATION_INSTRUCTION, 'charged exactly as recorded: the fuse trips at call 4');
const next = h.exec(listLong.args, 'Playground/photo-renamer-test', listLong.id);
assert.equal(next.decision?.block, true);
assert.equal(stopped(next.decision.blockReason), true);
diff --git a/ods/extensions/services/pixel-agent/tests/preview_check_stop_delivery.test.mjs b/ods/extensions/services/pixel-agent/tests/preview_check_stop_delivery.test.mjs
new file mode 100644
index 000000000..bee286b24
--- /dev/null
+++ b/ods/extensions/services/pixel-agent/tests/preview_check_stop_delivery.test.mjs
@@ -0,0 +1,426 @@
+// RTX Spark, 2026-10-25, "Make me a simple stopwatch web page with start, stop
+// and lap buttons" (seen twice): the model wrote the page and published it, and
+// the preview card worked. Its next three preview checks failed on its own plan
+// mistakes ("Step 4 matched the element but did not observe its requested
+// visibility", "Step 7 (assert-text) matched 2 elements", then a generic
+// failure), which used up the tool budget. Every later call was refused, and
+// the owner read under the working card: "This response was stopped after
+// repeated tool failures or attempts without progress. ... The full request was
+// not completed ... This is the last verified publication, not proof that all
+// requested work completed."
+//
+// The model never saw the instruction to answer: on ODS's runtime the result
+// persisted for a call is what the next model request carries, and every result
+// after the stop, the refusal that carried the instruction included, was
+// persisted as the stop text, which says to continue "with a corrected
+// approach". Now those results carry the instruction, which tells the model to
+// stop checking a published page and say what it built and could not verify.
+// The owner reads that answer, if any, one plain line and the preview card.
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {createHash} from 'node:crypto';
+import {createToolLoopGuard, PROGRESS_STOP_HELP, PROGRESS_STOPPED_DELIVERY_PREFIX,
+ WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX} from '../plugin/tool-loop-guard.mjs';
+import {PREVIEW_INSPECTION_TOOL} from '../plugin/preview-interaction-assurance.mjs';
+import {INSPECTION_KIND, INSPECTION_SCOPE, createWorkspacePreviewInspectTool, inspectionPlanHash} from '../plugin/workspace-preview-inspect.mjs';
+import {PREVIEW_CONTINUE_NOTE, PREVIEW_INCOMPLETE_NOTE, PREVIEW_STOPPED_NOTE,
+ PREVIEW_UNFINISHED_NOTE} from '../plugin/preview-explanation.mjs';
+import {PREVIEW_CHECK_FINALIZATION_INSTRUCTION, PROGRESS_FINALIZATION_INSTRUCTION,
+ PROGRESS_FINALIZATION_NOTE} from '../plugin/progress-finalization.mjs';
+import {RUN_PROGRESS_LIMITS, RUN_PROGRESS_STOP_REASON} from '../plugin/run-progress-budget.mjs';
+
+const USER = 'ods-' + '5f0'.repeat(21) + 'a';
+const runId = 'chatcmpl_5f0a7c11-2d3e-4f50-8a61-7b8c9d0e1f2a';
+const context = {agentId: 'pixel', runId, sessionId: 'stopwatch-session', sessionKey: `agent:pixel:openai-user:${USER}`};
+const PROMPT = 'Make me a simple stopwatch web page with start, stop and lap buttons';
+const PAGE = '<!doctype html><title>Stopwatch</title><div id="display">00:00.0</div>' +
+ '<button id="start">Start</button><button id="stop" disabled>Stop</button><button id="lap" disabled>Lap</button>' +
+ '<ol id="laps"></ol><script src="app.js"></script>';
+const ANSWER = 'Your stopwatch page is ready: it shows the running time with Start, Stop and Lap buttons, and Lap adds ' +
+ 'the current time to a numbered list. I could not verify automatically that Stop and Lap respond, because my own ' +
+ 'checks of those buttons kept failing, so please try them.';
+// What an owner must not read after a build that published a working preview.
+const ALARM = /stopped after|tool failures|without progress|not completed|not proof|tool limit|verified publication|corrected approach/i;
+
+const shown = {count: 1, visible: true, display: 'block', visibility: 'visible', opacity: '1', hidden: false,
+ hiddenUntilFound: false, rectCount: 1};
+// A capsule receipt whose steps passed up to `failAt`, where `failure` failed.
+function failedReceipt(request, failAt, failure) {
+ const steps = request.steps.slice(0, failAt + 1).map((step, index) => {
+ const base = {index, action: step.action, locator: step.locator, stable: true,
+ ...(step.action === 'assert-text' ? {expectedText: step.expectedText} : {})};
+ if (index === failAt) return {...base, ...failure, status: 'failed'};
+ return {...base, status: 'passed', ...(step.action === 'click' ? {after: shown} : {}),
+ before: step.action === 'assert-text' ? {...shown, text: {actual: step.expectedText, truncated: false}} : shown};
+ });
+ return {schemaVersion: 1, kind: INSPECTION_KIND, status: 'failed', siteId: request.siteId, sha256: request.sha256,
+ planSha256: inspectionPlanHash(request), viewport: request.viewport, steps,
+ diagnostics: {renderedHiddenAttributeCount: 0, hiddenUntilFoundCount: 0}, blockedRequests: [], scope: INSPECTION_SCOPE};
+}
+const button = name => ({role: 'button', name, exact: true});
+// The three checks of the Spark run, each failing on the model's own plan.
+const CHECKS = [
+ {steps: [{action: 'assert-visible', locator: {selector: '#display'}}, {action: 'click', locator: button('Start')},
+ {action: 'click', locator: button('Stop')}, {action: 'assert-hidden', locator: button('Stop')}],
+ failAt: 3, failure: {before: shown, errorCode: 'visibility_mismatch'},
+ says: /^Preview inspection failed\. Step 4 matched the element but did not observe its requested visibility\./},
+ {steps: [{action: 'assert-visible', locator: {selector: '#display'}}, {action: 'click', locator: button('Start')},
+ {action: 'click', locator: button('Lap')}, {action: 'click', locator: button('Lap')}, {action: 'click', locator: button('Stop')},
+ {action: 'assert-visible', locator: {selector: '#laps'}}, {action: 'assert-text', locator: {selector: '#laps li'}, expectedText: 'Lap 1'}],
+ failAt: 6, failure: {before: {count: 2}, errorCode: 'selector_not_unique'},
+ says: /Step 7 \(assert-text\) matched 2 elements; a locator must match exactly one/},
+ {steps: [{action: 'click', locator: button('Start')}, {action: 'assert-text', locator: {selector: '#display'}, expectedText: '00:00.1'}],
+ failAt: 0, failure: {before: shown, errorCode: 'click_failed'},
+ says: /^Preview inspection failed\. Requested behavior remains unverified; a failed inspection does not establish/},
+];
+
+// One stopwatch turn through the real guard and inspection tool: write and
+// publish the page, then a failed read and the three failed checks, so that the
+// third check is the one that uses up the budget, as on the Spark. `persist`
+// replays each result as the runtime persists it and returns the text the next
+// model request carries.
+async function stopwatchTurn({published = true, edited = false, checks = published && !edited} = {}) {
+ const aborts = [];
+ const guard = createToolLoopGuard({workspacePreviewInspectionAvailable: true,
+ abortRun: (sessionId) => { aborts.push(sessionId); return true; }});
+ guard.observeRun({...context, trigger: 'user'}, 'pixel', {prompt: PROMPT});
+ let sequence = 0;
+ const persisted = [];
+ const persist = (toolName, toolCallId, result) => {
+ const message = {role: 'toolResult', toolName, toolCallId, isError: result?.isError === true, content: result?.content ?? []};
+ const decision = guard.toolResultPersist({toolCallId, message}, {...context, toolName, toolCallId});
+ persisted.push((decision?.message ?? message).content.map(block => block.text).join('\n'));
+ return persisted.at(-1);
+ };
+ const round = () => { guard.observeModelEnd({}, context); guard.observeModelCall({}, context); };
+ const call = (toolName, params) => {
+ const ctx = {...context, toolName, toolCallId: `call-${sequence++}`};
+ const decision = guard.beforeToolCall({toolName, runId, toolCallId: ctx.toolCallId, params}, ctx);
+ return {ctx, decision, params: decision?.params ?? params};
+ };
+ const run = (toolName, params, result) => {
+ const {ctx, decision, params: actual} = call(toolName, params);
+ assert.notEqual(decision?.block, true, decision?.blockReason);
+ guard.afterToolCall({toolName, runId, toolCallId: ctx.toolCallId, params: actual, result,
+ ...(result.isError ? {error: result.content?.[0]?.text ?? 'failed'} : {})}, ctx);
+ persist(toolName, ctx.toolCallId, result);
+ return actual;
+ };
+ guard.observeModelCall({}, context);
+ const written = run('write', {path: 'stopwatch/index.html', content: PAGE}, {content: [{type: 'text', text: 'Successfully wrote file.'}]});
+ const relativeDirectory = written.path.slice(0, -'/index.html'.length);
+ let preview;
+ if (published) {
+ round();
+ const sha256 = createHash('sha256').update(relativeDirectory + PAGE).digest('hex'), siteId = `site-${sha256.slice(0, 24)}`;
+ preview = {schemaVersion: 1, kind: 'ods-pixel-workspace-preview', status: 'succeeded', relativeDirectory, siteId, sha256,
+ entryFile: 'index.html', entrySha256: createHash('sha256').update(PAGE).digest('hex'), files: 2, bytes: 2048, port: 9437,
+ url: `http://${siteId}.localhost:9437/${siteId}/`, httpStatus: 200, readbackVerified: true, executable: false, overwritten: false};
+ run('pixel_ods_workspace_preview', {relativeDirectory}, {details: preview});
+ }
+ if (edited) {
+ round();
+ run('edit', {path: 'stopwatch/index.html', edits: [{oldText: '00:00.0', newText: '00:00.00'}]},
+ {content: [{type: 'text', text: 'Successfully replaced text.'}]});
+ }
+ round();
+ run('read', {path: 'stopwatch/style.css'}, {isError: true, content: [{type: 'text', text: 'ENOENT: no such file or directory'}]});
+ const inspections = [];
+ for (const check of checks ? CHECKS : []) {
+ round();
+ const params = {siteId: preview.siteId, sha256: preview.sha256, viewport: {width: 1280, height: 800}, steps: check.steps};
+ const tool = createWorkspacePreviewInspectTool({request: async request => failedReceipt(request, check.failAt, check.failure)});
+ const {ctx, decision, params: prepared} = call(PREVIEW_INSPECTION_TOOL, params);
+ assert.notEqual(decision?.block, true, decision?.blockReason);
+ const result = await tool.execute(ctx.toolCallId, prepared);
+ assert.equal(result.isError, true);
+ assert.match(result.content[0].text, check.says);
+ guard.afterToolCall({toolName: PREVIEW_INSPECTION_TOOL, runId, toolCallId: ctx.toolCallId, params: prepared, result,
+ error: result.content[0].text}, ctx);
+ inspections.push({result, persisted: persist(PREVIEW_INSPECTION_TOOL, ctx.toolCallId, result)});
+ }
+ return {guard, preview, inspections, persisted, aborts, round, call, persist};
+}
+
+const receiptOf = guard => {
+ const recorded = guard.verificationForRun(runId).text;
+ return recorded.slice(recorded.indexOf('Your preview is ready.'));
+};
+
+test('Spark stopwatch: the check that stops the run tells the model to stop checking and wrap up', async () => {
+ const {guard, inspections, persisted, call, persist, round, aborts} = await stopwatchTurn();
+ // The first two checks reach the model unchanged; they did not stop the run.
+ assert.deepEqual(inspections.slice(0, 2).map(item => item.persisted), inspections.slice(0, 2).map(item => item.result.content[0].text));
+ // The third one stopped it: its persisted result, which the next model request
+ // carries, is the wrap-up instruction instead of the stop text.
+ assert.equal(inspections[2].persisted, PREVIEW_CHECK_FINALIZATION_INSTRUCTION);
+ assert.ok(!persisted.includes(RUN_PROGRESS_STOP_REASON), 'the model never reads "continue with a corrected approach"');
+ assert.match(PREVIEW_CHECK_FINALIZATION_INSTRUCTION, /^\[ODS Pixel tool limit\] Stop checking the preview now: tools are disabled/);
+ assert.match(PREVIEW_CHECK_FINALIZATION_INSTRUCTION, /say plainly which requested behavior you could not verify/);
+ // The Spark model's next call: refused with the same instruction, persisted as it.
+ round();
+ const listing = call('exec', {command: 'ls -la stopwatch && head -5 stopwatch/index.html'});
+ assert.deepEqual(listing.decision, {block: true, blockReason: PREVIEW_CHECK_FINALIZATION_INSTRUCTION});
+ assert.equal(persist('exec', listing.ctx.toolCallId, {isError: true, content: [{type: 'text', text: listing.decision.blockReason}]}),
+ PREVIEW_CHECK_FINALIZATION_INSTRUCTION);
+ // A tool call in the answer turn still ends the run at that boundary.
+ round();
+ const again = call('read', {path: 'stopwatch/app.js'});
+ assert.deepEqual(again.decision, {block: true, blockReason: RUN_PROGRESS_STOP_REASON});
+ assert.equal(persist('read', again.ctx.toolCallId, {isError: true, content: [{type: 'text', text: RUN_PROGRESS_STOP_REASON}]}),
+ RUN_PROGRESS_STOP_REASON, 'once the answer turn is spent, results carry the stop text');
+ assert.equal(aborts.length, 1);
+});
+
+test('Spark stopwatch: without an answer the owner reads one plain line and the preview card', async () => {
+ const {guard, preview, round, call} = await stopwatchTurn();
+ round();
+ call('exec', {command: 'ls -la stopwatch'});
+ round();
+ call('read', {path: 'stopwatch/app.js'});
+ guard.beforeAgentFinalize({lastAssistantMessage: 'Let me check the files again.'}, context);
+ const delivery = guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.status, 'failed', 'Portal certifies nothing');
+ assert.equal(delivery.text, `${PREVIEW_UNFINISHED_NOTE}\n\n${receiptOf(guard)}`);
+ assert.ok(delivery.text.includes(`\n\nYour preview is ready.\n\n[Open preview](${preview.url})\n\n`), 'the receipt becomes the card');
+ assert.doesNotMatch(delivery.text, ALARM);
+ assert.equal(delivery.preview.siteId, preview.siteId, 'the preview card stays');
+ // The record keeps every check fact, as the model read them.
+ assert.match(guard.verificationForRun(runId).text, /^The attempted preview interaction checks have not passed browser inspection\./);
+ assert.equal(guard.replyPayloadSending({runId, kind: 'final', payload: {text: 'x'}}).payload.text, delivery.text);
+});
+
+test('Spark stopwatch: the model\'s own wrap-up comes first, then Portal\'s line and the card', async () => {
+ const {guard, preview, round} = await stopwatchTurn();
+ round();
+ guard.beforeAgentFinalize({lastAssistantMessage: ANSWER, messages: [{role: 'user', content: PROMPT},
+ {role: 'assistant', content: [{type: 'text', text: ANSWER}], stopReason: 'stop'}]}, context);
+ const delivery = guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.status, 'failed');
+ assert.equal(delivery.text, `${ANSWER}\n\n${PREVIEW_UNFINISHED_NOTE}\n\n${receiptOf(guard)}`);
+ assert.doesNotMatch(delivery.text.slice(ANSWER.length), ALARM);
+ assert.ok(!delivery.text.includes(PROGRESS_FINALIZATION_NOTE));
+ assert.equal(delivery.preview.sha256, preview.sha256);
+});
+
+test('a stopped build whose files changed since publication links the earlier preview with its plain line', async () => {
+ const {guard, preview, round, call} = await stopwatchTurn({edited: true});
+ // Without a current publication, failed reads alone stop it: the generic instruction applies.
+ for (let i = 0; i < RUN_PROGRESS_LIMITS.consecutiveFailures - 1; i++) {
+ round();
+ const {ctx} = call('read', {path: `stopwatch/missing-${i}.js`});
+ guard.afterToolCall({toolName: 'read', runId, toolCallId: ctx.toolCallId, params: {path: `stopwatch/missing-${i}.js`},
+ result: {isError: true, content: [{type: 'text', text: 'ENOENT'}]}, error: 'ENOENT'}, ctx);
+ }
+ round();
+ assert.equal(call('exec', {command: 'ls'}).decision.blockReason, PROGRESS_FINALIZATION_INSTRUCTION);
+ round();
+ call('read', {path: 'stopwatch/app.js'});
+ const delivery = guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.text, `${PREVIEW_STOPPED_NOTE}\n\n[Open last published preview](${preview.url})`);
+ assert.doesNotMatch(delivery.text, ALARM);
+ assert.equal(delivery.preview.sha256, preview.sha256);
+});
+
+test('a stopped build with no preview says so plainly, with what there is, the next step and where to get help', async () => {
+ const {guard, round, call} = await stopwatchTurn({published: false});
+ for (let i = 0; i < RUN_PROGRESS_LIMITS.consecutiveFailures - 1; i++) {
+ round();
+ const {ctx} = call('exec', {command: `npx serve stopwatch --port ${3000 + i}`});
+ guard.afterToolCall({toolName: 'exec', runId, toolCallId: ctx.toolCallId, params: {command: 'npx serve'},
+ result: {isError: true, details: {status: 'completed', exitCode: 127}, content: [{type: 'text', text: 'npx: not found'}]},
+ error: 'npx: not found'}, ctx);
+ }
+ round();
+ call('exec', {command: 'ls'});
+ round();
+ call('read', {path: 'stopwatch/app.js'});
+ const delivery = guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.status, 'failed');
+ assert.equal(delivery.preview, undefined);
+ assert.equal(delivery.text, `${PROGRESS_STOPPED_DELIVERY_PREFIX}\n\n${WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX}\n\n${PROGRESS_STOP_HELP}`);
+ assert.doesNotMatch(delivery.text, /localhost|tool failures|corrected approach/);
+});
+
+test('the wrap-up never lets another tool run, and the budget is unchanged', async () => {
+ assert.deepEqual(RUN_PROGRESS_LIMITS, {consecutiveFailures: 4, totalFailures: 12, roundsWithoutProgress: 8, identicalSuccesses: 2});
+ const {round, call} = await stopwatchTurn();
+ const decisions = [];
+ for (const [toolName, params] of [['exec', {command: 'ls'}], ['pixel_ods_workspace_preview_inspect', {siteId: 'x'}],
+ ['write', {path: 'stopwatch/app.js', content: 'x'}], ['read', {path: 'stopwatch/app.js'}]]) {
+ round();
+ decisions.push(call(toolName, params).decision);
+ }
+ assert.ok(decisions.every(decision => decision?.block === true), 'every call after the stop is refused');
+ assert.deepEqual(decisions.map(decision => decision.blockReason), [PREVIEW_CHECK_FINALIZATION_INSTRUCTION,
+ RUN_PROGRESS_STOP_REASON, RUN_PROGRESS_STOP_REASON, RUN_PROGRESS_STOP_REASON]);
+});
+
+// Review of #8198: four stops that the wording above must not misread. The page
+// has only a Start button; the edits that would add Stop and Lap keep failing.
+const START_ONLY = '<!doctype html><title>Stopwatch</title><div id="display">00:00.0</div>' +
+ '<button id="start">Start</button><ol id="laps"></ol><script src="app.js"></script>';
+const MIXED_PROMPT = '/extensions install https://github.com/example/project; also build a small status web page and publish a preview of it.';
+function harness(prompt = PROMPT) {
+ const aborts = [];
+ const guard = createToolLoopGuard({workspacePreviewInspectionAvailable: true,
+ abortRun: (sessionId) => { aborts.push(sessionId); return true; }});
+ guard.observeRun({...context, trigger: 'user'}, 'pixel', {prompt}, {executionHost: 'sandbox'});
+ let sequence = 0;
+ const persist = (toolName, toolCallId, result, ctx = {...context, toolName, toolCallId}) => {
+ const message = {role: 'toolResult', toolName, toolCallId, isError: result?.isError === true, content: result?.content ?? []};
+ const decision = guard.toolResultPersist({toolCallId, message}, ctx);
+ return (decision?.message ?? message).content.map(block => block.text).join('\n');
+ };
+ const round = () => { guard.observeModelEnd({}, context); guard.observeModelCall({}, context); };
+ const call = (toolName, params) => {
+ const ctx = {...context, toolName, toolCallId: `call-${sequence++}`};
+ const decision = guard.beforeToolCall({toolName, runId, toolCallId: ctx.toolCallId, params}, ctx);
+ return {ctx, decision, params: decision?.params ?? params};
+ };
+ // A call as the runtime runs it: refused (its refusal persisted) or run, then persisted.
+ const run = (toolName, params, result) => {
+ const {ctx, decision, params: actual} = call(toolName, params);
+ if (decision?.block) return {blocked: decision.blockReason,
+ persisted: persist(toolName, ctx.toolCallId, {isError: true, content: [{type: 'text', text: decision.blockReason}]})};
+ guard.afterToolCall({toolName, runId, toolCallId: ctx.toolCallId, params: actual, result,
+ ...(result.isError ? {error: result.content?.[0]?.text ?? 'failed'} : {})}, ctx);
+ return {params: actual, persisted: persist(toolName, ctx.toolCallId, result)};
+ };
+ const publish = (page = START_ONLY) => {
+ const written = run('write', {path: 'stopwatch/index.html', content: page}, {content: [{type: 'text', text: 'Successfully wrote file.'}]});
+ const relativeDirectory = written.params.path.slice(0, -'/index.html'.length);
+ round();
+ const sha256 = createHash('sha256').update(relativeDirectory + page).digest('hex'), siteId = `site-${sha256.slice(0, 24)}`;
+ const preview = {schemaVersion: 1, kind: 'ods-pixel-workspace-preview', status: 'succeeded', relativeDirectory, siteId, sha256,
+ entryFile: 'index.html', entrySha256: createHash('sha256').update(page).digest('hex'), files: 2, bytes: 2048, port: 9437,
+ url: `http://${siteId}.localhost:9437/${siteId}/`, httpStatus: 200, readbackVerified: true, executable: false, overwritten: false};
+ run('pixel_ods_workspace_preview', {relativeDirectory}, {details: preview});
+ return preview;
+ };
+ // Edits that try to add the missing buttons and fail: the fourth stops the run.
+ const failedEdits = () => {
+ let last;
+ for (let i = 0; i < RUN_PROGRESS_LIMITS.consecutiveFailures; i++) {
+ round();
+ last = run('edit', {path: 'stopwatch/index.html', edits: [{oldText: `<button id="lap-${i}">`, newText: '<button id="lap">Lap</button>'}]},
+ {isError: true, content: [{type: 'text', text: 'Could not find the exact text in stopwatch/index.html'}]});
+ }
+ return last;
+ };
+ return {guard, aborts, persist, round, call, run, publish, failedEdits};
+}
+const answerTurn = text => ({lastAssistantMessage: text, messages: [{role: 'user', content: PROMPT},
+ {role: 'assistant', content: [{type: 'text', text}], stopReason: 'stop'}]});
+
+test('a mixed request with a managed installation keeps the strict stop text, so the unverified install is not hidden', () => {
+ const h = harness(MIXED_PROMPT);
+ h.guard.observeModelCall({}, context);
+ for (let i = 0; i < RUN_PROGRESS_LIMITS.consecutiveFailures; i++) {
+ h.round();
+ assert.equal(h.run('pixel_ods_extension_request_prepare', {}, {isError: true,
+ content: [{type: 'text', text: 'Repository evidence unavailable'}]}).blocked, undefined);
+ }
+ h.round();
+ const preview = h.publish();
+ for (let i = 0; i < RUN_PROGRESS_LIMITS.consecutiveFailures; i++) {
+ h.round();
+ h.run('read', {path: `stopwatch/missing-${i}.js`}, {isError: true, content: [{type: 'text', text: 'ENOENT'}]});
+ }
+ h.round();
+ // Receipt-based work keeps the strict stop: no answer turn, no instruction.
+ const refused = h.run('read', {path: 'stopwatch/app.js'}, {});
+ assert.equal(refused.blocked, RUN_PROGRESS_STOP_REASON);
+ assert.equal(refused.persisted, RUN_PROGRESS_STOP_REASON);
+ h.guard.beforeAgentFinalize(answerTurn('The status page is published.'), context);
+ assert.match(h.guard.verificationForRun(runId).text, /ODS did not observe a verified managed installation receipt/);
+ const delivery = h.guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.status, 'failed');
+ assert.equal(delivery.text, `${RUN_PROGRESS_STOP_REASON}\n\n[Open last published preview](${preview.url})\n\n` +
+ 'This is the last verified publication, not proof that all requested work completed.',
+ 'the owner reads that the request was not completed, not only a calm line over the card');
+ assert.equal(delivery.preview.sha256, preview.sha256);
+});
+
+test('a stop after failed edits says the published page may be unfinished, not that its checks did not finish', () => {
+ const h = harness();
+ h.guard.observeModelCall({}, context);
+ const preview = h.publish();
+ // Edits stopped the run, not a preview check: the general instruction.
+ assert.equal(h.failedEdits().persisted, PROGRESS_FINALIZATION_INSTRUCTION);
+ h.round();
+ assert.equal(h.call('read', {path: 'stopwatch/app.js'}).decision.blockReason, PROGRESS_FINALIZATION_INSTRUCTION);
+ h.round();
+ h.call('read', {path: 'stopwatch/app.js'});
+ h.guard.beforeAgentFinalize({lastAssistantMessage: 'Let me check.'}, context);
+ assert.equal(h.guard.verificationForRun(runId).status, 'passed', 'the record: a publication without failed checks');
+ const delivery = h.guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.text, `${PREVIEW_INCOMPLETE_NOTE}\n\n${receiptOf(h.guard)}`);
+ assert.doesNotMatch(delivery.text, /couldn't finish checking/);
+ assert.match(PREVIEW_INCOMPLETE_NOTE, /^Portal stopped before it finished\b.*\. Send a message to continue\.$/);
+ assert.equal(delivery.preview.sha256, preview.sha256);
+});
+
+test('a call the runtime rejects after the stop hands over the instruction, and the answer that follows is kept', () => {
+ const answer = 'I built the stopwatch page in stopwatch/index.html with a running display and a Start button. ' +
+ 'I could not add the Stop and Lap buttons: my edits to add them did not apply, so those are still missing.';
+ const reject = h => h.persist('edit', 'native-1', {isError: true,
+ content: [{type: 'text', text: 'Validation failed for tool "edit": edits must be an array'}]},
+ {agentId: 'pixel', sessionKey: context.sessionKey, toolName: 'edit', toolCallId: 'native-1'});
+ const h = harness();
+ h.guard.observeModelCall({}, context);
+ h.publish();
+ h.failedEdits();
+ // The next model call reads the instruction, but the runtime rejects its call
+ // before before_tool_call: that persisted result hands over the instruction.
+ h.round();
+ assert.equal(reject(h), PROGRESS_FINALIZATION_INSTRUCTION);
+ // The following model call is the single answer turn, so its answer is kept.
+ h.round();
+ h.guard.beforeAgentFinalize(answerTurn(answer), context);
+ const delivery = h.guard.deliveryVerificationForRun(runId);
+ assert.equal(delivery.text, `${answer}\n\n${PREVIEW_INCOMPLETE_NOTE}\n\n${receiptOf(h.guard)}`);
+ assert.deepEqual(h.aborts, []);
+
+ // The bound is unchanged: a tool call in that answer turn ends the run.
+ const bounded = harness();
+ bounded.guard.observeModelCall({}, context);
+ bounded.publish();
+ bounded.failedEdits();
+ bounded.round();
+ reject(bounded);
+ bounded.round();
+ assert.equal(bounded.call('read', {path: 'stopwatch/app.js'}).decision.blockReason, RUN_PROGRESS_STOP_REASON);
+ assert.equal(bounded.aborts.length, 1);
+ assert.equal(bounded.guard.deliveryVerificationForRun(runId).text, `${PREVIEW_INCOMPLETE_NOTE}\n\n${receiptOf(bounded.guard)}`);
+});
+
+test('an answer that ends unfinished is followed by the line that its next step has not started', () => {
+ const text = 'I built the stopwatch page in stopwatch/index.html. It shows the elapsed time and has a Start button that ' +
+ 'starts the timer. The Stop and Lap buttons are not on the page yet because my edits to add them did not apply. ' +
+ 'Now let me add the Stop and Lap buttons to the page.';
+ // A partial answer: the answer turn's message carried text and a tool call.
+ const partial = harness();
+ partial.guard.observeModelCall({}, context);
+ partial.publish();
+ partial.failedEdits();
+ partial.round();
+ assert.equal(partial.call('read', {path: 'stopwatch/app.js'}).decision.blockReason, PROGRESS_FINALIZATION_INSTRUCTION);
+ partial.round();
+ const id = 'partial-edit';
+ partial.guard.observeAssistantMessage({message: {role: 'assistant', content: [{type: 'text', text},
+ {type: 'toolCall', id, name: 'edit'}]}}, context);
+ assert.equal(partial.guard.beforeToolCall({toolName: 'edit', runId, toolCallId: id, params: {path: 'stopwatch/index.html'}},
+ {...context, toolName: 'edit', toolCallId: id}).blockReason, RUN_PROGRESS_STOP_REASON);
+ const refused = partial.guard.deliveryVerificationForRun(runId);
+ assert.equal(refused.text, `${text}\n\n${PREVIEW_CONTINUE_NOTE}\n\n${receiptOf(partial.guard)}`);
+ // A tool-free answer that announces more work reads the same way.
+ const announced = harness();
+ announced.guard.observeModelCall({}, context);
+ announced.publish();
+ announced.failedEdits();
+ announced.round();
+ announced.guard.beforeAgentFinalize(answerTurn(text), context);
+ assert.equal(announced.guard.deliveryVerificationForRun(runId).text,
+ `${text}\n\n${PREVIEW_CONTINUE_NOTE}\n\n${receiptOf(announced.guard)}`);
+});
diff --git a/ods/extensions/services/pixel-agent/tests/preview_explanation_delivery.test.mjs b/ods/extensions/services/pixel-agent/tests/preview_explanation_delivery.test.mjs
index 4abe700c8..1290fbc55 100644
--- a/ods/extensions/services/pixel-agent/tests/preview_explanation_delivery.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/preview_explanation_delivery.test.mjs
@@ -17,7 +17,7 @@ import assert from 'node:assert/strict';
import * as fs from 'node:fs';
import {createHash} from 'node:crypto';
import {createServer} from 'node:http';
-import {createToolLoopGuard, WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX,
+import {createToolLoopGuard, PROGRESS_STOP_HELP, PROGRESS_STOPPED_DELIVERY_PREFIX, WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX,
WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX} from '../plugin/tool-loop-guard.mjs';
import {createIngressServer} from '../host/pixel_ingress.mjs';
import {PREVIEW_INSPECTION_TOOL} from '../plugin/preview-interaction-assurance.mjs';
@@ -447,7 +447,8 @@ test('Portal picks one line from the check facts: a broken page, a missing reque
});
test('Portal\'s lines are short, calm, fixed English, and the dashboard mutes exactly these', () => {
- const lines = [...PREVIEW_NOTES, WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX, WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX];
+ const lines = [...PREVIEW_NOTES, WORKSPACE_PREVIEW_UNVERIFIED_DELIVERY_PREFIX, WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX,
+ PROGRESS_STOPPED_DELIVERY_PREFIX];
assert.equal(new Set(lines).size, lines.length);
for (const line of lines) {
assert.match(line, /^[\x20-\x7e]+$/, line);
@@ -456,6 +457,7 @@ test('Portal\'s lines are short, calm, fixed English, and the dashboard mutes ex
}
for (const line of PREVIEW_NOTES) assert.doesNotMatch(line, ALARM, line);
assert.deepEqual([...DELIVERY_NOTES].sort(), [...lines].sort());
+ assert.ok(!DELIVERY_NOTES.includes(PROGRESS_STOP_HELP), 'the help link after a stop is a paragraph of its own, not muted');
});
test('the folded text sees the label however markdown or HTML draws it; fences follow CommonMark', () => {
diff --git a/ods/extensions/services/pixel-agent/tests/progress_finalization.test.mjs b/ods/extensions/services/pixel-agent/tests/progress_finalization.test.mjs
index c608e28dd..bc4253170 100644
--- a/ods/extensions/services/pixel-agent/tests/progress_finalization.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/progress_finalization.test.mjs
@@ -2,7 +2,9 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import {createToolLoopGuard, DEFAULT_WEB_TOOL_LIMITS, FREE_CORRECTIONS_PER_KIND, PHANTOM_PROCESS_REASON,
- WEB_LOOP_ABORT_REASON, WEB_LOOP_DELIVERY_REASON, WEB_SEARCH_BUDGET_EXHAUSTED_REASON} from '../plugin/tool-loop-guard.mjs';
+ PROGRESS_STOP_HELP, PROGRESS_STOPPED_DELIVERY_PREFIX, WEB_LOOP_ABORT_REASON, WEB_LOOP_DELIVERY_REASON,
+ WEB_SEARCH_BUDGET_EXHAUSTED_REASON, WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX} from '../plugin/tool-loop-guard.mjs';
+import {PREVIEW_INCOMPLETE_NOTE} from '../plugin/preview-explanation.mjs';
import {RUN_PROGRESS_LIMITS, RUN_PROGRESS_STOP_REASON} from '../plugin/run-progress-budget.mjs';
import {composeProgressFinalization, createProgressFinalization, progressFinalizationAnswer,
PROGRESS_FINALIZATION_INSTRUCTION, PROGRESS_FINALIZATION_NOTE, PROGRESS_READ_PAGES_HEADING} from '../plugin/progress-finalization.mjs';
@@ -66,9 +68,11 @@ function callTool(guard, toolName = 'web_search', params = {query: 'RTX 5070 vs
return guard.beforeToolCall({toolName, toolCallId: id, params}, {...context, toolName, toolCallId: id});
}
-// The model call after the exhausting result still sees that original result
-// (the persisted rewrite is transcript-only). Its next tool call is refused
-// with the instruction, and the following call is the single answer turn.
+// The model call after the exhausting result reads that result as persisted:
+// on ODS's runtime the persisted copy is what the next model request carries
+// (host/openclaw-compaction-budget.json), and it holds the instruction. A tool
+// call from that model call is refused with the instruction too, and the
+// following call is the single answer turn.
function enterAnswerTurn(guard) {
guard.observeModelCall({}, context);
assert.deepEqual(callTool(guard), {block: true, blockReason: PROGRESS_FINALIZATION_INSTRUCTION});
@@ -149,7 +153,8 @@ test('composition keeps the requested format first and closes an unterminated fe
test('research stop (tower3 replay): one tool-free turn yields the evidence-based answer plus an honest note', () => {
const {guard, aborts} = guardFixture();
Object.values(PAGES).forEach((url, index) => readPage(guard, url, `read-${index}`));
- assert.equal(text(exhaustByFailures(guard)), RUN_PROGRESS_STOP_REASON, 'the saved transcript copy is unchanged');
+ assert.equal(text(exhaustByFailures(guard)), PROGRESS_FINALIZATION_INSTRUCTION,
+ 'the persisted copy the next model request carries is the answer instruction, not the stop text');
// The model call that issued the exhausting tool calls may end late.
guard.observeModelEnd({}, context);
enterAnswerTurn(guard);
@@ -274,6 +279,9 @@ test('visual stops never gain an unverified preview or localhost claim', () => {
fabricated: 'I built the site in night-garden. Open http://localhost:8080/ to view the finished event page.',
honest: 'I wrote night-garden/index.html with the three event cards. The preview was not published before the tool limit.',
};
+ // No preview was published: the owner reads the stop plainly, what there is
+ // and what to do next, then where to get help.
+ const unpublished = `${PROGRESS_STOPPED_DELIVERY_PREFIX}\n\n${WORKSPACE_PREVIEW_NOT_CREATED_DELIVERY_PREFIX}\n\n${PROGRESS_STOP_HELP}`;
for (const [kind, answer] of Object.entries(claims)) {
const {guard} = guardFixture(prompt);
exhaustByFailures(guard);
@@ -282,23 +290,25 @@ test('visual stops never gain an unverified preview or localhost claim', () => {
const delivery = guard.deliveryVerificationForRun(context.runId);
assert.equal(delivery.status, 'failed', kind);
assert.equal(delivery.preview, undefined, kind);
- assert.doesNotMatch(delivery.text, /Open last published preview/, kind);
- if (kind === 'fabricated') assert.equal(delivery.text, RUN_PROGRESS_STOP_REASON, 'an unverified local URL forfeits the answer');
- else {
- assert.ok(delivery.text.startsWith(answer));
- assert.match(delivery.text, /ODS did not verify a preview in this response\. No localhost URL is live or claimed\./);
- }
+ assert.doesNotMatch(delivery.text, /Open (?:last published )?preview|preview is ready|localhost/, kind);
+ if (kind === 'fabricated') assert.equal(delivery.text, unpublished, 'an unverified local URL forfeits the answer');
+ else assert.equal(delivery.text, `${answer}\n\n${unpublished}`);
}
- // Only the host-verified publication may be linked, and only as a snapshot.
+ // Only the host-verified publication may be linked: its receipt, which the
+ // dashboard shows as the preview card, after Portal's plain line.
const {guard} = guardFixture(prompt);
const details = verifiedPreview(guard);
exhaustByFailures(guard);
enterAnswerTurn(guard);
- guard.beforeAgentFinalize({lastAssistantMessage: `The page is published at ${details.url} but the sold-out toggle is unverified.`}, context);
+ const answer = `The page is published at ${details.url} but the sold-out toggle is unverified.`;
+ guard.beforeAgentFinalize({lastAssistantMessage: answer}, context);
const delivery = guard.deliveryVerificationForRun(context.runId);
- assert.ok(delivery.text.startsWith('The page is published at'));
- assert.ok(delivery.text.includes(`[Open last published preview](${details.url})`));
- assert.match(delivery.text, /not proof that all requested work completed/);
+ const recorded = guard.verificationForRun(context.runId).text;
+ const receipt = recorded.slice(recorded.indexOf('Your preview is ready.'));
+ assert.ok(receipt.startsWith(`Your preview is ready.\n\n[Open preview](${details.url})\n\n`), receipt);
+ // Failed fetches, not a preview check, stopped it: the page may be unfinished.
+ assert.equal(delivery.text, `${answer}\n\n${PREVIEW_INCOMPLETE_NOTE}\n\n${receipt}`);
+ assert.doesNotMatch(delivery.text, /not proof|not completed|stopped after|tool limit|Open last published preview/);
assert.equal(delivery.preview.sha256, details.sha256);
});
diff --git a/ods/extensions/services/pixel-agent/tests/run_deadline_delivery.test.mjs b/ods/extensions/services/pixel-agent/tests/run_deadline_delivery.test.mjs
index 92a5e79e8..750c01867 100644
--- a/ods/extensions/services/pixel-agent/tests/run_deadline_delivery.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/run_deadline_delivery.test.mjs
@@ -11,6 +11,7 @@ import {readFileSync} from 'node:fs';
import {createIngressServer} from '../host/pixel_ingress.mjs';
import {createToolLoopGuard} from '../plugin/tool-loop-guard.mjs';
import {PREVIEW_EARLIER_NOTE} from '../plugin/preview-explanation.mjs';
+import {PROGRESS_FINALIZATION_INSTRUCTION} from '../plugin/progress-finalization.mjs';
import {RUN_PROGRESS_LIMITS, RUN_PROGRESS_STOP_REASON} from '../plugin/run-progress-budget.mjs';
const RUN_ID = 'chatcmpl_3d1f6c0a-6b1e-4f7a-9a52-2e6f0c7d1a30';
@@ -206,7 +207,9 @@ test('a budget stop keeps its own text, and its tool-free turn gets no notice',
content: [{type: 'text', text: 'Web fetch failed (403)'}]}}, {...OWNER, toolName: 'web_fetch', toolCallId});
}
f.at(26);
- assert.deepEqual(f.read().persisted.content, [{type: 'text', text: RUN_PROGRESS_STOP_REASON}]);
+ // The answer turn is still ahead, so the persisted result carries its
+ // instruction (progress-finalization.mjs), never a deadline notice.
+ assert.deepEqual(f.read().persisted.content, [{type: 'text', text: PROGRESS_FINALIZATION_INSTRUCTION}]);
f.at(30);
f.guard.observeAgentEnd(CUT_OFF, OWNER);
const verification = f.guard.deliveryVerificationForRun(RUN_ID);
diff --git a/ods/extensions/services/pixel-agent/tests/tool_loop_guard.test.mjs b/ods/extensions/services/pixel-agent/tests/tool_loop_guard.test.mjs
index 433aa12da..427286d21 100644
--- a/ods/extensions/services/pixel-agent/tests/tool_loop_guard.test.mjs
+++ b/ods/extensions/services/pixel-agent/tests/tool_loop_guard.test.mjs
@@ -1,6 +1,6 @@
import { RUN_PROGRESS_STOP_REASON } from "../plugin/run-progress-budget.mjs";
import { PROGRESS_FINALIZATION_INSTRUCTION } from "../plugin/progress-finalization.mjs";
-import { PREVIEW_EARLIER_NOTE, PREVIEW_STOPPED_NOTE } from "../plugin/preview-explanation.mjs";
+import { PREVIEW_EARLIER_NOTE, PREVIEW_INCOMPLETE_NOTE, PREVIEW_STOPPED_NOTE } from "../plugin/preview-explanation.mjs";
import test from "node:test";
import vm from 'node:vm';
@@ -344,8 +344,12 @@ test('malformed dispatch failures stop only their active run and retain its veri
const delivery = guard.deliveryVerificationForRun('run-1');
assert.equal(delivery.status,'failed');
assert.equal(delivery.preview.sha256,details.sha256);
- assert.match(delivery.text,/Open last published preview/);
- assert.match(delivery.text,/not completed/);
+ // The owner reads Portal's plain line, that the build stopped unfinished,
+ // and the receipt that becomes the preview card, not the stop facts
+ // (progressStopPresentation).
+ assert.ok(delivery.text.startsWith(`${PREVIEW_INCOMPLETE_NOTE}\n\nYour preview is ready.\n\n[Open preview](${details.url})`),
+ delivery.text);
+ assert.doesNotMatch(delivery.text,/not completed|not proof|stopped after/);
const other = {agentId:'pixel',runId:'run-2',sessionId:'session-2'};
guard.observeRun(other,'pixel',{prompt:'hello'});
assert.equal(guard.deliveryVerificationForRun('run-2').status,'none');
@@ -16492,7 +16496,10 @@ test('progress stops scope historical preview delivery to the current owner requ
}
const delivery = guard.deliveryVerificationForRun(context.runId);
assert.equal(delivery.status, 'failed', prompt);
- assert.ok(delivery.text.startsWith(RUN_PROGRESS_STOP_REASON), prompt);
+ // A website request reads the stop in the owner's wording: Portal's line
+ // and the preview it can show (progressStopPresentation).
+ assert.ok(expectPreview ? delivery.text.startsWith(`${PREVIEW_STOPPED_NOTE}\n\n[Open last published preview](`)
+ : delivery.text.startsWith(RUN_PROGRESS_STOP_REASON), `${prompt}\n${delivery.text}`);
assert.equal(Boolean(delivery.preview), expectPreview, prompt);
assert.equal(delivery.text.includes(details.url), expectPreview, prompt);
if (expectPreview) assert.equal(delivery.preview.sha256, details.sha256);