LibreChat/api/server/controllers/agents
Danny Avila 11210d8b98
🏁 fix: Message Race Condition if Cancelled Early (#11462)
* 🔧 fix: Prevent race conditions in message saving during abort scenarios

* Added logic to save partial responses before returning from the abort endpoint to ensure parentMessageId exists in the database.
* Updated the ResumableAgentController to save response messages before emitting final events, preventing orphaned parentMessageIds.
* Enhanced handling of unfinished responses to improve stability and data integrity in agent interactions.

* 🔧 fix: logging and job replacement handling in ResumableAgentController

* Added detailed logging for job creation and final event emissions to improve traceability.
* Implemented logic to check for job replacement before emitting events, preventing stale requests from affecting newer jobs.
* Updated abort handling to log additional context about the abort result, enhancing debugging capabilities.

* refactor: abort handling and token spending logic in AgentStream

* Added authorization check for abort attempts to prevent unauthorized access.
* Improved response message saving logic to ensure valid message IDs are stored.
* Implemented token spending for aborted requests to prevent double-spending across parallel agents.
* Enhanced logging for better traceability of token spending operations during abort scenarios.

* refactor: remove TODO comments for token spending in abort handling

* Removed outdated TODO comments regarding token spending for aborted requests in the abort endpoint.
* This change streamlines the code and clarifies the current implementation status.

*  test: Add comprehensive tests for job replacement and abort handling

* Introduced unit tests for job replacement detection in ResumableAgentController, covering job creation timestamp tracking, stale job detection, and response message saving order.
* Added tests for the agent abort endpoint, ensuring proper authorization checks, early abort handling, and partial response saving.
* Enhanced logging and error handling in tests to improve traceability and robustness of the abort functionality.
2026-01-21 13:57:12 -05:00
..
__tests__ 🏁 fix: Message Race Condition if Cancelled Early (#11462) 2026-01-21 13:57:12 -05:00
callbacks.js 🏞️ fix: Gemini Image Filenames and Add Tool Cache Safety (#11306) 2026-01-12 09:01:23 -05:00
client.js 💰 fix: Multi-Agent Token Spending & Prevent Double-Spend (#11433) 2026-01-20 14:43:19 -05:00
client.test.js 💰 fix: Multi-Agent Token Spending & Prevent Double-Spend (#11433) 2026-01-20 14:43:19 -05:00
errors.js 🛜 refactor: Streamline App Config Usage (#9234) 2025-08-26 12:10:18 -04:00
recordCollectedUsage.spec.js 🪙 refactor: Collected Usage & Anthropic Prompt Caching (#11319) 2026-01-12 23:02:08 -05:00
request.js 🏁 fix: Message Race Condition if Cancelled Early (#11462) 2026-01-21 13:57:12 -05:00
v1.js 🌅 fix: Agent Avatar S3 URL Refresh Pagination and Persistence (#11323) 2026-01-13 13:01:11 -05:00
v1.spec.js 🌅 fix: Agent Avatar S3 URL Refresh Pagination and Persistence (#11323) 2026-01-13 13:01:11 -05:00