fix(workbench): stop projection resume after terminal trace (#2018)
This commit is contained in:
@@ -1376,7 +1376,8 @@ async function runAgentRunProjectionResumePass({ options = {}, traceStore = defa
|
|||||||
try {
|
try {
|
||||||
const result = await resumeAgentRunProjectionCandidate({ candidate, options, traceStore });
|
const result = await resumeAgentRunProjectionCandidate({ candidate, options, traceStore });
|
||||||
resumed += 1;
|
resumed += 1;
|
||||||
if (agentRunProjectionObservedTerminal(result, result?.runnerTrace ?? traceStore?.snapshot?.(candidate.traceId))) {
|
const currentTraceSnapshot = safeTraceStoreSnapshot(traceStore, candidate.traceId);
|
||||||
|
if (agentRunProjectionObservedTerminal(result, result?.runnerTrace ?? currentTraceSnapshot) || traceSnapshotIsTerminal(currentTraceSnapshot)) {
|
||||||
terminal += 1;
|
terminal += 1;
|
||||||
candidateRetryState.delete(retryKey);
|
candidateRetryState.delete(retryKey);
|
||||||
} else {
|
} else {
|
||||||
@@ -1653,6 +1654,7 @@ function projectionResumeCandidateRetryDelayMs(retryAttempt, initialDelayMs, max
|
|||||||
function appendProjectionResumeError(traceStore, candidate, error, retry = {}) {
|
function appendProjectionResumeError(traceStore, candidate, error, retry = {}) {
|
||||||
const traceId = safeTraceId(candidate?.traceId);
|
const traceId = safeTraceId(candidate?.traceId);
|
||||||
if (!traceId) return;
|
if (!traceId) return;
|
||||||
|
if (traceSnapshotIsTerminal(safeTraceStoreSnapshot(traceStore, traceId))) return;
|
||||||
traceStore.append(traceId, {
|
traceStore.append(traceId, {
|
||||||
type: "turn-status",
|
type: "turn-status",
|
||||||
status: "degraded",
|
status: "degraded",
|
||||||
@@ -1676,6 +1678,7 @@ function appendProjectionResumeError(traceStore, candidate, error, retry = {}) {
|
|||||||
function appendProjectionResumeRetry(traceStore, candidate, retry = {}) {
|
function appendProjectionResumeRetry(traceStore, candidate, retry = {}) {
|
||||||
const traceId = safeTraceId(candidate?.traceId);
|
const traceId = safeTraceId(candidate?.traceId);
|
||||||
if (!traceId) return;
|
if (!traceId) return;
|
||||||
|
if (traceSnapshotIsTerminal(safeTraceStoreSnapshot(traceStore, traceId))) return;
|
||||||
traceStore.append(traceId, {
|
traceStore.append(traceId, {
|
||||||
type: "turn-status",
|
type: "turn-status",
|
||||||
status: "degraded",
|
status: "degraded",
|
||||||
@@ -1697,6 +1700,23 @@ function appendProjectionResumeRetry(traceStore, candidate, retry = {}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeTraceStoreSnapshot(traceStore, traceId) {
|
||||||
|
try {
|
||||||
|
return typeof traceStore?.snapshot === "function" ? traceStore.snapshot(traceId) : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function traceSnapshotIsTerminal(snapshot) {
|
||||||
|
if (!snapshot || typeof snapshot !== "object") return false;
|
||||||
|
if (snapshot.finishedAt) return true;
|
||||||
|
if (isTraceCommandTerminalStatus(snapshot.status)) return true;
|
||||||
|
if (isTraceCommandTerminalStatus(snapshot.lastEvent?.status) || snapshot.lastEvent?.terminal === true) return true;
|
||||||
|
const events = Array.isArray(snapshot.events) ? snapshot.events : [];
|
||||||
|
return events.some((event) => event?.terminal === true || isTraceCommandTerminalStatus(event?.status));
|
||||||
|
}
|
||||||
|
|
||||||
function logAgentRunProjectionResume(logger, payload) {
|
function logAgentRunProjectionResume(logger, payload) {
|
||||||
try {
|
try {
|
||||||
const line = JSON.stringify(payload);
|
const line = JSON.stringify(payload);
|
||||||
|
|||||||
Reference in New Issue
Block a user