fix(agents): add error handling to orphaned message cleanup (#2262)

This commit is contained in:
Episkey 2026-01-27 11:16:23 +08:00
parent dce7925e2a
commit 2d09f8e615
2 changed files with 19 additions and 10 deletions

View File

@ -56,6 +56,7 @@ Status: unreleased.
- **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed). - **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed).
### Fixes ### Fixes
- Agents: add error handling to orphaned message cleanup to prevent message processing queue from blocking. (#2262)
- Gateway: suppress AbortError and transient network errors in unhandled rejections. (#2451) Thanks @Glucksberg. - Gateway: suppress AbortError and transient network errors in unhandled rejections. (#2451) Thanks @Glucksberg.
- TTS: keep /tts status replies on text-only commands and avoid duplicate block-stream audio. (#2451) Thanks @Glucksberg. - TTS: keep /tts status replies on text-only commands and avoid duplicate block-stream audio. (#2451) Thanks @Glucksberg.
- Security: pin npm overrides to keep tar@7.5.4 for install toolchains. - Security: pin npm overrides to keep tar@7.5.4 for install toolchains.

View File

@ -713,6 +713,7 @@ export async function runEmbeddedAttempt(
}); });
// Repair orphaned trailing user messages so new prompts don't violate role ordering. // Repair orphaned trailing user messages so new prompts don't violate role ordering.
try {
const leafEntry = sessionManager.getLeafEntry(); const leafEntry = sessionManager.getLeafEntry();
if (leafEntry?.type === "message" && leafEntry.message.role === "user") { if (leafEntry?.type === "message" && leafEntry.message.role === "user") {
if (leafEntry.parentId) { if (leafEntry.parentId) {
@ -727,6 +728,13 @@ export async function runEmbeddedAttempt(
`runId=${params.runId} sessionId=${params.sessionId}`, `runId=${params.runId} sessionId=${params.sessionId}`,
); );
} }
} catch (err) {
log.error(
`Failed to repair orphaned user message, continuing anyway. ` +
`runId=${params.runId} sessionId=${params.sessionId}`,
{ error: err instanceof Error ? err.message : String(err) },
);
}
try { try {
// Detect and load images referenced in the prompt for vision-capable models. // Detect and load images referenced in the prompt for vision-capable models.