fix(liveWatcher): ensure idempotency on cancelRequest and detailed error reporting

This commit is contained in:
tyuXX 2026-11-04 20:33:13 +00:00
parent f558ef4c88
commit 680c080c78
2 changed files with 6 additions and 3 deletions

View file

@ -391,7 +391,7 @@ export class LiveWatcher {
}): void { }): void {
if (!this.isWatcherActive) return; if (!this.isWatcherActive) return;
const entry = this.buffer.find(e => e.id === params.requestId); const entry = this.buffer.find(e => e.id === params.requestId);
if (!entry) return; if (!entry || (entry.endTime !== undefined && entry.status === 'completed')) return;
entry.endTime = Date.now(); entry.endTime = Date.now();
entry.durationMs = entry.endTime - entry.startTime; entry.durationMs = entry.endTime - entry.startTime;
@ -426,7 +426,7 @@ export class LiveWatcher {
public cancelRequest(requestId: string): void { public cancelRequest(requestId: string): void {
if (!this.isWatcherActive) return; if (!this.isWatcherActive) return;
const entry = this.buffer.find(e => e.id === requestId); const entry = this.buffer.find(e => e.id === requestId);
if (!entry) return; if (!entry || entry.endTime !== undefined) return;
entry.endTime = Date.now(); entry.endTime = Date.now();
entry.durationMs = entry.endTime - entry.startTime; entry.durationMs = entry.endTime - entry.startTime;

View file

@ -627,7 +627,9 @@ export class RevolverEngine {
// If we reached here, all tiers and all candidates failed // If we reached here, all tiers and all candidates failed
cleanupTimers(); cleanupTimers();
if (onFailure) onFailure('all_tiers_exhausted'); if (onFailure) onFailure('all_tiers_exhausted');
const finalErrorMessage = lastError ? lastError.message : 'All model tiers and provider keys are exhausted or rate-limited.'; const finalErrorMessage = lastError?.cause?.message
? `${lastError.message}: ${lastError.cause.message}`
: (lastError ? lastError.message : 'All model tiers and provider keys are exhausted or rate-limited.');
const journey: RequestFallbackJourney = { const journey: RequestFallbackJourney = {
requestId, requestId,
@ -673,6 +675,7 @@ export class RevolverEngine {
})); }));
res.end(); res.end();
} else { } else {
res.setHeader('Cache-Control', 'no-cache, no-transform');
res.status(503).json({ res.status(503).json({
error: { error: {
message: `[Revolver Fallback Error]: ${finalErrorMessage}`, message: `[Revolver Fallback Error]: ${finalErrorMessage}`,