Repository navigation
🧪 feat: Add LIBRECHAT_CODE_DEFAULT_PROFILE to Run Chat Code on the Stateful Profile - #17182
Open
TomasPalsson wants to merge 24 commits into
Open
TomasPalsson wants to merge 24 commits into
TomasPalsson wants to merge 24 commits into
Conversation
…ult profile Agent code gates and subagent workspace inheritance treat an agent as stateful when the deployment's default profile is stateful, even if its saved flag is off or unset.
…he stateful default profile
The stateful default profile setting no longer opts an agent out of code in a no-workspace conversation unless stateful sessions are available and the agent's resolved environment is attached. Without the capability, or without a stateful route, the agent keeps code execution instead of silently losing it.
…n the setting is on A download that names no execution profile now resolves it from LIBRECHAT_CODE_DEFAULT_PROFILE, so it reaches the same Code API that produced the file. Explicit profiles and the unset default are unchanged.
…er the stateful default When LIBRECHAT_CODE_DEFAULT_PROFILE=stateful makes an agent stateful, an agent whose code_environment_id no longer resolves to a configured environment now opts out of attached environments in a "No workspace" conversation, the same as an agent with stateful_code_sessions enabled. Previously it kept code and failed with "Stateful code environment is not configured".
Describe the default/stateful values and that `stateful` overrides an agent's saved "stateful sessions: off".
…ed or missing machine The stateful default setting now applies to an agent only when its resolved code machine is neither attached nor a dangling environment id. Agents on an attached or missing machine keep their existing behavior, and the no-workspace opt-out returns to its original rule.
Drive the provisioning callback and service from an agent's resolved code context and assert the upload carries the stateful profile when the default profile setting is stateful, and the default profile when it is unset.
Drive initialize with a flag-false code subagent and assert the lazy descriptor reports statefulCodeSessions true under LIBRECHAT_CODE_DEFAULT_PROFILE=stateful and false when it is unset.
…Is Off A download link with no execution_profile now follows the configured default profile only when the stateful_code_sessions capability is enabled; otherwise it stays on the default Code API. An explicit execution_profile still wins.
…CODE_DEFAULT_PROFILE
…allowed The stateful default setting no longer forces stateful sessions on an agent whose scope is outside the allowed stateful code environments, so it can no longer turn a working deployment into a policy error. Explicit stateful agents are still refused. Resolver tests for the unset, default and capability-off cases now use a machine the setting applies to.
…ault is stateful Code output fallback links from default-profile runs carried no profile, so the download route would resolve them to the configured default profile. Write execution_profile=default explicitly in that case; links are unchanged when the default profile is unset or default.
…Outside Allowed Scopes
Verify ephemeral Code-toggle agents and added-conversation agents saved with stateful sessions off resolve the stateful profile when the deployment default is stateful, and stay on the default profile when it is unset.
…Palsson/LibreChat into feat/stateful-code-default-profile
…eful Advertise the deployment code profile on the agents endpoint config and have the agent builder treat it as stateful: the switch is hidden and the workspace options are shown, with the form value forced on.
TomasPalsson
marked this pull request as ready for review
October 19, 2026 09:38
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Summary
Deployments whose Code Interpreter runs only the
statefulprofile reject every code request from an Agent that has not switched on stateful sessions, and from every normal chat with the Code toggle on. Users see "Failed to provision 1 file(s) to the code environment" (409 from the service) and the turn dies. Today the only way out is flipping the toggle on every Agent, which does nothing for normal chats.This PR adds one deployment setting,
LIBRECHAT_CODE_DEFAULT_PROFILE(default|stateful, defaultdefault). Withstateful, saved Agents with the toggle off or unset, normal chats with Code on, added-conversation Agents and subagents all run on the stateful profile, and code-output downloads with no named profile follow it. Unset ordefaultbehaves exactly as today.How it works
packages/api/src/code/config.tsparses the setting (trimmed, case-sensitive, an unknown value counts as unset and warns once).isStatefulDefaultEligibleinpackages/api/src/code/agent.tsdecides whether it applies to an Agent, and every gate that readstateful_code_sessions === truenow readsstateful_code_sessions === true || <eligible>, keeping its existing capability check:resolveAgentCodeFlags(packages/api/src/code/agent.ts), which ToolService and both agent initialisers already delegate topackages/api/src/code/inheritance.ts)api/app/clients/tools/util/handleTools.js)The setting applies only when the
stateful_code_sessionscapability is on, the Agent hasexecute_code, its code machine is not an attached environment (or an id that matches no configured environment), and its stateful scope is allowed bystatefulCodeSessions.allowedEnvironments.optsOutOfAttachedCodeEnvironmentis unchanged.Downloads:
GET /api/files/code/download/...with noexecution_profileuses the setting only when the capability is on; an explicit valid value still wins.createDownloadFallbacknow writesexecution_profile=defaultfor default-profile runs when the setting isstateful, so those links stay on the default service.Agent builder: the agents endpoint config now carries
codeDefaultProfile. When it isstateful, the Run Code dialog hides the "Stateful code sessions" switch (it would read off while code runs stateful), shows the stateful options directly under a "Stateful code sessions" heading styled like the dialog's "User control" heading (role="group",aria-labelledby), and sets the form value on (not dirty) so saving stores what runs. No new strings; without the setting the dialog is unchanged.Type of change
.env.example)Testing
Run on this branch (base
a7e6cc89fondev; merges cleanly with currentdev):packages/api:npx jest src/code src/files/provision/callback.spec.ts src/agents/__tests__/initialize.test.ts— 1100 passed, 1 skipped (pre-existing);npx tsc --noEmit -p tsconfig.jsonexit 0;npm run buildexit 0client:npx jest src/components/SidePanel/Agents— 711 passed (newCodeSettings.statefulDefault.spec.tsx);packages/apisrc/endpoints/config— 109 passed (newendpoints.codeDefaultProfile.spec.ts); clienttsc --noEmitexit 0api:npx jest server/routes/files/files.test.js app/clients/tools/util/handleTools.test.js server/services/Endpoints/agents/initialize.spec.js server/services/Endpoints/agents/addedConvo.spec.js server/services/Files/Code/process.spec.js— 418 passedprettier --checkon every changed file: cleanNot run: a live deployment. We are verifying on a stateful-only staging deployment next.
Risk / compatibility
default: every changed expression reduces to the existing one; the download route makes no extra capability call.librechat.yaml: it describes the deployment's Code Interpreter (likeLIBRECHAT_CODE_BASEURL_STATEFUL), not per-endpoint behaviour.stateful, Agents on an attached machine, on an unconfigured machine id, or whose stateful scope is not allowed keep their saved setting.Checklist