fix(audit): expose verified visit exports and export-only recovery
This commit is contained in:
@@ -1846,6 +1846,7 @@ function refreshVisibleListOnForeground() {
|
||||
/** Render whatever a run-state change touched, without re-reading anything. */
|
||||
function renderRunState() {
|
||||
if (state.view === "runs" || state.view === "pipelines") renderContent();
|
||||
views.dialogs.refreshStageAudit?.();
|
||||
refreshAttentionBell();
|
||||
}
|
||||
|
||||
@@ -2101,6 +2102,7 @@ function applyRunEvent(frame) {
|
||||
}
|
||||
const detail = state.runDetail;
|
||||
if (detail && Number(detail.id) === runId) {
|
||||
if (frame.session_export_updated === true) scheduleRunDetailSync(runId);
|
||||
runWatch.detailDeltaCount += 1;
|
||||
const folded = foldRunEventDetail(detail, frame);
|
||||
const detailChanged = folded !== detail;
|
||||
@@ -2381,6 +2383,7 @@ const runtime = {
|
||||
onReconnectClicked,
|
||||
selectPipeline,
|
||||
selectRun,
|
||||
refreshRunDetail: scheduleRunDetailSync,
|
||||
setError,
|
||||
loadCurrentView,
|
||||
};
|
||||
|
||||
+38
-1
@@ -468,12 +468,49 @@ export function artifactViewerPositionLabel(index, count, contentType) {
|
||||
* that recorded no export, whose export name is blank, or whose file is missing
|
||||
* from a truncated listing yields null. Mirrors SessionExport.kt sessionExportFile.
|
||||
*/
|
||||
export function effectiveSessionExport(step) {
|
||||
const recorded = step?.session_export ?? null;
|
||||
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);
|
||||
// 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);
|
||||
return repairs.find(isComplete) ?? (isComplete(original) ? original : null) ?? repairs.find(hasFile) ?? (hasFile(original) ? original : null) ?? repairs[0] ?? original ?? null;
|
||||
}
|
||||
|
||||
export function sessionExportArtifact(step) {
|
||||
const html = step?.session_export?.html;
|
||||
const html = effectiveSessionExport(step)?.html;
|
||||
if (typeof html !== "string" || html.trim() === "") return null;
|
||||
return (step?.artifacts ?? []).find((artifact) => artifact?.name === html) ?? null;
|
||||
}
|
||||
|
||||
/** A recorded ID and an exported document are different facts. Never call a
|
||||
* recorded session "not recorded" just because its export is missing. */
|
||||
export function sessionCaptureState(step) {
|
||||
const evidence = effectiveSessionExport(step);
|
||||
const sessionId = String(step?.session_id || evidence?.session_id || "");
|
||||
const artifact = sessionExportArtifact(step);
|
||||
if (artifact) return { sessionId, evidence, artifact, message: "" };
|
||||
if (sessionId) {
|
||||
const recovery = step?.session_export_recovery;
|
||||
const status = recovery?.status === "pending" || recovery?.status === "running"
|
||||
? "pending recovery" : evidence?.status === "complete" ? "not available in the artifact inventory" : evidence?.status || "not yet available";
|
||||
return { sessionId, evidence, artifact: null,
|
||||
message: `Session ${sessionId} is recorded. Its export is ${status}.${evidence?.diagnostic ? ` ${evidence.diagnostic}` : ""}` };
|
||||
}
|
||||
const model = Boolean(step?.model || step?.provider);
|
||||
const skipped=step?.status==="skipped" || step?.outcome==="skipped";
|
||||
const stopped=["canceled","interrupted"].includes(step?.status);
|
||||
return { sessionId, evidence, artifact: null, message: skipped ? "This visit was skipped; no harness session was started." : stopped ? "The stage stopped before a harness session was recorded." : model
|
||||
? step?.status === "running" ? "The stage session is being created."
|
||||
: step?.status === "failed" ? `The stage did not create a harness session.${step?.diagnostic ? ` ${step.diagnostic}` : ""}`
|
||||
: "Runtime error: this model stage has no recorded session identity."
|
||||
: "This visit has no harness session." };
|
||||
}
|
||||
|
||||
/**
|
||||
* The absolute url a gallery artifact can be opened at, or null when it cannot
|
||||
* be resolved against the configured server (blank or invalid). The one place a
|
||||
|
||||
@@ -25,6 +25,7 @@ export const Protocol = Object.freeze({
|
||||
LIST_RUNS: "list_runs",
|
||||
RUNS: "runs",
|
||||
GET_RUN: "get_run",
|
||||
REPAIR_SESSION_EXPORT: "repair_session_export",
|
||||
RUN: "run",
|
||||
|
||||
// Live run state (internal/protocol/runevents.go, Message.kt; R10). `subscribe`
|
||||
|
||||
@@ -115,6 +115,14 @@ export class PipelinesRepository {
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/** Export the exact recorded visit again; never invokes its model or tools. */
|
||||
async repairSessionExport(id, sequence) {
|
||||
if (!Number.isSafeInteger(id) || id<1 || !Number.isSafeInteger(sequence) || sequence<1) throw new ProtocolError("An exact run and visit are required.");
|
||||
const response=await this.#client.call({type:Protocol.REPAIR_SESSION_EXPORT,run_id:id,export_sequence:sequence});
|
||||
if (!response.run_detail) throw new ProtocolError("The server returned no run detail.");
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the server to push this connection the live run state it displays
|
||||
* (R10, also the source of L5's notifications). Send-only, mirroring
|
||||
|
||||
@@ -59,6 +59,9 @@ export function createDialogsView(rt) {
|
||||
|
||||
let changeViewerOverlay = null;
|
||||
let changeViewerIndex = null;
|
||||
let refreshAudit = null;
|
||||
|
||||
function refreshStageAudit() { refreshAudit?.(); }
|
||||
|
||||
/** Close the diff viewer; the controller returns focus to the viewed row. */
|
||||
function closeChangeViewer() {
|
||||
@@ -840,10 +843,10 @@ function openStageDefinition(detail, stageKey, subtitle = "") {
|
||||
* on the right. It is the only place the system files are shown, so the artifact
|
||||
* surfaces stay focused on what the stage actually produced.
|
||||
*/
|
||||
function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = null } = {}) {
|
||||
function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = null, revision = null } = {}) {
|
||||
const available = (tabs ?? []).filter((tab) => typeof tab?.body === "function");
|
||||
if (!available.length) return;
|
||||
const close = () => modal.close("stage-audit");
|
||||
const close = () => { refreshAudit = null; modal.close("stage-audit"); };
|
||||
const overlay = h("div", {
|
||||
class: "audit-viewer",
|
||||
role: "dialog",
|
||||
@@ -890,6 +893,12 @@ function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = n
|
||||
overlay.append(panel);
|
||||
|
||||
let active = available[0].key;
|
||||
let renderedRevision = null;
|
||||
const renderBody = () => {
|
||||
const current = available.find((tab) => tab.key === active) ?? available[0];
|
||||
body.replaceChildren(current.body());
|
||||
renderedRevision = typeof revision === "function" ? revision(active) : null;
|
||||
};
|
||||
const renderTabs = () => {
|
||||
nav.replaceChildren(
|
||||
...available.map((tab) => {
|
||||
@@ -923,8 +932,7 @@ function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = n
|
||||
});
|
||||
}),
|
||||
);
|
||||
const current = available.find((tab) => tab.key === active) ?? available[0];
|
||||
body.replaceChildren(current.body());
|
||||
renderBody();
|
||||
};
|
||||
renderTabs();
|
||||
modal.open("stage-audit", overlay, {
|
||||
@@ -932,9 +940,14 @@ function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = n
|
||||
trigger,
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
refreshAudit = () => {
|
||||
if (!overlay.isConnected || typeof revision !== "function") return;
|
||||
if (revision(active) !== renderedRevision) renderBody();
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
refreshStageAudit,
|
||||
openStageDefinition,
|
||||
closeChangeViewer,
|
||||
openChangeViewer,
|
||||
|
||||
+62
-12
@@ -50,6 +50,8 @@ import {
|
||||
presentedArtifacts,
|
||||
resolvedArtifactUrl,
|
||||
sessionExportArtifact,
|
||||
effectiveSessionExport,
|
||||
sessionCaptureState,
|
||||
stageArtifacts,
|
||||
systemArtifacts,
|
||||
visitArtifacts,
|
||||
@@ -111,6 +113,31 @@ export function createRunDetailView(rt) {
|
||||
const openArtifactViewer = (...args) => rt.views.dialogs.openArtifactViewer(...args);
|
||||
const showStageAudit = (...args) => rt.views.dialogs.openStageAudit(...args);
|
||||
const selectPipeline = (...args) => rt.selectPipeline(...args);
|
||||
const sessionRepairs = new Set();
|
||||
|
||||
function sessionExportRetry(step) {
|
||||
const run=state.runDetail;
|
||||
if (!run?.id || !step?.sequence || !(step.session_id || step.session_export?.session_id)) return null;
|
||||
const key=`${run.id}:${step.sequence}`;
|
||||
const running=step.agent_active || ["running","queued"].includes(run.status) ||
|
||||
(run.status==="waiting" && run.export_pending_sequence!==step.sequence);
|
||||
const button=h("button",{class:"ghost session-export-retry",type:"button",disabled:running || sessionRepairs.has(key),
|
||||
text:sessionRepairs.has(key)?"Exporting…":"Retry export only",
|
||||
title:"Read the exact recorded session again. Does not rerun the stage or its tools."});
|
||||
button.addEventListener("click",async()=>{
|
||||
if (sessionRepairs.has(key)) return;
|
||||
sessionRepairs.add(key);button.disabled=true;button.textContent="Exporting…";
|
||||
try {
|
||||
const detail=await repo.repairSessionExport(run.id,step.sequence);
|
||||
if (state.runDetail?.id===run.id) {
|
||||
if (rt.refreshRunDetail) rt.refreshRunDetail(run.id);
|
||||
else {state.runDetail=detail;renderContent();}
|
||||
}
|
||||
} catch(error) {state.actionError=describeError(error);renderContent();}
|
||||
finally {sessionRepairs.delete(key);button.disabled=Boolean(running);button.textContent="Retry export only";rt.views.dialogs.refreshStageAudit?.();}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* The run detail: a tab strip (Summary / Graph / Input / Output / Timeline) over
|
||||
@@ -213,18 +240,30 @@ function latestVisitIndex(d, key) {
|
||||
/** Open the audit dialog for one visit: its turn files, session and definition. */
|
||||
function openAuditFor(d, step, stageKey, visitIndex) {
|
||||
if (!step) return;
|
||||
const currentStep = () => state.runDetail?.id === d.id
|
||||
? state.runDetail.steps?.find((entry) => entry.sequence === step.sequence) ?? step : step;
|
||||
showStageAudit({
|
||||
title: `${nodeLabel(stageKey)} audit`,
|
||||
subtitle: `Visit ${visitIndex + 1} · ${runLabelFor(d)}`,
|
||||
tabs: [
|
||||
{ key: "input", label: "Input", body: () => auditArtifact(step, "input.md", EMPTY_INPUT_MESSAGE) },
|
||||
{ key: "output", label: "Output", body: () => auditArtifact(step, "output.md", EMPTY_OUTPUT_MESSAGE) },
|
||||
{ key: "memory", label: "Memory", body: () => auditArtifact(step, "memory.md", "No memory recorded for this visit.") },
|
||||
{ key: "session", label: "Session", body: () => auditSession(step) },
|
||||
{ key: "input", label: "Input", body: () => auditArtifact(currentStep(), "input.md", EMPTY_INPUT_MESSAGE) },
|
||||
{ key: "output", label: "Output", body: () => auditArtifact(currentStep(), "output.md", EMPTY_OUTPUT_MESSAGE) },
|
||||
{ key: "memory", label: "Memory", body: () => auditArtifact(currentStep(), "memory.md", "No memory recorded for this visit.") },
|
||||
{ key: "session", label: "Session", body: () => auditSession(currentStep()) },
|
||||
{ key: "definition", label: "Definition", body: () => definitionDocument(
|
||||
runDefinition(d), stageKey, (text) => rt.views.chat.renderMarkdown(text),
|
||||
) },
|
||||
],
|
||||
revision: (tab) => {
|
||||
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]);
|
||||
}
|
||||
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}`;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -303,15 +342,25 @@ function auditArtifact(step, name, emptyMessage) {
|
||||
|
||||
/** The exported session, rendered in place, with the raw file one click away. */
|
||||
function auditSession(step) {
|
||||
const artifact = systemArtifacts(step).find((entry) => entry.name === "session.html");
|
||||
const capture = sessionCaptureState(step);
|
||||
const legacy = !step?.session_export && !(step?.session_export_repairs?.length);
|
||||
const artifact = capture.artifact ?? (legacy ? systemArtifacts(step).find((entry) => entry.name === "session.html") : null);
|
||||
if (!artifact) {
|
||||
return h("div", {
|
||||
class: "muted",
|
||||
text: "Session not recorded for this visit. Sessions are exported by model stages.",
|
||||
const body = h("div", {
|
||||
class: "audit-session-state muted",
|
||||
"data-session-id": capture.sessionId,
|
||||
});
|
||||
body.append(h("p",{text:capture.message}));
|
||||
const retry=sessionExportRetry(step);if(retry)body.append(retry);
|
||||
return body;
|
||||
}
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
const wrap = h("div", { class: "audit-session" });
|
||||
if (capture.sessionId) wrap.append(h("p", {class:"audit-session-state muted",text:`Recorded session: ${capture.sessionId}`}));
|
||||
if (capture.evidence && (capture.evidence.status && capture.evidence.status!=="complete" || capture.evidence.truncated)) {
|
||||
wrap.append(h("p",{class:"audit-session-state muted",text:`This export is ${capture.evidence.status || "partial"}; full session evidence is not available.`}));
|
||||
const retry=sessionExportRetry(step);if(retry)wrap.append(retry);
|
||||
}
|
||||
if (!resolved) {
|
||||
wrap.append(h("div", { class: "muted", text: ARTIFACT_SERVER_HINT }));
|
||||
return wrap;
|
||||
@@ -1273,23 +1322,24 @@ function artifactAction(kind, label, disabled, onclick) {
|
||||
function renderSessionExport(step) {
|
||||
const file = sessionExportArtifact(step);
|
||||
const wrap = h("div", { class: "session-export" });
|
||||
const evidence = effectiveSessionExport(step);
|
||||
const complete = evidence?.status === "complete" && evidence.messages>0 && evidence.html_bytes>0 && file && !evidence.truncated && !evidence.diagnostic;
|
||||
const recovery = step?.session_export_recovery;
|
||||
if (recovery) wrap.append(h("div", { class: "muted", text: `Automatic export recovery: ${recovery.status} · ${recovery.attempts}/3 attempts. ${recovery.diagnostic || ""}` }));
|
||||
if (recovery && !complete) wrap.append(h("div", { class: "muted", text: `Automatic export recovery: ${recovery.status} · ${recovery.attempts}/3 attempts. ${recovery.diagnostic || ""}` }));
|
||||
for (const repair of step?.session_export_repairs || []) {
|
||||
const row = h("div", { class: "session-export-repair" });
|
||||
row.append(h("span", { text: `Repair: ${repair.status || "partial"} · ${repair.messages || 0} messages. ${repair.diagnostic || ""}` }));
|
||||
const repaired = sessionExportArtifact({ ...step, session_export: repair });
|
||||
const repaired = sessionExportArtifact({ ...step, session_export: repair, session_export_repairs: [] });
|
||||
const repairedHref = repaired && resolvedArtifactUrl(repaired, state.url);
|
||||
if (repairedHref) row.append(h("a", { ...artifactBrowserLinkProps(repairedHref), text: "Open repaired export" }));
|
||||
wrap.append(row);
|
||||
}
|
||||
const evidence = step?.session_export;
|
||||
const incomplete = evidence && (evidence.status && evidence.status !== "complete" || !evidence.messages || evidence.truncated || evidence.diagnostic);
|
||||
if (incomplete) {
|
||||
wrap.append(h("span", { class: "muted", text: `Session recorded, but export ${evidence.status || (!evidence.messages ? "empty" : "partial")}. Full session evidence was not captured.${evidence.diagnostic ? ` ${evidence.diagnostic}` : ""}` }));
|
||||
}
|
||||
if (!file) {
|
||||
if (!incomplete) wrap.append(h("span", { class: "muted", text: step?.session_id ? "Session recorded, but export failed or was not captured." : "No session was exported for this visit." }));
|
||||
wrap.append(h("span", { class: "muted", text: sessionCaptureState(step).message }));
|
||||
return wrap;
|
||||
}
|
||||
const href = resolvedArtifactUrl(file, state.url);
|
||||
|
||||
Reference in New Issue
Block a user