* 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>
* ⏳ fix: Keep BYOM tools queued across capacity windows
* ⏳ fix: Configure the admission budget and refresh queued credentials
Addresses the Codex review on #16060:
- Add `limits.maxQueueWaitMs` to the code environment config schema so a
deployment can shorten or disable the five-minute admission budget from
`librechat.yaml`; omission keeps the merged behavior, `0` surfaces the
first capacity expiry to the model. Resolved through
`resolveAttachedWorkspaceQueueWaitMs` and passed by ToolService, matching
how `maxCommandTimeoutMs` already flows.
- Accept an auth-header supplier in `executeWorkspaceTool` and mint it per
admission attempt, so a call queued past the Code API token TTL presents
fresh credentials instead of failing permanently with 401. The attached
Bash tool and the workspace file operations now pass suppliers.
- Recheck the deadline after a clamped wait and throw the saved rejection
rather than opening an admission window that could still be admitted
once the budget is spent.
* fix: Complete workspace admission wiring and caller regressions
* fix: Share protected edit retry budgets and schema limits
---------
Co-authored-by: Lia <lia@librechat.ai>
* fix: Enable programmatic Bash in selected attached workspaces
* Centralize project PTC construction and preserve recognized capabilities
* Prevent stale list refreshes from restoring removed pins
* 🧭 fix: Let a Sealed Chat Follow Its Agent to a New Machine
A conversation's code-environment decision is sealed on its first turn, but the
environment an agent uses stays editable. Pointing an agent at a different
attached machine left every chat sealed to the old one with no valid move: the
client showed an unusable workspace chooser, and any other selection was
rejected by the server as locked. Forking copied the stale seal.
The owner can now move such a chat explicitly. The composer names the machine
the chat used and the one its agent uses now, and moving it goes through an
owner-scoped endpoint that compare-and-swaps the persisted decision after
validating the new workspace against the live worker. A move never switches the
workspace of an environment the decision already covers, never upgrades a chat
that continues without an attached environment, and is refused while a
generation is in flight.
A saved chat also no longer auto-selects a sole workspace for an environment its
decision never covered, which submitted a selection the server always rejected.
* fix: Hold Moves Through Terminal Saves and Move Every Target at Once
A terminal claim marks a generation complete before its response save lands,
and that save still writes the decision the run started with, so a move is now
refused until terminalPersistencePending clears.
The API advertises codeEnvironmentMoveVersion, and the client offers a move only
when it is present, so a new client never exposes an endpoint an older API lacks.
The move menu picks one workspace per new environment, with a sole workspace
preselected, and a single confirm sends the complete target set in one request,
so a partial move can no longer leave a half-migrated decision. A new machine
that advertises no workspace shows its unavailable state instead of an empty
section, and the confirm stays disabled.
* fix: Keep Runs From Rewriting Moved Decisions and Gate Moves by Policy
Every agent turn used to persist the decision it started with, so a run from any
ingress that settled after a move could write the old decision back: the chat
controller reads the conversation before its generation job exists, and
Responses API runs never enroll one. Runs now persist a decision only for a
conversation that does not store one yet, and a legacy row records only the mode
it inferred, so no admission or persistence order can revert a move.
Moves are now an operator setting, statefulCodeSessions.conversationMoves.enabled,
off by default. The API advertises codeEnvironmentMoveVersion and accepts moves
only where the effective policy enables them.
A saved chat carrying attached selections no longer auto-selects a sole workspace
even when selection-less decisions are not advertised, because the server seals
those selections either way.
* fix: Fence Moves Across Remote Runs and Let Moves Drop Unused Machines
A Responses API run is keyed by its response id, so the conversation stream
alone could not show it still working on a chat. A move is now refused while any
generation that can still act for the conversation exists, using the same
conversation-scoped enumeration conversation deletion drains.
A move now validates every workspace it persists, not only the added ones, so a
successful move never hands back a decision whose kept workspace is gone.
A chat sealed to machines its agents no longer all use could not be sent or
moved: the client trimmed the unused selection and the server rejected the
trimmed set as locked. A saved chat now treats that seal as unresolvable, offers
a move that drops the unused machine, and the server accepts drop-only moves.
* fix: Own the Decision Fallback in TypeScript and Settle Move Caches
The fields a run may persist when it never resolved a decision were chosen by a
branch in AgentClient; resolvePersistableCodeEnvironmentDecision now owns that
fallback too, under the same never-overwrite rule, and the CJS method only wires
the request into it.
Workspace choices made in the move menu belong to the chat they were made in, so
another relocatable chat targeting the same machine starts undecided.
A successful move cancels conversation, pinned, and list reads already in flight
before writing the moved decision, so a response from before the move cannot
restore the replaced decision in the cache.
* Trace BYOM command cancellation at the HTTP boundary
* 🧹 chore: Sort Command Module Imports
The Static Checks job fails on this branch at the "Import sorting" step:
`node scripts/sort-imports.mts --check` reports
`packages/api/src/code/command.ts` as out of order.
The `logger` import added for the BYOM command diagnostics was placed after
`import { tool } from '@librechat/agents/langchain/tools'`, but package
imports sort shortest to longest line, and the data-schemas import is the
shorter of the two. Reordered by running the repo's own sorter, which is
also what the pre-commit lint-staged hook applies.