LibreChat/api/server/controllers/agents/__tests__
Danny Avila b34bbd83ef fix: lease-token lifecycle fences — same-generation isolation, admission fence, undelivered-Stop retention, legacy abort enrollment
Fifth external review round; four P1s, handled as the requested consolidated
lifecycle-fence pass.

- Lease tokens. Marker fields were (streamId, createdAt), shared by every
  contender on the same generation — completion and Stop, or two racing Stops —
  so a losing contender's cleanup erased the winner's still-live marker. Every
  registrant now carries a unique lease token in the field and may only ever
  clear its own lease; unqualified legacy clears cannot touch qualified entries.

- Admission fence. Authentication can pass before the deletion barrier goes up,
  and the durable createJob is several async steps later — a deletion quiesce in
  that window saw neither an active job nor a marker and could cascade before
  the admitted request created its job. The controller now registers an
  admission lease and THEN rereads the deletion barrier: the ordering guarantees
  either this request observes the barrier (403, lease released, slot/claim
  cleanup) or the quiesce observes the lease and defers. Held until createJob is
  durable; released on every refusal and initialization-error path. Fail closed
  when the lease itself cannot be registered (503 retryable).

- Undelivered-Stop retention. abortJob released its lease in a finally even when
  delivery AND publication had provably failed — the job reads terminal
  (invisible to active-set scans), a user Stop writes no durable abort fence,
  and the remote owner keeps generating and will persist its abort-catch writes
  whenever the signal finally lands. The lease is now retained in exactly that
  case, and each resignal attempt heartbeats a fresh lease so the fence outlives
  the TTL for as long as delivery is still being driven. The abort-winning
  turn's own loser-side pending saves are additionally fenced in the controller
  catch (best-effort — those writes are already in flight).

- Legacy abort enrollment. abortMiddleware (assistants abort route fallback for
  non-assistants endpoints) awaited abortJob and then spent usage and saved the
  stopped response AFTER the abort's lease was released. Both writes now run
  inside `beforePublish`, between the abort CAS and publication, covered by the
  same lease as every other abort.

Barrier tests, each verified to fail without its fix: same-generation lease
isolation (store), racing two-Stop loser cleanup (manager, stale-read forced
CAS race), undelivered-Stop lease retention, resignal heartbeat, admission
refusal with lease-before-reread ordering plus release-on-durable-create, and
legacy-abort persistence inside beforePublish.
2026-08-18 07:46:18 -04:00
..
askUserQuestion.e2e.spec.js feat: Scheduled Chats — agent-centric scheduled runs creating real conversations 2026-08-18 07:46:18 -04:00
callbacks.spec.js 🛤️ feat: Per-Agent Code Execution Routing With Stateful Session Scopes (#14848) 2026-08-16 09:42:15 -04:00
client.contextMetadata.spec.js 🪙 fix: Correct Context Usage Gauge After Summarization (#13744) 2026-06-14 18:23:30 -04:00
client.memory.spec.js 🧰 refactor: Unify code-execution tools (#12767) 2026-04-25 04:02:01 -04:00
client.steerWiring.spec.js 🛑 feat: Preemptive Steer - Backend Interrupt & Steer (#14518) 2026-07-30 12:36:13 -04:00
client.subagentUsage.spec.js 🧵 feat: Persist View-Only Subagent Threads (#14957) 2026-08-18 07:41:42 -04:00
client.transactions.spec.js 🧾 fix: Honor Disabled Transactions on the Token-Count Fallback Path (#14774) 2026-08-12 22:31:13 -04:00
hitlCheckpoint.e2e.spec.js feat: Scheduled Chats — agent-centric scheduled runs creating real conversations 2026-08-18 07:46:18 -04:00
jobReplacement.spec.js fix: lease-token lifecycle fences — same-generation isolation, admission fence, undelivered-Stop retention, legacy abort enrollment 2026-08-18 07:46:18 -04:00
modelEndHandler.spec.js 💸 feat: Per-Agent Endpoint Token Config in Multi-Endpoint Billing (#13738) 2026-06-14 12:00:32 -04:00
openai.spec.js 🕸️ feat: Run Saved Agent Teams as Subagents (#14944) 2026-08-17 18:02:52 -04:00
protocol.spec.js ⚡ feat: Reliable Interrupt & Steer Escalation and Recovery (#14558) 2026-07-31 20:07:56 -04:00
request.partialDisconnect.spec.js fix: lease-token lifecycle fences — same-generation isolation, admission fence, undelivered-Stop retention, legacy abort enrollment 2026-08-18 07:46:18 -04:00
request.resumeMetadata.spec.js fix: lease-token lifecycle fences — same-generation isolation, admission fence, undelivered-Stop retention, legacy abort enrollment 2026-08-18 07:46:18 -04:00
responses.unit.spec.js 🧵 feat: Persist View-Only Subagent Threads (#14957) 2026-08-18 07:41:42 -04:00
resume.spec.js fix: lease-token lifecycle fences — same-generation isolation, admission fence, undelivered-Stop retention, legacy abort enrollment 2026-08-18 07:46:18 -04:00
steer.spec.js 🛰️ feat: Execute Generic Agent Trigger Deliveries (#14921) 2026-08-17 08:45:49 -04:00
usageEvents.integration.spec.js 🪙 refactor: Reconcile Context Gauge to Actual Provider Tokens (#13780) 2026-06-16 11:05:44 -04:00
usageEvents.live.spec.js 📊 feat: Real-Time Context Window & Token Usage Tracking (#13670) 2026-06-13 19:38:28 -04:00
v1.duplicate-actions.spec.js
v1.spec.js 🕸️ feat: Run Saved Agent Teams as Subagents (#14944) 2026-08-17 18:02:52 -04:00