LibreChat/packages/api/src/code
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
..
fixtures 🕹️ feat: Run Declared Project Actions on Attached Workers (#15943) 2026-09-14 18:35:33 -04:00
bridge.spec.ts ⛓️ fix: Bind Programmatic Bash to Selected Workspaces (#15992) 2026-09-16 07:46:16 -04:00
bridge.ts 📖 Load Repository Instructions for Attached Workspaces (#16008) 2026-09-16 09:00:35 -04:00
capabilities.spec.ts ⛓️ fix: Bind Programmatic Bash to Selected Workspaces (#15992) 2026-09-16 07:46:16 -04:00
capabilities.ts 📖 Load Repository Instructions for Attached Workspaces (#16008) 2026-09-16 09:00:35 -04:00
command.spec.ts 🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060) 2026-09-19 09:03:06 -04:00
command.ts 🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060) 2026-09-19 09:03:06 -04:00
config.spec.ts 🚛 fix: Move Sealed Chats to New Code Environments (#15902) 2026-09-14 00:58:08 -04:00
config.ts 🚛 fix: Move Sealed Chats to New Code Environments (#15902) 2026-09-14 00:58:08 -04:00
decision.spec.ts 🎱 fix: Stop Sealing a Code Environment Decision a Chat Never Made (#16056) 2026-09-19 13:13:24 -04:00
decision.ts 🎱 fix: Stop Sealing a Code Environment Decision a Chat Never Made (#16056) 2026-09-19 13:13:24 -04:00
enrollment.spec.ts 🛂 feat: Add Configurable BYOM Enrollment Policy (#15673) 2026-09-06 15:04:43 -04:00
enrollment.ts 🛂 feat: Add Configurable BYOM Enrollment Policy (#15673) 2026-09-06 15:04:43 -04:00
environment.live.spec.ts 🕹️ feat: Run Declared Project Actions on Attached Workers (#15943) 2026-09-14 18:35:33 -04:00
environments.integration.spec.ts 🛂 feat: Add Configurable BYOM Enrollment Policy (#15673) 2026-09-06 15:04:43 -04:00
environments.ts 🕹️ feat: Configure BYOM Tool Permissions (#15504) 2026-09-02 10:38:00 -04:00
errors.spec.ts 🖋️ feat: Seal Code Environment Choices Per Conversation (#15868) 2026-09-12 20:45:00 -04:00
errors.ts 🖋️ feat: Seal Code Environment Choices Per Conversation (#15868) 2026-09-12 20:45:00 -04:00
http.spec.ts 🚛 fix: Move Sealed Chats to New Code Environments (#15902) 2026-09-14 00:58:08 -04:00
http.ts 🚛 fix: Move Sealed Chats to New Code Environments (#15902) 2026-09-14 00:58:08 -04:00
index.ts 📖 Load Repository Instructions for Attached Workspaces (#16008) 2026-09-16 09:00:35 -04:00
instructions.spec.ts 📖 Load Repository Instructions for Attached Workspaces (#16008) 2026-09-16 09:00:35 -04:00
instructions.ts 📖 Load Repository Instructions for Attached Workspaces (#16008) 2026-09-16 09:00:35 -04:00
lifecycle.spec.ts 🧮 fix: Scale Code Environment Reconciliation (#15625) 2026-09-04 22:27:39 -04:00
lifecycle.ts 🧮 fix: Scale Code Environment Reconciliation (#15625) 2026-09-04 22:27:39 -04:00
remoteWorkspace.spec.ts 🖋️ feat: Seal Code Environment Choices Per Conversation (#15868) 2026-09-12 20:45:00 -04:00
settings.spec.ts 🕹️ feat: Configure BYOM Tool Permissions (#15504) 2026-09-02 10:38:00 -04:00
settings.ts 🕹️ feat: Configure BYOM Tool Permissions (#15504) 2026-09-02 10:38:00 -04:00
workspace.spec.ts 🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060) 2026-09-19 09:03:06 -04:00
workspace.ts 🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060) 2026-09-19 09:03:06 -04:00