Skip to content

🧳 feat: Choose Agent-Allowed Machines For New Chats - #16651

Merged
danny-avila merged 9 commits into
devfrom
danny-avila/chat-code-machines
Oct 2, 2026
Merged

danny-avila merged 9 commits into
devfrom
danny-avila/chat-code-machines

Conversation

@danny-avila

@danny-avila danny-avila commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

I added an explicit per-agent list of attached machines that new chats may choose from. Today a coding agent is fixed to one machine, so using the same agent on an application VM and a runtime VM requires changing its default or creating a duplicate agent. With this opt-in, each new chat chooses its own allowed machine and workspace without modifying the agent's default or moving an existing chat.

  • Define additional permitted machines through code_environment_ids, with the existing code_environment_id implicitly allowed and retained as the default.
  • Offer checkboxes in the agent builder and a machine picker in the new-chat workspace menu.
  • Intersect the agent's list with the current user's authorized machines; discover alternative workspaces only when that machine is expanded.
  • Route file provisioning, tool discovery, approvals, session partitions and lazy subagent execution through the chosen machine's own configuration.
  • Preserve fixed routing when the deployment opt-in is disabled or the agent has no additional machines, and reject inaccessible, unlisted, managed or ambiguous targets.
  • Persist the selection and explicit graph-agent ownership in the existing conversation workspace decision, and preserve versioned agent settings, including restoring a version predating the allowlist.
  • Keep child-agent choices independent and retain explicit recovery controls when a saved machine becomes unavailable or is removed from the agent's list.
  • Identify the coding agent and machine behind each missing workspace, including lazy reviewers, in a visible composer explanation and in menu sections.
  • Match persisted ownership to stable agent IDs even after parallel execution adds runtime suffixes, and reject a revoked owned route instead of reverting to the default machine.
  • Expose removable saved machines that are no longer accessible and omit unchanged allowlists from unrelated agent updates.
  • Authorize and bound all additional machine references before create, update, duplicate or version restore; expose maxEnvironmentChoices with a default of 32 and a ceiling of 128.
  • Reserve every configured machine during agent writes and version restore, and protect additional-machine references during environment deletion and reconciliation.
  • Exercise the same-agent two-machine journey in the existing real-worker acceptance harness and run both native isolation and saved-chat transition variants in CI.

How it works

Agent configuration
  default machine + explicit additional-machine list
    ∩ user's authorized environments
      new-chat machine + workspace choice
        conversation.codeWorkspaces (+ choosing agent IDs)
          execution route + machine permissions + live worker capabilities

The deployment gate is endpoints.agents.statefulCodeSessions.allowEnvironmentSelection: true. Enable it only after all API replicas support this change and advertise environment-decision protocol 1 (CODE_ENVIRONMENT_DECISION_VERSION=1), then refresh clients. In the agent builder, retain the original default machine and check the additional machine(s) this agent may use. No Code API or worker update is required specifically for this feature.

The allowlist is not an access grant. An explicit choice includes agentIds, so Lia can select B while a fixed reviewer stays on A. Ownership is bounded, included in the decision seal and preserved through reload, retry and workspace recovery; one agent cannot own two machine choices. Legacy selections without ownership prefer the selected default, then require exactly one allowed target. Fixed-machine graph requirements survive alternative picks. Update every API replica before enabling the gate and refresh clients, because older strict validators reject ownership-bearing selections rather than silently rerouting them. This PR does not add arbitrary machine switching to sealed chats or change their existing transition policy.

Type of change

  • Feature
  • Tests / tooling / CI

Testing

Tested environments/configuration: macOS, Node 24.16.0, Chrome, isolated memory MongoDB and Redis, a real local Code API and two paired native SRT workers. Only model inference is deterministic; the browser, authorization, approval and worker execution paths are real. No production workers, credentials or databases were used.

Automated tests:

  • All 61 data-provider suites (2,521 tests), 471 focused API routing/initialization/decision/management tests, 256 client workspace/menu/settings/helper tests, plus agent-controller and database persistence/version-restoration coverage. Includes the real added-agent loader followed by routing resolution, and saved-chat recovery after deployment or agent-level revocation.
  • npx tsc --noEmit in data-provider, data-schemas, API and client.
  • Workspace and production client builds, scoped static checks, circular-dependency checks, OpenAPI contract generation and router smoke checks.
  • Native browser canary: one agent reads different physical files on worker A and B; reload preserves B; a separate new chat uses default A; a stopped B cannot write or fall back to A. A fixed lazy reviewer stays on A while Lia chooses B, both menu sections name their agents, actual reads reach B and reload preserves both bindings. Includes Ask, Accept edits, Full access and rejected-write checks.
  • Saved-chat canary: ordinary-agent to coding-agent switch without implicit access, explicit workspace attach, approved native command, offline detach and continued chat after reload.
  • Nine harness tests cover owned-process cleanup and generation-readiness polling; the browser starts only after /readyz, and transient terminal-settlement snapshots retry without hiding authorization or gateway failures.
  • Lighthouse with 250 ms per Mongo query: median LCP 3.84 s, CLS 0.018 and TBT 79.5 ms, within the existing budgets.

Not certified by the local canary: fleet load limits, Linux/WSL native execution, live-provider inference or production deployment behavior. Remote CI status is tracked separately from these local results.

Screenshots / recordings

Actual isolated running apps, same 1280 × 900 viewport. The agent named Lia is a disposable test fixture. Before is the base client; after expands an explicitly permitted second machine in a new chat. Screenshots are uploaded as attachments, not committed.

Before After
Before After

Machine-selection recording: https://github.com/user-attachments/assets/c94bdd18-9e7a-4dcb-9385-4f4bfcd54554

Checklist

  • I followed the contributor guidance and performed a self-review.
  • I added focused regression coverage and verified the real native execution journey locally.
  • I preserved existing defaults, stored decisions and machine authorization boundaries.
  • I localized visible strings and retained shared controls and keyboard behavior.
  • I documented the opt-in and rollout order in the example configuration and acceptance README.
  • I kept API wiring free of new behavior and retained the existing error export while moving its definition to the error module to avoid a dependency cycle.
  • Required dependency changes: none.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 01:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T03:01:29.641548Z 9b7ea9d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head c8ea9b7. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 6b8baea. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads. Both native machine-choice and saved-chat transition canaries now pass, and the generated OpenAPI contract matches the new agent field.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Graph selection, inaccessible-route handling and picker consistency still have unresolved functional issues.

Review effort: Balanced
Findings: 6 Medium severity

Open (6)
What changed in this PR

Adds opt-in, per-chat machine selection for coding agents, using authorized attached machines while preserving agent defaults and existing conversation decisions.

Changes:

  • Persist and restore agent machine allowlists.
  • Add builder checkboxes and lazy machine/workspace selection.
  • Route execution through the selected machine and extend regression coverage and native acceptance checks.
File Description
packages/​data-schemas/​src/​types/​agent.ts Adds persisted allowlist type.
packages/​data-schemas/​src/​schema/​agentWorkspace.spec.ts Tests allowlist persistence.
packages/​data-schemas/​src/​schema/​agent.ts Stores machine allowlists.
packages/​data-schemas/​src/​methods/​agent.ts Projects and restores allowlists.
packages/​data-schemas/​src/​methods/​agent.spec.ts Tests version restoration.
packages/​data-provider/​src/​types/​agents.ts Extends shared agent contracts.
packages/​data-provider/​src/​types.ts Exposes deployment opt-in.
packages/​data-provider/​src/​schemas.ts Initializes builder allowlists.
packages/​data-provider/​src/​config.ts Defines configuration toggle.
packages/​data-provider/​src/​code/​workspace.ts Resolves permitted machine choices.
packages/​data-provider/​src/​code/​selection.spec.ts Tests selection validation.
packages/​api/​src/​endpoints/​config/​endpoints.ts Advertises enabled selection.
packages/​api/​src/​endpoints/​config/​endpoints.spec.ts Tests opt-in advertisement.
packages/​api/​src/​code/​errors.ts Centralizes workspace selection errors.
packages/​api/​src/​code/​capabilities.ts Preserves error exports after relocation.
packages/​api/​src/​agents/​validation.ts Validates machine allowlists.
packages/​api/​src/​agents/​validation.spec.ts Tests allowlist inputs.
packages/​api/​src/​agents/​management.ts Returns allowlists in management responses.
packages/​api/​src/​agents/​management.spec.ts Tests management round-trips.
packages/​api/​src/​agents/​lazySubagents.ts Preserves lazy-subagent allowlists.
packages/​api/​src/​agents/​initialize.ts Passes conversation machine choices.
packages/​api/​src/​agents/​execution.ts Resolves selected execution routes.
packages/​api/​src/​agents/​execution.spec.ts Tests routing, policy and isolation.
packages/​api/​src/​agents/​__tests__/​initialize.test.ts Tests restored-machine initialization.
librechat.example.yaml Documents deployment opt-in.
e2e/​byom/​run.mjs Enables disposable selection fixtures.
e2e/​byom/​README.md Documents acceptance scope and rollout.
e2e/​byom/​native.spec.ts Exercises independent machine choices.
client/​src/​locales/​en/​translation.json Adds machine-selection labels.
client/​src/​hooks/​Agents/​useCodeWorkspace.ts Discovers choices and validates submissions.
client/​src/​hooks/​Agents/​useCodeApprovalMode.ts Uses selected-machine approval policy.
client/​src/​hooks/​Agents/​__tests__/​useCodeWorkspace.test.tsx Tests choices and restored selections.
client/​src/​hooks/​Agents/​__tests__/​useCodeApprovalMode.test.ts Tests machine-specific permissions.
client/​src/​components/​SidePanel/​Agents/​Code/​Settings.tsx Adds allowed-machine checkboxes.
client/​src/​components/​SidePanel/​Agents/​AgentSelect.tsx Loads allowlists into the builder.
client/​src/​components/​SidePanel/​Agents/​AgentPanel.tsx Includes allowlists in updates.
client/​src/​components/​SidePanel/​Agents/​__tests__/​CodeSettings.spec.tsx Tests builder selection controls.
client/​src/​components/​Chat/​Input/​CodeWorkspaceMenu.tsx Adds lazy machine/workspace picking.
client/​src/​components/​Chat/​Input/​__tests__/​CodeWorkspaceMenu.spec.tsx Tests discovery, selection and retry.
client/​src/​common/​agents-types.ts Extends builder form types.
api/​server/​services/​ToolService.js Forwards selection context to routing.
api/​server/​services/​Endpoints/​agents/​initialize.js Forwards choices during initialization.
api/​app/​clients/​tools/​util/​handleTools.js Forwards choices during tool loading.
.github/​workflows/​workspace-acceptance.yml Runs both native acceptance variants.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client/src/components/Chat/Input/CodeWorkspaceMenu.tsx Outdated
Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread packages/api/src/agents/execution.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b8baeaecf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Agents/useCodeWorkspace.ts
Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread packages/data-schemas/src/schema/agent.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 9ff3580. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads. Graph machine-choice composition, revoked-route recovery, fail-closed subagent loading and additional-machine reference lifecycle now have transition coverage.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ff35809e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Agents/useCodeWorkspace.ts Outdated
Comment thread packages/data-provider/src/code/workspace.ts Outdated
Comment thread packages/api/src/agents/validation.ts Outdated
Comment thread api/server/services/ToolService.js Outdated
Comment thread packages/api/src/agents/validation.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 6b99e96. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

I audited the shared routing, graph discovery versus admission, principal-scoped machine authorization, persisted/request precedence, lifecycle reference bounds and saved-chat recovery as a subsystem. The five previous findings are fixed together, with transition and controller-level coverage. The composer now visibly names which agent and machine still need a workspace. Both local native-worker browser canaries, focused tests, all four workspace typechecks, OpenAPI checks and Lighthouse passed.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 7e5dd58. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

The only change since 6b99e96 is direct data-provider regression coverage: preserve a selected default alongside a graph-required alternative, but reject multiple non-default matches. All 61 provider suites (2510 tests) and its typecheck pass locally. The routing, authorization, recovery and visible graph-requirement changes remain as previously described.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 094ad52. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

This final test-only change removes an unused queued action mock from the unauthorized-duplicate regression. The request correctly rejects before loading actions; the unused mock leaked into subsequent content-filter tests because clearAllMocks preserves queued responses. The complete controller suite now passes all 154 tests. Production code is unchanged from 6b99e96. All provider suites, native-worker canaries, workspace typechecks, static checks, OpenAPI and Lighthouse also pass locally.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 094ad52ab3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/components/SidePanel/Agents/AgentPanel.tsx Outdated
Comment thread packages/data-provider/src/code/workspace.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 9e2d746. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

I traced graph ownership across choice, authorization, execution, persisted decisions, retry equality, saved-chat transitions and serialization. Explicit agentIds now distinguish Lia on B from a fixed reviewer on A; canonical seals include ownership. Inaccessible saved allowlists can be removed or omitted on unrelated edits. The composer states that every coding agent, including subagents, needs a workspace and identifies the missing agent and machine. Provider, API, controller, client and real-Mongo tests, all four workspace typechecks, native two-worker graph canary, saved-chat transition canary, OpenAPI, lint and Lighthouse passed locally.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e2d746f2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/data-provider/src/code/workspace.ts Outdated
Comment thread packages/data-provider/src/code/workspace.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 0a3a5d2. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 0a3a5d2fc3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 9b7ea9d. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

The only changes since the clean review at 0a3a5d2 are in the native acceptance harness and its workflow: wait for /readyz before browser startup, and retry only an explicit 503 SERVER_NOT_READY generation-status snapshot within the existing bounded poll. Authorization failures, unrelated 503s and non-JSON errors still fail. Nine harness unit tests and the real saved-chat transition canary pass locally. Application code is unchanged.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 9b7ea9d4c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila merged commit 2eee568 into dev Oct 2, 2026
46 checks passed
@danny-avila
danny-avila deleted the danny-avila/chat-code-machines branch October 2, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants