LibreChat/packages/api
Danny Avila 6e00a9743a
⏭️ fix: Let Queued User Turns Go Before Completion Wake-ups at Run End (#18027)
* fix: Let Queued User Turns Go Before Completion Wake-ups at Run End

When a run ends with both a server-owned queued user turn and a background
or subagent completion wake-up waiting on it, the wake-up was expedited at
generation settlement while the queued turn sat out its five-second
readiness re-check, so the wake-up claimed the predecessor fence first and
the user's turn waited behind a whole automated turn.

- Generation settlement now also expedites the conversation's queued-turn
  deliveries.
- Background and subagent wake-ups defer without consuming an attempt while
  a queued turn holds an unexpired claim or is the due lane head, then run
  after it, chained to its response.
- hasPendingAgentQueuedTurn answers false for rows that need recovery or a
  user decision (reservations, expired claims, indeterminate admissions,
  dead heads awaiting dismissal), so a stuck queued turn never holds a
  wake-up. The read runs in parallel with the existing conversation read
  and fails open.
- Readiness deferral logs now carry the execution error code.

* fix: Read Queued-Turn Precedence in Claim Order and Defer on Unknown State

- Read the live claim after the head read settles, so a queued -> claimed
  transition between the two reads cannot answer false.
- Take plain identifiers in hasPendingAgentQueuedTurn and convert the user
  id inside data-schemas, keeping Mongoose types out of packages/api.
- A failed precedence read now defers the wake-up without consuming an
  attempt (QUEUED_TURN_STATE_UNAVAILABLE) instead of proceeding.

* fix: Read the Active Queued-Turn Lane in One Query

A claim released back to `queued` between the head read and the live-claim
read could still answer false. Read the reserving, queued and claimed rows
in one query over the capacity index, whose `activeSlot` key holds steady
from reservation until a terminal state, so each row is seen exactly once
in one state. Dead heads and indeterminate quarantines stay separate
indexed reads in parallel. Falls back to a planner-chosen read when the
capacity index has not been built yet.

* fix: Fall Back to a Planner Read Whenever the Lane Hint Is Refused

A hint can be refused for reasons other than a missing index on some engines. The hinted read only pins the stable key, so any refusal now retries unhinted; a genuine outage fails that read too and defers the wake-up.

* fix: Read Queued-Turn Blockers After the Turn They Block

The precedence read gathered the active lane, the dead lane head and the
indeterminate quarantine in parallel, so a blocker could be older than the
queued turn it blocked. A dead head dismissed while the reads were in flight
still answered false and let a completion wake-up race the successor it had
just unblocked.

Read the active lane first, and the blockers (a reservation, an expired
claim, an indeterminate admission, a dead row ahead of the head) only
afterwards and only for a due head, in one existence query. A blocker that
has already cleared no longer answers false, and a conversation with no due
queued turn now costs one read instead of three.
2026-11-10 14:56:41 -05:00
..
openapi ⬆️ feat: Migrate to Zod v4 (#17442) 2026-10-26 14:16:22 +01:00
src ⏭️ fix: Let Queued User Turns Go Before Completion Wake-ups at Run End (#18027) 2026-11-10 14:56:41 -05:00
types
.gitignore
babel.config.cjs
jest.config.mjs 🦿 chore: Bump Agents SDK to 4.2.1 (#17664) 2026-10-31 15:17:05 -04:00
jest.setup.cjs
package.json 🖨️ fix: Preserve Concurrent PDF Extraction (#18008) 2026-11-10 12:21:34 -05:00
tsconfig.build.json
tsconfig.json 🚸 fix: Align Image Authorization and Static Serving Paths (#17392) 2026-10-24 09:18:19 +02:00
tsconfig.openapi.json
tsconfig.spec.json
tsdown.config.mjs 🦦 fix: Bound Spreadsheet Text Extraction (#17824) 2026-11-09 08:27:47 -05:00