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(test): read complete delegation evidence records (#8241)
Mike Bradley40fe2b1c770d
diff --git a/ods/extensions/services/pixel-agent/tests/complete_jsonl.test.mjs b/ods/extensions/services/pixel-agent/tests/complete_jsonl.test.mjsnew file mode 100644index 000000000..a27c9ea1a--- /dev/null+++ b/ods/extensions/services/pixel-agent/tests/complete_jsonl.test.mjs@@ -0,0 +1,51 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import {appendFileSync, mkdtempSync, rmSync, writeFileSync} from 'node:fs';+import {tmpdir} from 'node:os';+import {dirname, join} from 'node:path';+import {readCompleteJsonl} from './fixtures/complete-jsonl.mjs';++function fixture(t) {+ const root = mkdtempSync(join(tmpdir(), 'ods-jsonl-evidence-'));+ t.after(() => rmSync(root, {recursive: true, force: true}));+ return join(root, 'hooks.jsonl');+}++test('a split append defers only its unfinished record and reads it after completion', t => {+ const path = fixture(t);+ const first = {hook: 'prompt', runId: 'announce:1'};+ const second = {hook: 'end', runId: 'announce:1', note: 'café'};+ const record = Buffer.from(JSON.stringify(second) + '\n');+ const split = record.indexOf(Buffer.from('é')) + 1;+ writeFileSync(path, JSON.stringify(first) + '\n');+ appendFileSync(path, record.subarray(0, split));+ assert.deepEqual(readCompleteJsonl(path), [first]);+ appendFileSync(path, record.subarray(split));+ assert.deepEqual(readCompleteJsonl(path), [first, second]);+});++test('a valid tail still waits for its newline commit marker', t => {+ const path = fixture(t);+ writeFileSync(path, '{"hook":"end"}');+ assert.deepEqual(readCompleteJsonl(path), []);+ appendFileSync(path, '\n');+ assert.deepEqual(readCompleteJsonl(path), [{hook: 'end'}]);+});++test('malformed complete evidence fails instead of being hidden', t => {+ const path = fixture(t);+ writeFileSync(path, '{"hook":"start"}\n{"broken":}\n{"tail":');+ assert.throws(() => readCompleteJsonl(path), SyntaxError);+});++test('missing and empty evidence can be polled before the producer starts', t => {+ const path = fixture(t);+ assert.deepEqual(readCompleteJsonl(path), []);+ writeFileSync(path, '');+ assert.deepEqual(readCompleteJsonl(path), []);+});++test('filesystem errors other than a missing file remain visible', t => {+ const path = fixture(t);+ assert.throws(() => readCompleteJsonl(dirname(path)), {code: 'EISDIR'});+});diff --git a/ods/extensions/services/pixel-agent/tests/fixtures/complete-jsonl.mjs b/ods/extensions/services/pixel-agent/tests/fixtures/complete-jsonl.mjsnew file mode 100644index 000000000..a22c476aa--- /dev/null+++ b/ods/extensions/services/pixel-agent/tests/fixtures/complete-jsonl.mjs@@ -0,0 +1,16 @@+import {readFileSync} from 'node:fs';++// A live append can end mid-record. The newline commits a JSONL record;+// leave an unfinished tail for the next poll, but reject malformed full lines.+export function readCompleteJsonl(path) {+ let text;+ try {+ text = readFileSync(path, 'utf8');+ } catch (error) {+ if (error.code === 'ENOENT') return [];+ throw error;+ }+ const end = text.lastIndexOf('\n');+ if (end < 0) return [];+ return text.slice(0, end).split('\n').filter(Boolean).map(JSON.parse);+}diff --git a/ods/extensions/services/pixel-agent/tests/runtime_delegation_delivery_hooks.integration.mjs b/ods/extensions/services/pixel-agent/tests/runtime_delegation_delivery_hooks.integration.mjsindex cc9b2b9b7..76d698d56 100644--- a/ods/extensions/services/pixel-agent/tests/runtime_delegation_delivery_hooks.integration.mjs+++ b/ods/extensions/services/pixel-agent/tests/runtime_delegation_delivery_hooks.integration.mjs@@ -12,6 +12,7 @@ import {tmpdir} from 'node:os';import {join} from 'node:path';import {createHash} from 'node:crypto';import {pathToFileURL} from 'node:url';+import {readCompleteJsonl} from './fixtures/complete-jsonl.mjs';import {createIngressServer} from '../host/pixel_ingress.mjs';import {createChatHistoryLedger} from '../host/chat_history_ledger.mjs';import {setTimeout as delay} from 'node:timers/promises';@@ -261,7 +262,7 @@ test(`real gateway deferred delegation waits for two children and a verified rev// actually ended. This reproduces the live partial-completion ordering.let firstEnded=false;for(let i=0;i<250;i++) {- const events=existsSync(eventsFile)?readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];+ const events=readCompleteJsonl(eventsFile);firstEnded=events.some(e=>e.hook==='end'&&e.runId?.startsWith('announce:'));if(firstEnded)break;await delay(50);}@@ -271,7 +272,7 @@ test(`real gateway deferred delegation waits for two children and a verified revif(interim==='daily-reset'){let yielded=false;for(let i=0;i<250;i++){- const events=readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse);+ const events=readCompleteJsonl(eventsFile);yielded=events.some(e=>e.hook==='tool'&&e.toolName==='sessions_yield')&& events.some(e=>e.hook==='end'&&e.runId?.startsWith('chatcmpl_'));if(yielded)break;await delay(20);@@ -286,7 +287,7 @@ test(`real gateway deferred delegation waits for two children and a verified revdelta={role:'assistant',content:childTexts[userMessages.includes('CHILD_FIXTURE_TASK 1')?1:0]};} else if(userMessages.includes('Internal task completion event') || userMessages.includes('CONSOLIDATED_REVIEW') || revision) {trace.branch='parent-announcement';- const observed=readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse);+ const observed=readCompleteJsonl(eventsFile);const finished=observed.filter(e=>e.hook==='end'&&e.sessionKey?.includes(':subagent:')&&childTexts.includes(e.lastText)).length;const announced=new Set(observed.filter(e=>e.hook==='prompt'&&e.provenance?.sourceTool==='subagent_announce').map(e=>e.provenance.sourceSessionKey)).size;if(finished<2||announced<2)delta={role:'assistant',content:interim==='silent'?'NO_REPLY':'One review arrived; waiting for the second.'};@@ -339,7 +340,7 @@ test(`real gateway deferred delegation waits for two children and a verified revconst responsePromise=fetch(`http://127.0.0.1:${ingressPort}/v1/chat/completions`,{method:'POST',headers:{Authorization:'Bearer fixture-only-0123456789abcdef','Content-Type':'application/json'},body:JSON.stringify({model:'openclaw:pixel',stream:true,user:'delegation-fixture',messages:[{role:'user',content:'Delegate two read-only reviews, yield, and consolidate the result.'}],...interim==='cancel'?{request_id:'cancel-original',history_snapshot:{schemaVersion:1,messages:[...prior,{role:'user',content:'Delegate two read-only reviews, yield, and consolidate the result.'}]}}:{}}),signal:AbortSignal.timeout(45000)});if(interim==='reset'){const initialBody=responsePromise.then(response=>response.text()).catch(error=>{assert.ok(['terminated','AbortError'].includes(error.message)||error.name==='AbortError');return '';});- const readEvents=()=>existsSync(eventsFile)?readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];+ const readEvents=()=>readCompleteJsonl(eventsFile);let events=[];for(let i=0;i<250;i++){events=readEvents();@@ -385,7 +386,7 @@ test(`real gateway deferred delegation waits for two children and a verified rev}if(interim==='cancel') {const initialBody=responsePromise.then(response=>response.text()).catch(error=>{assert.ok(['terminated','AbortError'].includes(error.message)||error.name==='AbortError');return '';});- const readEvents=()=>existsSync(eventsFile)?readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];+ const readEvents=()=>readCompleteJsonl(eventsFile);let events=[];for(let i=0;i<250;i++){events=readEvents();@@ -450,7 +451,7 @@ test(`real gateway deferred delegation waits for two children and a verified revif(interim==='overflow-failure'){let events=[];for(let i=0;i<350;i++){- events=existsSync(eventsFile)?readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];+ events=readCompleteJsonl(eventsFile);if(events.some(e=>e.hook==='admission'&&e.runId?.startsWith('announce:')&&e.decision?.outcome==='block'))break;await delay(100);}@@ -467,7 +468,7 @@ test(`real gateway deferred delegation waits for two children and a verified revassert.ok(body.includes('CONSOLIDATED_VERIFIED'),body);assert.ok(!body.includes('Waiting for the review.'),body);assert.ok(!body.includes('CONSOLIDATED_REVIEW'),body);let events=[];for(let i=0;i<250;i++) {- events=existsSync(eventsFile)?readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];+ events=readCompleteJsonl(eventsFile);if(events.some(e=>e.hook==='end'&&e.lastText==='CONSOLIDATED_VERIFIED'))break;await delay(100);}@@ -526,7 +527,7 @@ test(`real gateway deferred delegation waits for two children and a verified revconst reply=await fetch(`http://127.0.0.1:${ingressPort}/v1/chat/completions`,{method:'POST',headers:{Authorization:'Bearer fixture-only-0123456789abcdef','Content-Type':'application/json'},body:JSON.stringify({model:'openclaw:pixel',stream:true,user,messages:[{role:'user',content:prompt}]}),signal:AbortSignal.timeout(30000)});const visible=await reply.text();for(let i=0;i<100;i++) {- events=readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse);+ events=readCompleteJsonl(eventsFile);if(events.some(e=>e.hook==='end'&&e.sessionKey===`agent:pixel:openai-user:ods-${sha(user)}`))break;await delay(50);}@@ -555,7 +556,7 @@ test(`real gateway deferred delegation waits for two children and a verified revheaders:{Authorization:'Bearer fixture-only-0123456789abcdef','Content-Type':'application/json'},body:JSON.stringify({model:'openclaw:pixel',stream:true,user:'delegation-fixture',messages:[{role:'user',content:'HELLO_FIXTURE: a new ordinary owner request after the reset boundary.'}]}),signal:AbortSignal.timeout(30000)});const visible=await next.text();assert.ok(visible.includes('HELLO_VERIFIED'),visible);- events=readFileSync(eventsFile,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse);+ events=readCompleteJsonl(eventsFile);const newOwner=events.filter(e=>e.hook==='prompt'&&e.runId?.startsWith('chatcmpl_')&&e.sessionKey===original.sessionKey).at(-1);assert.notEqual(newOwner.sessionId,original.sessionId,'an ordinary new owner request retains the native daily-reset policy');}