LibreChat/api/server
lia-by-librechat[bot] 1080f90bed
🎱 fix: Stop Sealing a Code Environment Decision a Chat Never Made (#16056)
* fix: Stop Sealing a Code Environment Decision a Chat Never Made

Switching an existing chat to a coding agent left the composer unable to
send. The chat had no workspace to select, Send stayed disabled, and the
workspace chip was a read-only status with a recovery hint.

Both layers treated "no decision recorded" as "decided to run without an
attached environment". `readPersistedDecision` documented that a stored
conversation always carries a decision and inferred `without_attached`
whenever `codeEnvironmentMode` and `codeWorkspaces` were both absent,
which is the ordinary state of a chat whose turns never involved a
code-capable agent. `resolveConversationCodeEnvironmentDecision` then
sealed that inference, so the first workspace its owner picked came back
as `locked`. The client mirrored the same premise: `locked` was any saved
chat, so `useCodeWorkspace` withheld agent defaults, a remembered
selection, and a sole workspace, and `CodeWorkspaceMenu` rendered its
non-interactive locked branch.

Only a recorded decision is sealed now. A conversation holding neither
field is undecided, so its first coding turn establishes the decision,
and `resolvePersistableCodeEnvironmentDecision` records that decision
with its selections; writing the mode alone would leave `attached`
without the selections the next turn validates. On the client the same
predicate drives `locked`, and the selection defaults that already
applied to a new chat now apply to any chat that has not decided.

An explicit `without_attached` stays sealed, a legacy row still infers
`attached` from the selections it stores, and a sealed decision is still
replaced only by its owner's move.

* fix: Record the first code environment decision on an existing chat

A saved chat that holds no decision may record the one a run establishes,
but every caller persists through `saveConvo`, which carries those fields
only in `$setOnInsert`. On a row that already exists the write was dropped,
so the choice never survived a reload and a later turn could resolve a
different workspace.

`saveConvo` now fills a whole decision onto a row that holds none, by
compare-and-set on that absence: a writer that decided first keeps its
decision, a chat that already holds one is untouched, and bare selections
never seed a row.

* fix: Record the decision a failed turn of a saved chat ran under

`saveErrorTurn` built its conversation fields only when it was seeding a new
row, so an existing chat kept the stored error turn without the decision that
turn ran under: a retry could then pick a different workspace than the failure
already recorded. The validated decision now travels on both branches, where
the conditional write in `saveConvo` keeps it from replacing a stored one.

* refactor: Resolve the error turn's decision fields in `packages/api`

The error-turn save derived its own decision fields, putting persistence
policy in a CJS controller where `/api` is meant to hold wiring only. It now
calls `resolvePersistableCodeEnvironmentDecision`, the resolver the streaming
saves already use, so one rule decides what a turn may record: a chat that
holds a decision keeps it and receives no decision fields at all.

* fix: Keep the legacy code environment lock until the protocol is advertised

The composer unlocked a saved chat that holds no decision without consulting
`codeEnvironmentDecisionVersion`, so during the rollout window it could attach
an agent default and submit it to a replica that still reads a field-less row
as a sealed `without_attached` and rejects the turn as `locked`.

The unlock now waits for the deployment to advertise the protocol, which makes
the hook identical to its previous behavior while the flag is unset. Nothing is
lost by waiting: the unmade decision is only reported once that flag is on.

---------

Co-authored-by: Lia <lia@librechat.ai>
2026-09-19 13:13:24 -04:00
..
controllers 🎱 fix: Stop Sealing a Code Environment Decision a Chat Never Made (#16056) 2026-09-19 13:13:24 -04:00
middleware 🗯️ fix: Give Failed Turns Actionable Guidance (#15896) 2026-09-14 10:37:22 -04:00
routes 🫗 fix: Roll Back Incomplete Skill Archive Imports (#16052) 2026-09-19 12:41:30 -04:00
services 🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060) 2026-09-19 09:03:06 -04:00
utils 🚄 perf: Linearize Conversation Import Lineage (#15881) 2026-09-13 03:48:22 -04:00
cleanup.js
csp.spec.js 🔌 fix: Close Leaked HTTP Server in Server Specs (#15821) 2026-09-10 15:17:06 -04:00
experimental.js 🔌 feat: OpenAPI spec and docs for the public Agents API (#15928) 2026-09-16 13:50:05 -04:00
experimental.spec.js 🛎️ fix: Start Code Environment Reconciliation After Mongo Connects (#15620) 2026-09-04 19:08:44 -04:00
index.js 🔌 feat: OpenAPI spec and docs for the public Agents API (#15928) 2026-09-16 13:50:05 -04:00
index.metrics.spec.js 🔌 fix: Close Leaked HTTP Server in Server Specs (#15821) 2026-09-10 15:17:06 -04:00
index.spec.js 🪧 fix: Emit the Configured-Footer Answer With the HTML Shell (#15886) 2026-09-13 21:53:54 -04:00
socialLogins.js 🔁 feat: Retry OpenID Discovery After Startup Failures (#15899) 2026-09-13 23:16:26 -04:00
socialLogins.spec.js 🔁 feat: Retry OpenID Discovery After Startup Failures (#15899) 2026-09-13 23:16:26 -04:00
telemetry.js 🪵 feat: Add OpenTelemetry Logs Pipeline via Winston Bridge (#15565) 2026-09-03 21:16:09 -04:00
telemetry.spec.js 🪵 feat: Add OpenTelemetry Logs Pipeline via Winston Bridge (#15565) 2026-09-03 21:16:09 -04:00