馃珎 fix: Keep Legacy Background Results Until Durable - #16405
Merged
Merged
Conversation
Contributor
Author
|
Review handoff for exact remote head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After #16365, a background completion admitted by an older producer can have an automatic delivery but no independent
persistResultwriter. Its parent-message projection is then the only durable result. Shutdown currently releases the task's handle when the tool finishes, before that projection commits; a flush can also count afalsereceipt as success. A non-cooperative tool can therefore lose its result while shutdown reports a clean drain. Separately, an unsuccessful write leaves an unconfirmed shutdown handle reachable even after the registry expires or evicts the task.Keep these pre-admitted tasks tracked until their projection is confirmed. When shutdown interrupts a still-running task without a receipt writer, project one terminal interruption through the existing result path. A late tool settlement cannot overwrite it. If neither a receipt nor a projection is confirmed, report the drain as unsettled rather than successful. Release and warn about unconfirmed handles when their task is evicted, so a run of failed writes cannot retain an unbounded set of dead tasks.
How it works
The original delivery identity, caller authorization, claim rules and configurable shutdown grace are unchanged. The one-result guard also prevents a tool that ignores its abort from rewriting a forced interruption later in the same process.
Type of change
Testing
Tested environments/configuration: Node 24, local Jest with the receipt-capable and legacy pre-admitted completion adapters; no external model or database required for the focused tests.
Automated tests:
handlers.shutdown.spec.ts: legacy projection pending through flush, failed projection, an uncooperative legacy task whose interruption is projected, failed interruption projection, and late success after the forced result. Existing receipt, fallback, code harvest, cancellation and admission cases remain covered.background.shutdown.spec.ts: task expiry and capacity-pressure eviction cannot leave an unconfirmed shutdown handle retained. Existing drain and ordering cases remain covered.background.shutdown.spec.ts,background.spec.ts,handlers.shutdown.spec.ts,handlers.background.spec.ts,triggers/service.delivery.spec.ts,app/shutdown.spec.ts.npx tsc --noEmitinpackages/api;npm run sort-imports -- <changed paths>andnpm run static-checks -- --against origin/dev.Screenshots / recordings
No new user-facing UI. The forced legacy result uses the existing shutdown interruption message.
Risk / compatibility
A poll-only task with no pre-admitted durable delivery remains process-local and cannot be recovered after restart. A non-cooperative external action can keep running after LibreChat exits; its forced interruption does not prove the external side effect did not happen. The existing shutdown deadline and grace continue to bound these attempts. There are no schema, configuration or API changes.
Checklist