✅ feat: Default Machine Selection and Linked-Worktree Lanes On (#16678)

* ✅ feat: Default Machine Selection and Linked-Worktree Lanes On

Per-chat machine choice from an agent's saved allowlist and linked-worktree
lane routing were both opt-in, so neither worked until a deployment found and
set its flag. Both are now on unless set to false: machine choice still only
applies to agents with a saved allowlist, and lanes still require a worker
that advertises git_linked_worktree. One helper per flag in data-provider
decides the default for every server reader and the advertised client config.

* feat: Advertise the Code Environment Decision Protocol by Default

Per-chat machine choice needs the conversation decision protocol, which the
client requires before offering allowlisted machines, but the protocol was
only advertised when CODE_ENVIRONMENT_DECISION_VERSION=1. With selection on
by default, authors could save an allowlist the composer never offered.
An unset or blank value now advertises protocol v1; any other value, such as
0, keeps the legacy-safe path.

* fix: Turn Machine Choice Off With the Decision Protocol Opt-Out

CODE_ENVIRONMENT_DECISION_VERSION=0 stopped advertising the protocol but
routing still accepted a non-default machine, so a cached tab or a direct
client could persist a choice during a mixed-version rollout. Machine choice
is recorded through that protocol, so isCodeEnvironmentSelectionEnabled now
requires both, for routing and for the advertised endpoints config. The
protocol resolver moves to code/protocol.ts (re-exported from code/config)
so execution and endpoints can use it without an import cycle.

* style: Format checkout routing regression cases

---------

Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
Danny Avila 2026-10-02 20:08:35 -04:00 • committed by GitHub
parent 2d35614a0c
commit 1a8d23e1ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 218 additions and 71 deletions

View file

@ -452,19 +452,32 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
expect(resolved.codeWorkspace?.environment).toEqual(environment);
});
it.each(['source', 'isolated'] as const)(
'honors an explicit %s checkout choice',
async (checkout) => {
jest
.spyOn(globalThis, 'fetch')
.mockResolvedValue(
workspaceStatus([{ id: 'worktree', workspaceInstances: ['git_worktree'] }]),
);
it.each([
{ checkout: 'source', linkedWorktrees: undefined, lanes: true },
{ checkout: 'source', linkedWorktrees: true, lanes: true },
{ checkout: 'source', linkedWorktrees: false, lanes: false },
{ checkout: 'isolated', linkedWorktrees: undefined, lanes: false },
{ checkout: 'isolated', linkedWorktrees: true, lanes: false },
{ checkout: 'isolated', linkedWorktrees: false, lanes: false },
] as const)(
'honors checkout $checkout with linkedWorktrees=$linkedWorktrees',
async ({ checkout, linkedWorktrees, lanes }) => {
jest.spyOn(globalThis, 'fetch').mockResolvedValue(
workspaceStatus([
{
id: 'worktree',
workspaceInstances: ['git_worktree'],
workspaceScopes: ['git_linked_worktree'],
},
]),
);
const resolved = await resolveCodeExecutionWorkspaceContext({
context: {
...context,
conversationWorkspaceInstanceId: 'c'.repeat(64),
codeEnvironmentConfigSchema: { workspaces: { allowCheckoutSelection: true } },
codeEnvironmentConfigSchema: {
workspaces: { allowCheckoutSelection: true, linkedWorktrees },
},
},
requestedSelections: [{ environmentId: 'personal', workspaceId: 'worktree', checkout }],
environments,
@ -474,6 +487,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
expect(resolved.codeWorkspace?.workspaceInstanceId).toBe(
checkout === 'isolated' ? 'c'.repeat(64) : undefined,
);
expect(resolved.codeWorkspace?.linkedWorktrees).toBe(lanes ? true : undefined);
},
);
@ -549,7 +563,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
expect(legacy.codeWorkspace).not.toHaveProperty('workspaceInstanceId');
});
it('routes linked worktrees into lanes only when configured and no conversation instance owns the checkout', async () => {
it('routes linked worktrees into lanes unless disabled or a conversation instance owns the checkout', async () => {
const workspaceInstanceId = 'c'.repeat(64);
jest.spyOn(globalThis, 'fetch').mockImplementation(async () =>
workspaceStatus([
@ -588,7 +602,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
expect(lanes.codeWorkspace?.linkedWorktrees).toBe(true);
expect(disabled.codeWorkspace).not.toHaveProperty('linkedWorktrees');
expect(unconfigured.codeWorkspace).not.toHaveProperty('linkedWorktrees');
expect(unconfigured.codeWorkspace?.linkedWorktrees).toBe(true);
expect(instance.codeWorkspace?.workspaceInstanceId).toBe(workspaceInstanceId);
expect(instance.codeWorkspace).not.toHaveProperty('linkedWorktrees');
expect(legacy.codeWorkspace).not.toHaveProperty('linkedWorktrees');

View file

@ -1,6 +1,7 @@
import { logger } from '@librechat/data-schemas';
import {
isCodeWorkspaceSelections,
isLinkedWorktreeRoutingAllowed,
canonicalizeCodeWorkspaceSelections,
isCodeWorkspaceCheckoutAvailable,
} from 'librechat-data-provider';
@ -161,7 +162,9 @@ export async function resolveCodeExecutionWorkspaceContext({
...selection,
operations: [...(workspace.operations ?? status.operations)],
...(usesIsolation ? { workspaceInstanceId: context.conversationWorkspaceInstanceId } : {}),
...(context.codeEnvironmentConfigSchema?.workspaces?.linkedWorktrees === true &&
...(isLinkedWorktreeRoutingAllowed(
context.codeEnvironmentConfigSchema?.workspaces?.linkedWorktrees,
) &&
workspace.workspaceScopes?.includes('git_linked_worktree') &&
!usesIsolation
? { linkedWorktrees: true }

View file

@ -2,6 +2,7 @@ import { EModelEndpoint } from 'librechat-data-provider';
import type { AppConfig } from '@librechat/data-schemas';
import {
isImplicitStatefulCodeRouteAvailable,
isCodeEnvironmentSelectionEnabled,
mergeAccessibleCodeEnvironments,
resolveCodeEnvironmentDecisionVersion,
resolveCodeEnvironmentMoveVersion,
@ -14,7 +15,11 @@ describe('resolveCodeEnvironmentDecisionVersion', () => {
expect(resolveCodeEnvironmentDecisionVersion('1')).toBe(1);
});
it.each([undefined, '0', '2', '1.0', 'true'])(
it.each([undefined, '', ' '])('advertises the supported version when unset (%p)', (version) => {
expect(resolveCodeEnvironmentDecisionVersion(version)).toBe(1);
});
it.each(['0', '2', '1.0', 'true'])(
'keeps unsupported configured version %s on the legacy-safe path',
(version) => {
expect(resolveCodeEnvironmentDecisionVersion(version)).toBeUndefined();
@ -82,10 +87,23 @@ describe('resolveCodeEnvironmentMoveVersion', () => {
});
});
describe('isCodeEnvironmentSelectionEnabled', () => {
it.each([
[undefined, undefined, true],
[true, '1', true],
[false, undefined, false],
[undefined, '0', false],
[true, '0', false],
])('flag %p with decision version %p resolves to %p', (flag, version, expected) => {
expect(isCodeEnvironmentSelectionEnabled(flag, version)).toBe(expected);
});
});
describe('isImplicitStatefulCodeRouteAvailable', () => {
it('requires both the deployed protocol version and a non-empty managed base URL', () => {
expect(isImplicitStatefulCodeRouteAvailable('1', 'https://code.example/v1')).toBe(true);
expect(isImplicitStatefulCodeRouteAvailable(undefined, 'https://code.example/v1')).toBe(false);
expect(isImplicitStatefulCodeRouteAvailable(undefined, 'https://code.example/v1')).toBe(true);
expect(isImplicitStatefulCodeRouteAvailable('0', 'https://code.example/v1')).toBe(false);
expect(isImplicitStatefulCodeRouteAvailable('1', ' ')).toBe(false);
});
});

View file

@ -1,6 +1,5 @@
import { logger } from '@librechat/data-schemas';
import {
CODE_ENVIRONMENT_DECISION_VERSION,
CODE_ENVIRONMENT_MOVE_VERSION,
CODE_ENVIRONMENT_TRANSITION_VERSION,
CODE_WORKSPACE_RECOVERY_VERSION,
@ -12,6 +11,12 @@ import type {
AccessibleCodeEnvironmentConfiguration,
CodeEnvironmentPrincipalContext,
} from './environments';
import { resolveCodeEnvironmentDecisionVersion } from './protocol';
export {
resolveCodeEnvironmentDecisionVersion,
isCodeEnvironmentSelectionEnabled,
} from './protocol';
type ConfigurationRegistry = {
listAccessibleConfigurations: (
@ -25,18 +30,6 @@ type StatefulCodeConfig = NonNullable<
>['statefulCodeSessions'];
type CodeEnvironmentConfig = NonNullable<NonNullable<StatefulCodeConfig>['environments']>[number];
/**
* Resolves the deployment-wide browser protocol gate. The exact version match
* keeps older and future wire shapes on the legacy-safe path.
*/
export function resolveCodeEnvironmentDecisionVersion(
configuredVersion?: string,
): typeof CODE_ENVIRONMENT_DECISION_VERSION | undefined {
return configuredVersion === String(CODE_ENVIRONMENT_DECISION_VERSION)
? CODE_ENVIRONMENT_DECISION_VERSION
: undefined;
}
function conversationMovesEnabled(appConfig?: Pick<AppConfig, 'endpoints'> | null): boolean {
return (
appConfig?.endpoints?.[EModelEndpoint.agents]?.statefulCodeSessions?.conversationMoves

View file

@ -0,0 +1,33 @@
import {
CODE_ENVIRONMENT_DECISION_VERSION,
isCodeEnvironmentSelectionAllowed,
} from 'librechat-data-provider';
/**
* Resolves the deployment-wide browser protocol gate. Unset or blank advertises the supported
* version, so per-chat machine choice works without a second opt-in. Any other value than the
* exact version — `0` to opt out, or an older or future wire shape — keeps the legacy-safe path.
*/
export function resolveCodeEnvironmentDecisionVersion(
configuredVersion?: string,
): typeof CODE_ENVIRONMENT_DECISION_VERSION | undefined {
const version = configuredVersion?.trim() ?? '';
return version === '' || version === String(CODE_ENVIRONMENT_DECISION_VERSION)
? CODE_ENVIRONMENT_DECISION_VERSION
: undefined;
}
/**
* Per-chat machine choice is recorded through the decision protocol, so a deployment that turns
* the protocol off (`CODE_ENVIRONMENT_DECISION_VERSION=0`) turns machine choice off as well, for
* both what the server advertises and what it routes.
*/
export function isCodeEnvironmentSelectionEnabled(
allowEnvironmentSelection?: boolean | null,
configuredDecisionVersion: string | undefined = process.env.CODE_ENVIRONMENT_DECISION_VERSION,
): boolean {
return (
isCodeEnvironmentSelectionAllowed(allowEnvironmentSelection) &&
resolveCodeEnvironmentDecisionVersion(configuredDecisionVersion) != null
);
}