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.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
fix(pixel): retain activity and downloads across native attempts (#8243)
Mike Bradley94eb8a7343cc
diff --git a/.github/workflows/portal-runtime.yml b/.github/workflows/portal-runtime.ymlindex f41cf8905..d2b0a5ad4 100644--- a/.github/workflows/portal-runtime.yml+++ b/.github/workflows/portal-runtime.yml@@ -65,6 +65,8 @@ jobs:run: node --test ods/extensions/services/pixel-agent/tests/repository_acquisition_routing.test.mjs ods/extensions/services/pixel-agent/tests/prompt_contract.test.mjs ods/extensions/services/pixel-agent/tests/english_default.test.mjs ods/extensions/services/pixel-agent/tests/response_language.test.mjs ods/extensions/services/pixel-agent/tests/operations_composition.test.mjs ods/extensions/services/pixel-agent/tests/download_promote.test.mjs ods/extensions/services/pixel-agent/tests/network_interface_intent.test.mjs ods/extensions/services/pixel-agent/tests/host_service_constraint_intent.test.mjs ods/extensions/services/pixel-agent/tests/download_terminal_receipt.test.mjs- name: Verify host report download continuation across platformsrun: node --test ods/extensions/services/pixel-agent/tests/host_workspace_artifact_continuation.test.mjs+ - name: Verify activity and downloads across native attempts+ run: node --test ods/extensions/services/pixel-agent/tests/attempt_lifecycle.test.mjs ods/extensions/services/pixel-agent/tests/task_activity.test.mjs- name: Verify bounded preview delivery across platformsrun: |node --test ods/extensions/services/pixel-agent/tests/preview_delivery_recovery.test.mjsdiff --git a/ods/extensions/services/pixel-agent/plugin/task-activity.mjs b/ods/extensions/services/pixel-agent/plugin/task-activity.mjsindex b7dfb3c09..056d01929 100644--- a/ods/extensions/services/pixel-agent/plugin/task-activity.mjs+++ b/ods/extensions/services/pixel-agent/plugin/task-activity.mjs@@ -62,12 +62,12 @@ export function createTaskActivity({agentId = 'pixel', now = () => new Date().toconst run = knownRun(event, context);const freshPromptBuild = event && typeof event === 'object' && !run.promptBuildEvents.has(event);if (event && typeof event === 'object') run.promptBuildEvents.add(event);- // OpenClaw emits agent_end for each embedded attempt, including a- // context-overflow precheck that it subsequently compacts and retries.- // Only a fresh owned before_prompt_build may reopen a failed attempt.+ // OpenClaw ends each embedded attempt, including an empty successful+ // attempt followed by real work under the same request ID.+ // Only a fresh owned before_prompt_build may reopen a settled attempt.// Preserve all prior tool failures and the original request start time.if (freshPromptBuild && typeof event.prompt === 'string' && event.prompt.trim()- && run.state === 'failed' && run.finishedAt && !run.sessionConflict+ && ['failed', 'completed', 'finished'].includes(run.state) && run.finishedAt && !run.sessionConflict&& typeof run.sessionId === 'string' && run.sessionId&& context?.sessionId === run.sessionId&& typeof run.sessionKey === 'string' && run.sessionKey@@ -144,6 +144,11 @@ export function createTaskActivity({agentId = 'pixel', now = () => new Date().tofinish(event, context) {const run = knownRun(event, context);if (!run) return;+ const endEvents = run.endEvents ??= new WeakSet();+ if (event && typeof event === 'object') {+ if (endEvents.has(event)) return;+ endEvents.add(event);+ }if (run.finishedAt) return;run.finishedAt = [...run.calls.values()].reduce((latest,call)=>noEarlierThan(latest,call.finishedAt ?? call.startedAt),noEarlierThan(now(),run.startedAt));diff --git a/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs b/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjsindex 80e36e547..713399a25 100644--- a/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs+++ b/ods/extensions/services/pixel-agent/plugin/tool-loop-guard.mjs@@ -10732,6 +10732,24 @@ export function createToolLoopGuard({state.artifactSurfaceReason = state.artifactOwnerInteractive ? undefined :state.artifactIdentityConflict ? 'run-identity-conflict' : state.artifactNoninteractiveObserved ? 'noninteractive-turn' :artifactContext.trigger == null ? 'trigger-unavailable' : 'owner-session-required';+ // agent_end closes an embedded attempt, not necessarily the outer+ // request. A fresh native prompt hook can start its next attempt.+ // Reopen only this owner's still-current request; retain all stop flags,+ // budgets and receipts. Replaying a previous hook cannot revive it.+ const promptBuildEvents = state.promptBuildEvents ??= new WeakSet();+ const freshPromptBuild = event && typeof event === 'object' && !promptBuildEvents.has(event);+ if (event && typeof event === 'object') promptBuildEvents.add(event);+ if (freshPromptBuild && typeof event.prompt === 'string' && event.prompt.trim()+ && state.runEnded && state.artifactOwnerInteractive && !state.managedTeamWorker+ && !state.clientCancelled && !state.odsAborted && !state.recursiveDeleteDenied+ && !state.progressBudget.exhausted+ && state.currentSessionId === context.sessionId && state.currentSessionKey === context.sessionKey+ && sessionRuns.get(context.sessionId) === runId) {+ state.runEnded = false;+ // A broker response reserved by the ended attempt must not attach to+ // its successor. Each admitted call has its own private scope object.+ state.artifactReservations = new WeakSet();+ }state.completionAssurance.begin(currentOwnerIntentText(event?.messages, event?.prompt), event);const ownerIntent=currentOwnerIntentText(event?.messages,event?.prompt);if (ownerIntent && state.ownerNoTools === undefined) state.ownerNoTools=ownerForbidsTools(ownerIntent);@@ -13638,6 +13656,11 @@ export function createToolLoopGuard({recordExampleOutcome({...context, runId}, examples.end(runId));const state = runs.get(runId);if (!state) return;+ const endEvents = state.agentEndEvents ??= new WeakSet();+ if (event && typeof event === 'object') {+ if (endEvents.has(event)) return;+ endEvents.add(event);+ }state.runEnded = true;state.runDeadlineReached = !state.clientCancelled && !state.odsAborted && !state.progressBudget.exhausted &&!state.recursiveDeleteDenied && runDeadlineReached(state.runDeadline, event, now());@@ -14504,11 +14527,12 @@ export function createToolLoopGuard({if (workspaceArtifactUnavailableReason(scope)) return false;const state=runs.get(scope.runId);state.artifactAttempts=(state.artifactAttempts ?? 0)+1;+ (state.artifactReservations ??= new WeakSet()).add(scope);return true;},acceptWorkspaceArtifact(scope,receipt) {const state=artifactScopeState(scope);- if (!state || !state.artifactAttempts || !validDeliveredArtifact(receipt)) return false;+ if (!state || !state.artifactReservations?.has(scope) || !validDeliveredArtifact(receipt)) return false;const artifacts=state.workspaceArtifacts ??= [];if (artifacts.some(item=>item.siteId === receipt.siteId && item.file.path === receipt.file.path)) return true;if (artifacts.length >= 4) return false;diff --git a/ods/extensions/services/pixel-agent/tests/attempt_lifecycle.test.mjs b/ods/extensions/services/pixel-agent/tests/attempt_lifecycle.test.mjsnew file mode 100644index 000000000..91408003d--- /dev/null+++ b/ods/extensions/services/pixel-agent/tests/attempt_lifecycle.test.mjs@@ -0,0 +1,122 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import {createTaskActivity} from '../plugin/task-activity.mjs';+import {createToolLoopGuard} from '../plugin/tool-loop-guard.mjs';+import {ARTIFACT_TOOL, ARCHIVE_BOUNDARY, createWorkspaceArtifactAdmission, createWorkspaceArtifactTool} from '../plugin/workspace-artifact.mjs';++const user = 'ods-' + 'a'.repeat(64);+const context = {trigger: 'user', agentId: 'pixel', runId: 'chatcmpl_11111111-1111-4111-8111-111111111111',+ sessionId: 'owned-session', sessionKey: 'agent:pixel:openai-user:' + user};+const prompt = 'Fix the README and deliver the project as a downloadable ZIP.';++function fixture() {+ const guard = createToolLoopGuard({abortRun: () => true});+ let instant = '2026-10-27T04:57:41.929Z';+ const activity = createTaskActivity({now: () => instant});+ const first = {prompt};+ function begin(event = {prompt}, scope = context) {+ guard.observeRun(scope, 'pixel', event);+ activity.begin(event, scope);+ }+ function end(event = {success: true}) {+ guard.observeAgentEnd(event, context);+ activity.finish(event, context);+ return event;+ }+ begin(first);+ return {guard, activity, first, begin, end, time: value => {instant = value;}};+}++for (const success of [true, false]) test(`a fresh owned attempt restores publication after success=${success}`, async () => {+ const f = fixture();+ f.time('2026-10-27T04:57:42.073Z');+ const ended = f.end({success});+ assert.equal(f.guard.workspaceArtifactUnavailableReason(context), 'run-ended');+ f.time('2026-10-27T04:57:42.258Z');+ f.begin();+ assert.equal(f.activity.activeForUser(user)?.runId, context.runId);+ assert.equal(f.activity.projection(context.runId).finishedAt, null);+ assert.equal(f.guard.workspaceArtifactUnavailableReason(context), undefined);++ // Re-delivery of the already observed end hook cannot close the new attempt.+ f.end(ended);+ assert.equal(f.activity.projection(context.runId).state, 'running');+ assert.equal(f.guard.workspaceArtifactUnavailableReason(context), undefined);+ const args = {sourcePath: 'project', relativePath: 'project.zip'};+ const scope = {...context, toolCallId: 'publish'};+ const event = {toolName: ARTIFACT_TOOL, params: args};+ const admission = createWorkspaceArtifactAdmission();+ admission.before(event, scope, f.guard.beforeToolCall(event, scope));+ f.activity.before(event, scope);+ const tool = createWorkspaceArtifactTool(context, {admission,+ reserve: s => f.guard.reserveWorkspaceArtifact(s),+ unavailableReason: s => f.guard.workspaceArtifactUnavailableReason(s),+ accept: (s, r) => f.guard.acceptWorkspaceArtifact(s, r),+ request: async () => ({schemaVersion: 1, kind: 'ods-pixel-workspace-artifact',+ relativePath: 'project.zip', siteId: 'site-' + 'a'.repeat(24), sha256: 'a'.repeat(64),+ file: {path: 'project.zip', bytes: 100, sha256: 'b'.repeat(64)}, status: 'succeeded',+ httpStatus: 200, readbackVerified: true, executable: false, overwritten: false,+ boundary: ARCHIVE_BOUNDARY, archive: {sourcePath: 'project', fileCount: 4, sourceBytes: 200, omittedCacheEntries: 2}})});+ const result = await tool.execute(scope.toolCallId, args);+ assert.notEqual(result.isError, true);+ f.activity.after({result}, scope);+ f.time('2026-10-27T04:59:24.198Z');+ f.end();+ const view = f.activity.projection(context.runId);+ assert.equal(view.startedAt, '2026-10-27T04:57:41.929Z');+ assert.equal(view.finishedAt, '2026-10-27T04:59:24.198Z');+ assert.equal(view.calls, 1);+ assert.equal(f.guard.deliveryVerificationForRun(context.runId).artifacts.length, 1);+});++test('replayed prompts and missing or mismatched identities cannot reopen publication', () => {+ for (const variant of ['same-event', 'blank-prompt', 'missing-prompt', 'session', 'key', 'missing-session', 'missing-key', 'agent', 'noninteractive']) {+ const f = fixture();+ f.end();+ const scope = {...context};+ if (variant === 'session') scope.sessionId = 'other';+ if (variant === 'key') scope.sessionKey = 'agent:pixel:openai-user:ods-' + 'b'.repeat(64);+ if (variant === 'missing-session') delete scope.sessionId;+ if (variant === 'missing-key') delete scope.sessionKey;+ if (variant === 'agent') scope.agentId = 'other';+ if (variant === 'noninteractive') scope.trigger = 'cron';+ f.begin(variant === 'same-event' ? f.first : variant === 'blank-prompt' ? {prompt: ' '} : variant === 'missing-prompt' ? {} : {prompt}, scope);+ assert.ok(f.guard.workspaceArtifactUnavailableReason(context), variant);+ }+});++test('attempts preserve cancellation and recursive-delete refusal', async () => {+ for (const stop of ['cancel', 'delete']) {+ const f = fixture();+ if (stop === 'cancel') await f.guard.abortUserRun(user);+ else assert.equal(f.guard.beforeToolCall({toolName: 'exec', toolCallId: 'delete',+ params: {command: 'rm -rf /workspace/project'}}, context)?.block, true);+ f.end({success: false});+ f.begin();+ assert.ok(f.guard.workspaceArtifactUnavailableReason(context), stop);+ }+});++test('attempts preserve the per-request publication budget', () => {+ const f = fixture();+ for (let i = 0; i < 4; i++) assert.ok(f.guard.reserveWorkspaceArtifact(context));+ f.end();+ f.begin();+ assert.equal(f.guard.workspaceArtifactUnavailableReason(context), 'publication-attempt-limit');+});++test('a late receipt reserved by the ended attempt cannot attach after reopening', () => {+ const f = fixture();+ const prior = {...context, toolCallId: 'prior-publication'};+ const next = {...context, toolCallId: 'next-publication'};+ const receipt = {schemaVersion: 1, kind: 'ods-pixel-workspace-artifact',+ relativePath: 'project.zip', siteId: 'site-' + 'a'.repeat(24), sha256: 'a'.repeat(64),+ file: {path: 'project.zip', bytes: 100, sha256: 'b'.repeat(64)}};+ assert.equal(f.guard.reserveWorkspaceArtifact(prior), true);+ f.end();+ f.begin();+ assert.equal(f.guard.reserveWorkspaceArtifact(next), true);+ assert.equal(f.guard.acceptWorkspaceArtifact(prior, receipt), false);+ assert.equal(f.guard.acceptWorkspaceArtifact({...next}, receipt), false);+ assert.equal(f.guard.acceptWorkspaceArtifact(next, receipt), true);+});diff --git a/ods/extensions/services/pixel-agent/tests/task_activity.test.mjs b/ods/extensions/services/pixel-agent/tests/task_activity.test.mjsindex 49e142bc3..736f8bbed 100644--- a/ods/extensions/services/pixel-agent/tests/task_activity.test.mjs+++ b/ods/extensions/services/pixel-agent/tests/task_activity.test.mjs@@ -52,14 +52,14 @@ test('recovered attempts retain previous failed calls and can themselves fail',});test('duplicate, unowned, incomplete and late hooks cannot reopen a closed attempt', () => {- for (const variant of ['completed','same-event','missing-prompt','blank-prompt','wrong-session','missing-session','missing-original-session','wrong-key','missing-key','conflicted-key','other-agent','late-tool','late-finish']) {+ for (const variant of ['same-event','missing-prompt','blank-prompt','wrong-session','missing-session','missing-original-session','wrong-key','missing-key','conflicted-key','other-agent','late-tool','late-finish']) {const context={...ctx,sessionId:'owned-session',sessionKey:'agent:pixel:openai-user:ods-'+'a'.repeat(64)};const recorder=createTaskActivity({now});const original={prompt:'Do the work'};const initialContext={...context};if(variant==='missing-original-session')delete initialContext.sessionId;recorder.begin(original,initialContext);- recorder.finish({success:variant==='completed'},context);+ recorder.finish({success:false},context);const closed=recorder.projection(runId);const retryContext={...context};if(variant==='wrong-session')retryContext.sessionId='other-session';