Skip to content

commonly agent run reports its chosen adapter once, into the installation's config.runtime.adapter #2184

Open

Description

@lilyshen0722

Problem

When a seat is connected through the Connect page (or an approved connect_local_agent card) and started with the page's lines, the installation is config.runtime.runtimeType: 'webhook'. Then commonly agent run <name> picks the adapter (claude / codex / pi / opencode / qwen) on the user's machine and stores it only in the local token file. The CLI says so itself (cli/src/commands/agent.js, bootstrapAgentRecordFromEnv): "The adapter names a binary on THIS machine — the one fact the server cannot know."

So the server can't tell which CLI a page-connected seat runs. Measured read-only on production: the installation has no adapter, the bot's botMetadata has none, and the agent's messages carry none. Everything that reads the resolved adapter sees null for these seats:

  • adapterForRuntimeBinding() (backend/services/grantBrokerConfinement.ts), which the grant-broker check uses. A seat that names no adapter is judged as daemon-decided (the claude/codex union).
  • runtimeAdapter in GET /api/agents/runtime/installations, which the CLI's own serverAdapterBindingRefusal reads.
  • Any per-seat or per-team count of which CLIs connected seats run, for support and usage analytics.

The daemon path already fills this field: commonly agent config <name> --adapter <x> PATCHes config.runtime.adapter (updateAgentConfiguration → PATCH /api/registry/pods/:podId/agents/:name), and daemon-supervisor.js reads it. Only the Connect-page / env-token path leaves it empty.

Proposal

CLI half (SWE): after bootstrapAgentRecordFromEnv resolves the adapter and passes the binding check, report it to the server once, into the installation's config.runtime.adapter. Do this only on first bootstrap, never on later runs from an existing token file. Make it best-effort: a failed report logs one line and never blocks the run.

Route half (CTO gates): the bootstrap path holds only the runtime token (cm_agent_*), so it can't use the installer-gated PATCH /api/registry/pods/:podId/agents/:name (user auth, installer-or-admin). It needs a narrow runtime-token write. One shape:

  • agentRuntimeAuth, applying only to installations of the calling agent identity (req.agentUser).
  • Body { podId, instanceId, adapter }. adapter must be a known adapter name, normalized like the daemon does (trim + lowercase).
  • Write-once: a conditional update on config.runtime.adapter being absent, and only when runtimeType is a runtime kind that names no adapter (webhook). Otherwise return 409 with no change.

Why the route half needs a gate

config.runtime.adapter is not informational today:

  1. daemon-supervisor.js reads row.runtime.adapter to choose which CLI it launches for a daemon-managed seat.
  2. grantBrokerConfinement.ts uses it to decide adapter_cannot_confine and which sandbox modes count as enforceable.
  3. Once it's set, serverAdapterBindingRefusal refuses a later bootstrap with a different CLI. Switching from claude to codex then needs agent config --adapter (the installer) instead of a fresh agent run --adapter.

That's why the existing writer is installer-only: config reaches the owner's machine. Write-once plus webhook-only keeps the seat from changing an adapter someone else set, but the reviewer should decide:

  • (a) whether a seat may set it even once, or
  • (b) whether a separate report-only field that no spawner or policy reads (e.g. config.runtime.reportedAdapter) is the better place.

Either one closes the gap for the readers that only want to know which CLI is running.

Acceptance

  • Page lines → commonly agent run x (claude detected) → installation shows config.runtime.adapter: 'claude', or the chosen field, and runtimeAdapter projects it.
  • A second agent run from the saved token file makes no write.
  • The route refuses: another agent's installation (403/404), an unknown adapter (400), and an installation that already names an adapter (409, unchanged).
  • Unit tests for the route (write-once, ownership, allowlist) and for the CLI bootstrap (reports once, a failed report doesn't block the run).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions