Repository navigation
Apply access policy when reusing channel agents #6838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa8c0c5
fix(desktop): honor owner-only on agent reuse
jmecom 1afb0ac
fix(desktop): default reused agents to owner-only
jmecom ff81812
fix(desktop): secure composer agent reuse
jmecom 2da2106
refactor(desktop): simplify reused agent policy fix
jmecom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { provisionChannelManagedAgent } from "./channelAgents.ts"; | ||
|
|
||
| const PUBKEY = "a".repeat(64); | ||
| const RUNTIME = { | ||
| id: "goose", | ||
| label: "Goose", | ||
| command: "goose", | ||
| defaultArgs: [], | ||
| mcpCommand: "buzz-dev-mcp", | ||
| }; | ||
|
|
||
| function makeAgent(personaId, overrides = {}) { | ||
| return { | ||
| pubkey: PUBKEY, | ||
| name: "reviewer", | ||
| personaId, | ||
| runtime: null, | ||
| teamId: null, | ||
| relayUrl: "wss://relay.example", | ||
| acpCommand: "buzz-acp", | ||
| agentCommand: "goose", | ||
| agentCommandOverride: null, | ||
| agentArgs: [], | ||
| mcpCommand: "buzz-dev-mcp", | ||
| turnTimeoutSeconds: 320, | ||
| idleTimeoutSeconds: null, | ||
| maxTurnDurationSeconds: null, | ||
| parallelism: 1, | ||
| systemPrompt: null, | ||
| avatarUrl: null, | ||
| model: null, | ||
| modelSource: null, | ||
| provider: null, | ||
| personaOutOfDate: false, | ||
| personaOrphaned: false, | ||
| needsRestart: false, | ||
| restartDiff: [], | ||
| envVars: {}, | ||
| status: "running", | ||
| pid: null, | ||
| createdAt: "2026-01-01T00:00:00Z", | ||
| updatedAt: "2026-01-01T00:00:00Z", | ||
| lastStartedAt: null, | ||
| lastStoppedAt: null, | ||
| lastExitCode: null, | ||
| lastError: null, | ||
| lastErrorCode: null, | ||
| logPath: "", | ||
| startOnAppLaunch: false, | ||
| autoRestartOnConfigChange: true, | ||
| backend: { type: "local" }, | ||
| backendAgentId: null, | ||
| respondTo: "anyone", | ||
| respondToAllowlist: [PUBKEY], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function toRawAgent(agent) { | ||
| return { | ||
| pubkey: agent.pubkey, | ||
| name: agent.name, | ||
| persona_id: agent.personaId, | ||
| runtime: agent.runtime, | ||
| team_id: agent.teamId, | ||
| relay_url: agent.relayUrl, | ||
| acp_command: agent.acpCommand, | ||
| agent_command: agent.agentCommand, | ||
| agent_command_override: agent.agentCommandOverride, | ||
| agent_args: agent.agentArgs, | ||
| mcp_command: agent.mcpCommand, | ||
| turn_timeout_seconds: agent.turnTimeoutSeconds, | ||
| idle_timeout_seconds: agent.idleTimeoutSeconds, | ||
| max_turn_duration_seconds: agent.maxTurnDurationSeconds, | ||
| parallelism: agent.parallelism, | ||
| system_prompt: agent.systemPrompt, | ||
| avatar_url: agent.avatarUrl, | ||
| model: agent.model, | ||
| model_source: agent.modelSource, | ||
| provider: agent.provider, | ||
| persona_out_of_date: agent.personaOutOfDate, | ||
| persona_orphaned: agent.personaOrphaned, | ||
| needs_restart: agent.needsRestart, | ||
| restart_diff: agent.restartDiff, | ||
| env_vars: agent.envVars, | ||
| status: agent.status, | ||
| pid: agent.pid, | ||
| created_at: agent.createdAt, | ||
| updated_at: agent.updatedAt, | ||
| last_started_at: agent.lastStartedAt, | ||
| last_stopped_at: agent.lastStoppedAt, | ||
| last_exit_code: agent.lastExitCode, | ||
| last_error: agent.lastError, | ||
| last_error_code: agent.lastErrorCode, | ||
| log_path: agent.logPath, | ||
| start_on_app_launch: agent.startOnAppLaunch, | ||
| auto_restart_on_config_change: agent.autoRestartOnConfigChange, | ||
| backend: agent.backend, | ||
| backend_agent_id: agent.backendAgentId, | ||
| respond_to: agent.respondTo, | ||
| respond_to_allowlist: agent.respondToAllowlist, | ||
| }; | ||
| } | ||
|
|
||
| test("reuse applies the owner-only default and clears stale allowlists", async (t) => { | ||
| const priorWindow = globalThis.window; | ||
| t.after(() => { | ||
| globalThis.window = priorWindow; | ||
| }); | ||
|
|
||
| for (const personaId of ["persona-1", null]) { | ||
| const existing = makeAgent(personaId); | ||
| const calls = []; | ||
| globalThis.window ??= {}; | ||
| window.__TAURI_INTERNALS__ = { | ||
| invoke(command, args) { | ||
| calls.push([command, args]); | ||
| assert.equal(command, "update_managed_agent"); | ||
| return Promise.resolve({ | ||
| agent: toRawAgent({ | ||
| ...existing, | ||
| respondTo: args.input.respondTo, | ||
| respondToAllowlist: args.input.respondToAllowlist, | ||
| }), | ||
| profile_sync_error: null, | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| const result = await provisionChannelManagedAgent( | ||
| { | ||
| runtime: RUNTIME, | ||
| name: "reviewer", | ||
| personaId, | ||
| }, | ||
| { | ||
| managedAgents: [existing], | ||
| channelMemberPubkeys: new Set(), | ||
| }, | ||
| ); | ||
|
|
||
| assert.equal(calls.length, 1); | ||
| assert.equal(calls[0][1].input.respondTo, "owner-only"); | ||
| assert.deepEqual(calls[0][1].input.respondToAllowlist, []); | ||
| assert.equal(result.agent.respondTo, "owner-only"); | ||
| assert.deepEqual(result.agent.respondToAllowlist, []); | ||
| } | ||
| }); | ||
|
|
||
| test("reuse skips updates when the owner-only default already matches", async (t) => { | ||
| const priorWindow = globalThis.window; | ||
| t.after(() => { | ||
| globalThis.window = priorWindow; | ||
| }); | ||
|
|
||
| globalThis.window ??= {}; | ||
| window.__TAURI_INTERNALS__ = { | ||
| invoke(command) { | ||
| assert.fail(`unexpected ${command} call`); | ||
| }, | ||
| }; | ||
|
|
||
| for (const personaId of ["persona-1", null]) { | ||
| const existing = makeAgent(personaId, { | ||
| respondTo: "owner-only", | ||
| respondToAllowlist: [], | ||
| }); | ||
| const result = await provisionChannelManagedAgent( | ||
| { | ||
| runtime: RUNTIME, | ||
| name: "reviewer", | ||
| personaId, | ||
| }, | ||
| { | ||
| managedAgents: [existing], | ||
| channelMemberPubkeys: new Set(), | ||
| }, | ||
| ); | ||
|
|
||
| assert.equal(result.agent, existing); | ||
| } | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMPORTANT — Correctness/Security: This fallback is not reached by the production path that prompted the fix. An existing managed-agent autocomplete result is handled by
ensureManagedAgentMentionsReady()indesktop/src/features/messages/ui/useMentionSendFlow.ts:128-171, which directly attaches/starts the identity without callingprovisionChannelManagedAgent(). In an exact-head composer run, an out-of-channel persona-linked agent seeded asanyoneplus a stale allowlist emitted noupdate_managed_agentand remained broad after attach/start/send. The new tests call this helper seam, so they do not catch that bypass. Please enforce the intended gate in the already-managed identity attach path and add a production-caller regression. Also resolve omitted policy using the same definition-aware semantics as fresh minting: this unconditionalowner-onlyfallback diverges for linked personas whose stored default isanyoneorallowlist.