diff --git a/docs/notes/session-export-handoff-gate.md b/docs/notes/session-export-handoff-gate.md index ac0b0739..1da7d97d 100644 --- a/docs/notes/session-export-handoff-gate.md +++ b/docs/notes/session-export-handoff-gate.md @@ -43,3 +43,38 @@ handoff files. Historical public repair paths remain verifiable for compatibilit Only unowned injected test executors are exempt from native-session enforcement. An original computation failure routed directly to failure stays a failure even when its best-effort diagnostic export cannot be recovered. + +## Verification (2026-10-20) + +Integrated changes use authenticated direct V2 API exports, tracked text-only +model prompts, and native settled Pi JSONL export. V1 retains its native CLI +export path. Native messages are retained as escaped JSON alongside the readable +HTML projection so provider metadata and inline tool content are not dropped. + +The original run #19 sessions were read without running any stage or changing +production evidence. Complete, nontruncated HTML exports in the approved +OpenCode temporary `run19-export-proof/` directory contained: + +| Stage | Messages | HTML bytes | +| --- | ---: | ---: | +| Survey | 14 | 1,253,234 | +| Code | 11 | 325,930 | +| Review | 10 | 308,622 | +| UIReview | 16 | 1,358,507 | +| Land | 11 | 320,557 | + +The old CLI silently cut exports at 262,144 bytes. These readbacks verify recovery +is possible for these exact original sessions; they are not production repair +records. Historical message-less `/generate` sessions cannot be reconstructed. + +Checks passed after integration: full Go suite, build/vet, focused gate/recovery +race tests, and browser audit fixtures. The browser fixture verifies export-only +retry and refresh of an already-open Session tab. Large (>256 KiB) API fixtures, +wrong identity, partial/empty exports, restart, cancellation, workspace reservation, +and exactly-once successor admission have focused regressions. A full ordinary +artifact inventory no longer blocks versioned audit repair. + +No shared service was restarted or redeployed. Production run #19's original +evidence remains unchanged. A new real multi-stage run against the installed +gate and native Linux execution remain unverified; source tests and read-only +native readbacks do not substitute for those deployment checks. diff --git a/web/src/artifacts.js b/web/src/artifacts.js index af94a033..04d48071 100644 --- a/web/src/artifacts.js +++ b/web/src/artifacts.js @@ -475,8 +475,12 @@ export function effectiveSessionExport(step) { const id = String(step?.session_id || recorded?.session_id || ""); const original = recorded?.session_id && id && recorded.session_id !== id ? null : recorded; const repairs = [...(step?.session_export_repairs ?? [])].reverse() - .filter((entry) => id !== "" && entry?.session_id === id); - const hasFile = (entry) => Boolean(entry?.html) && (step?.artifacts ?? []).some((file) => file?.name === entry.html && file.size_bytes > 0); + .filter((entry) => id !== "" && entry?.session_id === id && + (!original?.backend || entry.backend === original.backend) && + (!original?.directory || entry.directory === original.directory)); + const hasFile = (entry) => Boolean(entry?.html) && (step?.artifacts ?? []).some((file) => + file?.name === entry.html && file.size_bytes > 0 && + (!(entry.html_bytes > 0) || file.size_bytes === entry.html_bytes)); // A failed later attempt must not hide an earlier, verified full repair. const isComplete = (entry) => entry?.status === "complete" && entry.messages > 0 && entry.html_bytes > 0 && !entry.truncated && !entry.diagnostic && hasFile(entry); @@ -484,9 +488,11 @@ export function effectiveSessionExport(step) { } export function sessionExportArtifact(step) { - const html = effectiveSessionExport(step)?.html; + const evidence = effectiveSessionExport(step); + const html = evidence?.html; if (typeof html !== "string" || html.trim() === "") return null; - return (step?.artifacts ?? []).find((artifact) => artifact?.name === html) ?? null; + return (step?.artifacts ?? []).find((artifact) => artifact?.name === html && + (!(evidence.html_bytes > 0) || artifact.size_bytes === evidence.html_bytes)) ?? null; } /** A recorded ID and an exported document are different facts. Never call a diff --git a/web/src/views/runDetail.js b/web/src/views/runDetail.js index e02d9501..7da2bdda 100644 --- a/web/src/views/runDetail.js +++ b/web/src/views/runDetail.js @@ -274,8 +274,9 @@ function openAuditFor(d, step, stageKey, visitIndex) { const current = currentStep(); if (tab === "session") { const capture = sessionCaptureState(current); - const retrying = capture.artifact && capture.evidence?.status === "complete" ? false : sessionRepairs.has(`${d.id}:${step.sequence}`); - return JSON.stringify([capture.sessionId,capture.artifact,capture.evidence?.status,capture.evidence?.messages,capture.evidence?.truncated,capture.evidence?.diagnostic,capture.message,retrying]); + const complete = capture.artifact && capture.evidence?.status === "complete" && !capture.evidence.truncated; + const retryState = complete ? null : [sessionRepairs.has(`${d.id}:${step.sequence}`), current.agent_active, state.runDetail?.status, state.runDetail?.export_pending_sequence]; + return JSON.stringify([capture.sessionId,capture.artifact,capture.evidence?.status,capture.evidence?.messages,capture.evidence?.truncated,capture.evidence?.diagnostic,capture.message,retryState]); } if (["input","output","memory"].includes(tab)) return JSON.stringify(systemArtifacts(current).find((entry)=>entry.name===`${tab}.md`) ?? null); return `${d.pipeline_id}:${d.version}:${stageKey}`; diff --git a/web/sw.js b/web/sw.js index 21230636..872442bd 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ // A shell cache for an installed Pipelines app. The API (the WebSocket proxy and // artifact files) is never cached; static files prefer the network and fall back // to the last good copy so an installed app still opens when the server is away. -const CACHE = "pipelines-shell-v8"; +const CACHE = "pipelines-shell-v9"; const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"]; self.addEventListener("install", (event) => { diff --git a/web/test/serviceWorker.test.mjs b/web/test/serviceWorker.test.mjs index 62b0c9d5..755f7a66 100644 --- a/web/test/serviceWorker.test.mjs +++ b/web/test/serviceWorker.test.mjs @@ -9,9 +9,9 @@ test("shell updates retain unrelated caches and the current app cache", async () let activation; vm.runInNewContext(await readFile(new URL("../sw.js", import.meta.url), "utf8"), { self: { addEventListener: (type, handler) => handlers.set(type, handler), clients: { claim: async () => {} } }, - caches: { keys: async () => ["pipelines-shell-v7", "pipelines-shell-v8", "unrelated-user-cache"], delete: async (key) => deleted.push(key) }, + caches: { keys: async () => ["pipelines-shell-v8", "pipelines-shell-v9", "unrelated-user-cache"], delete: async (key) => deleted.push(key) }, }); handlers.get("activate")({ waitUntil: (promise) => { activation = promise; } }); await activation; - assert.deepEqual(deleted, ["pipelines-shell-v7"]); + assert.deepEqual(deleted, ["pipelines-shell-v8"]); }); diff --git a/web/test/session-audit-browser.mjs b/web/test/session-audit-browser.mjs index dc10974b..f18d12d8 100644 --- a/web/test/session-audit-browser.mjs +++ b/web/test/session-audit-browser.mjs @@ -23,6 +23,7 @@ const rt={state,modal:createModalController(),views:{},repo:{repairSessionExport rt.views.chat=createChatView(rt);rt.views.dialogs=createDialogsView(rt);rt.views.runDetail=createRunDetailView(rt); document.querySelector('main').append(rt.views.runDetail.renderStagePane(run));rt.modal.reconcile(); window.recordRepair=()=>{const updated={...step,session_export_repairs:[{session_id:'ses_exact',status:'complete',messages:14,html:'session-repair-1-fixed.html',html_bytes:100}],artifacts:[{name:'session-repair-1-fixed.html',url:'/artifacts/19/1/session-repair-1-fixed.html',content_type:'text/html',size_bytes:100}]};state.runDetail={...run,steps:[updated]};rt.views.dialogs.refreshStageAudit();}; +window.parkForExport=()=>{state.runDetail={...run,status:'waiting',export_pending_sequence:1,steps:[{...step,session_export_recovery:{status:'pending'}}]};rt.views.dialogs.refreshStageAudit();}; `; const server=createServer(async(req,res)=>{try{ const pathname=new URL(req.url,"http://fixture").pathname; @@ -40,6 +41,11 @@ try{ assert.match(await page.evaluate("document.querySelector('.audit-body').textContent"),/ses_exact is recorded/); assert.doesNotMatch(await page.evaluate("document.querySelector('.audit-body').textContent"),/Session not recorded|exported by model stages/); await page.screenshot(resolve(out,'01-recorded-identity-export-failed.png')); + await page.evaluate('parkForExport()'); + assert.match(await page.evaluate("document.querySelector('.audit-body').textContent"),/pending recovery/); + assert.equal(await page.evaluate("document.querySelector('.session-export-retry').disabled"),false); + assert.equal(await page.evaluate("document.querySelectorAll('.decision-card').length"),0); + await page.screenshot(resolve(out,'03-export-wait-is-not-a-human-decision.png')); await page.click('.session-export-retry');await page.waitForSelector('.audit-session-frame'); assert.deepEqual(await page.evaluate('repairRequests'),[{id:19,sequence:1}]); assert.match(await page.evaluate("document.querySelector('.audit-session-frame').src"),/session-repair-1-fixed.html$/); diff --git a/web/test/sessionCapture.test.mjs b/web/test/sessionCapture.test.mjs index 8d7c3644..1fcd3279 100644 --- a/web/test/sessionCapture.test.mjs +++ b/web/test/sessionCapture.test.mjs @@ -49,6 +49,24 @@ test("an original export naming another session is not selected", () => { assert.equal(sessionExportArtifact({session_id:"ses_stage",session_export:original,artifacts:[file("session.html")]}),null); }); +test("repairs must match the original backend and directory, not just its session ID", () => { + const original={session_id:"ses_stage",backend:"v2",directory:"/owned",status:"failed"}; + for (const override of [{backend:"pi",directory:"/owned"},{backend:"v2",directory:"/other"}]) { + const repair={...complete("session-repair-other.html"),...override}; + const step={session_id:"ses_stage",session_export:original,session_export_repairs:[repair],artifacts:[file(repair.html)]}; + assert.equal(effectiveSessionExport(step),original); + assert.equal(sessionExportArtifact(step),null); + } +}); + +test("a repair's file bytes must match its export receipt", () => { + const original=complete("session.html"); + const repair=complete("session-repair-mismatch.html"); + const step={session_id:"ses_stage",session_export:original,session_export_repairs:[repair],artifacts:[file(original.html),{...file(repair.html),size_bytes:1}]}; + assert.equal(effectiveSessionExport(step),original); + assert.equal(sessionExportArtifact({...step,session_export:null}),null); +}); + test("pre-admission failure, starting session and export recovery have distinct states", () => { assert.match(sessionCaptureState({model:"fixture",status:"running"}).message,/being created/); assert.match(sessionCaptureState({model:"fixture",status:"failed",diagnostic:"provider unreachable"}).message,/did not create.*provider unreachable/);