feat(panel): add step anomaly diagnostics, >=100 tok/s integer speed formatting, and capsule alignment fix

This commit is contained in:
fish
2026-11-19 22:28:39 +09:00
parent dfba5ead7b
commit 4a4e483209
20 changed files with 3546 additions and 143 deletions
+98 -13
View File
@@ -914,6 +914,84 @@ function decodeProtoContextWindowMetaSlice(buf, state, end, includeBreakdown) {
};
}
function decodeProtoRetryInfoSlice(buf, state, end) {
const ri = {};
while (state.off < end) {
const rTag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, end)));
const rFn = rTag >>> 3;
const rWt = rTag & 7;
if (rFn === 2 && rWt === 2) {
ri.usage = decodeProtoModelUsageSlice(buf, state, readSubEnd(buf, state, end));
} else if (rFn === 3 && rWt === 2) {
const errStr = readProtoString(buf, state, end).trim();
if (errStr) {
ri.error = errStr.length > 320 ? `${errStr.slice(0, 319)}…` : errStr;
}
} else if (rFn === 5 && rWt === 0) {
const code = Number(BigInt.asUintN(32, readProtoVarint(buf, state, end)));
if (code > 0) ri.reasonCode = code;
} else if (rFn === 7 && rWt === 2) {
const dur = decodeProtoDurationSlice(buf, state, readSubEnd(buf, state, end));
if (dur) ri.retryDelay = dur;
} else {
skipProtoField(buf, state, rWt, end);
}
}
state.off = end;
return ri;
}
function decodeProtoErrorMessageSlice(buf, state, end) {
let userErrorMessage = '';
let shortError = '';
let errorCode = 0;
let shouldShowModel = false;
let shouldShowUser = false;
while (state.off < end) {
const tag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, end)));
const fn = tag >>> 3;
const wt = tag & 7;
if (fn === 3 && wt === 2) {
const eEnd = readSubEnd(buf, state, end);
while (state.off < eEnd) {
const eTag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, eEnd)));
const eFn = eTag >>> 3;
const eWt = eTag & 7;
if (eFn === 1 && eWt === 2) {
const s = readProtoString(buf, state, eEnd).trim();
if (s) userErrorMessage = s.length > 240 ? `${s.slice(0, 239)}…` : s;
} else if (eFn === 2 && eWt === 2) {
const s = readProtoString(buf, state, eEnd).trim();
if (s) shortError = s.length > 320 ? `${s.slice(0, 319)}…` : s;
} else if (eFn === 7 && eWt === 0) {
errorCode = Number(BigInt.asUintN(32, readProtoVarint(buf, state, eEnd)));
} else {
skipProtoField(buf, state, eWt, eEnd);
}
}
state.off = eEnd;
} else if (fn === 4 && wt === 0) {
shouldShowModel = readProtoVarint(buf, state, end) !== 0n;
} else if (fn === 5 && wt === 0) {
shouldShowUser = readProtoVarint(buf, state, end) !== 0n;
} else {
skipProtoField(buf, state, wt, end);
}
}
state.off = end;
if (!userErrorMessage && !shortError && !errorCode) return null;
return {
error: {
...(userErrorMessage ? { userErrorMessage } : {}),
...(shortError ? { shortError } : {}),
...(errorCode > 0 ? { errorCode } : {}),
},
...(shouldShowModel ? { shouldShowModel: true } : {}),
...(shouldShowUser ? { shouldShowUser: true } : {}),
};
}
function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
let model = '';
let usage = null;
@@ -922,6 +1000,8 @@ function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
let streamingDuration = '';
let responseModel = '';
let modelDisplayName = '';
let retryCount = 0;
let retryInfos = null;
const extraMeta = {};
let messagePrompts = null;
let tools = null;
@@ -1004,6 +1084,8 @@ function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
timeToFirstToken = decodeProtoDurationSlice(buf, state, readSubEnd(buf, state, end));
} else if (fn === 12 && wt === 2) {
streamingDuration = decodeProtoDurationSlice(buf, state, readSubEnd(buf, state, end));
} else if (fn === 14 && wt === 0) {
retryCount = Number(BigInt.asUintN(32, readProtoVarint(buf, state, end)));
} else if (fn === 16 && wt === 2) {
if (includeBreakdown) {
const psEnd = readSubEnd(buf, state, end);
@@ -1030,6 +1112,10 @@ function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
} else {
skipProtoField(buf, state, wt, end);
}
} else if (fn === 17 && wt === 2) {
const ri = decodeProtoRetryInfoSlice(buf, state, readSubEnd(buf, state, end));
if (!retryInfos) retryInfos = [];
retryInfos.push(ri);
} else if (fn === 19 && wt === 2) {
responseModel = readProtoString(buf, state, end).trim();
} else if (fn === 20 && wt === 2) {
@@ -1056,6 +1142,8 @@ function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
usage.apiProvider = 'API_PROVIDER_ANTHROPIC';
}
const hasRetryEvidence =
retryCount > 0 || Boolean(retryInfos && retryInfos.some((r) => r?.error || r?.reasonCode));
return {
chatModel: {
...(model ? { model } : {}),
@@ -1065,6 +1153,8 @@ function decodeProtoChatModelMetaSlice(buf, state, end, includeBreakdown) {
: {}),
...(timeToFirstToken ? { timeToFirstToken } : {}),
...(streamingDuration ? { streamingDuration } : {}),
...(retryCount > 0 ? { retryCount } : {}),
...(hasRetryEvidence && retryInfos ? { retryInfos } : {}),
...(responseModel ? { responseModel } : {}),
...(modelDisplayName ? { modelDisplayName } : {}),
...(messagePrompts ? { messagePrompts } : {}),
@@ -1233,19 +1323,7 @@ function decodeProtoStepMeta(rawBlob, fallbackIdx) {
}
state.off = siEnd;
} else if (fn === 28 && wt === 2) {
const riEnd = readSubEnd(buf, state, end);
const ri = {};
while (state.off < riEnd) {
const rTag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, riEnd)));
const rFn = rTag >>> 3;
const rWt = rTag & 7;
if (rFn === 2 && rWt === 2) {
ri.usage = decodeProtoModelUsageSlice(buf, state, readSubEnd(buf, state, riEnd));
} else {
skipProtoField(buf, state, rWt, riEnd);
}
}
state.off = riEnd;
const ri = decodeProtoRetryInfoSlice(buf, state, readSubEnd(buf, state, end));
if (!retryInfos) retryInfos = [];
retryInfos.push(ri);
} else if (fn === 30 && wt === 2) {
@@ -1501,6 +1579,9 @@ function decodeProtoSelectiveStepPayload(
readSubEnd(buf, state, end),
keepFullText
);
} else if (fn === 24 && wt === 2 && stepTypeNum === 17) {
const em = decodeProtoErrorMessageSlice(buf, state, readSubEnd(buf, state, end));
if (em) out.errorMessage = em;
} else if (fn === 114 && wt === 2 && stepTypeNum === 101 && includeSystemMessage) {
const sysMsg = decodeProtoSystemMessageSlice(buf, state, readSubEnd(buf, state, end));
if (sysMsg) out.systemMessage = { message: sysMsg };
@@ -1786,6 +1867,7 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
if (
rec.stepTypeNum === 14 ||
rec.stepTypeNum === 15 ||
rec.stepTypeNum === 17 ||
(isChildTrajectory && rec.stepTypeNum === 101) ||
isInvSub ||
(inRunningTail && (rec.stepTypeNum !== 132 || !rec.metadata?.toolCall?.argumentsJson))
@@ -1868,6 +1950,9 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
if (decodedPayload.plannerResponse) {
stepObj.plannerResponse = decodedPayload.plannerResponse;
}
if (decodedPayload.errorMessage) {
stepObj.errorMessage = decodedPayload.errorMessage;
}
if (decodedPayload.invokeSubagent) {
stepObj.invokeSubagent = decodedPayload.invokeSubagent;
}