Skip to content

Commit 4fc2499

Browse files
joshspicerCopilot
andcommitted
fix(agent-host): clamp live managed bypass
Apply managed bypass restrictions to the live SDK permission mode immediately when root policy changes, rather than waiting for session refresh on the next send. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0c61d20 commit 4fc2499

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { CopilotCliConfigKey, applyModelFamilyAlias, copilotCliConfigSchema } fr
3232
import type { ChatInputRequestWithPlanReview, IAgentHostPlanReviewAction } from '../../common/agentHostPlanReview.js';
3333
import { gitHubMcpServerUrl } from '../../common/githubEndpoints.js';
3434
import { AgentHostSandboxConfigKey, sandboxConfigSchema } from '../../common/sandboxConfigSchema.js';
35-
import { AgentHostGlobalAutoApproveEnabledConfigKey, AgentHostAutoReplyAnswer, AgentHostAutoReplyEnabledConfigKey, AgentHostDisableRepoInfoTelemetryConfigKey, platformRootSchema, platformSessionSchema } from '../../common/agentHostSchema.js';
35+
import { AgentHostGlobalAutoApproveEnabledConfigKey, AgentHostAutoReplyAnswer, AgentHostAutoReplyEnabledConfigKey, AgentHostDisableRepoInfoTelemetryConfigKey, AgentHostManagedPermissionsConfigKey, platformRootSchema, platformSessionSchema } from '../../common/agentHostSchema.js';
3636
import { AgentSession, AgentSignal, AuthenticateParams, IMcpNotification, IRestoredSubagentSession, subagentChatTitle, type IAgentToolPendingConfirmationSignal } from '../../common/agentService.js';
3737
import { META_DIFF_BASE_BRANCH } from '../../common/agentHostGitService.js';
3838
import { stripRedundantCdPrefix } from '../../common/commandLineHelpers.js';
@@ -2992,6 +2992,9 @@ export class CopilotAgentSession extends Disposable {
29922992
* level. Agent mode is an orthogonal axis and does not affect approvals.
29932993
*/
29942994
private _isBypassApprovals(): boolean {
2995+
if (this._configurationService.getRootValue(platformRootSchema, AgentHostManagedPermissionsConfigKey)?.disableBypassPermissionsMode === 'disable') {
2996+
return false;
2997+
}
29952998
if (this._configurationService.getRootValue(platformRootSchema, AgentHostGlobalAutoApproveEnabledConfigKey) === true) {
29962999
return true;
29973000
}

src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { TestAgentHostTerminalManager } from './testAgentHostTerminalManager.js'
4747
import { buildCopilotSystemNotification } from '../../node/copilot/copilotSystemNotification.js';
4848
import { IAgentConfigurationService } from '../../node/agentConfigurationService.js';
4949
import { SessionConfigKey } from '../../common/sessionConfigKeys.js';
50-
import { AgentHostAutoReplyEnabledConfigKey, AgentHostDisableRepoInfoTelemetryConfigKey, AgentHostGlobalAutoApproveEnabledConfigKey } from '../../common/agentHostSchema.js';
50+
import { AgentHostAutoReplyEnabledConfigKey, AgentHostDisableRepoInfoTelemetryConfigKey, AgentHostGlobalAutoApproveEnabledConfigKey, AgentHostManagedPermissionsConfigKey } from '../../common/agentHostSchema.js';
5151
import { CopilotCliConfigKey } from '../../common/copilotCliConfig.js';
5252
import { AgentHostSandboxConfigKey, AgentHostSandboxKey } from '../../common/sandboxConfigSchema.js';
5353
import { AgentSandboxEnabledValue } from '../../../sandbox/common/settings.js';
@@ -3480,15 +3480,17 @@ suite('CopilotAgentSession', () => {
34803480
assert.deepStrictEqual(mockSession.permissionModeSetCalls, ['auto']);
34813481
});
34823482

3483-
test('syncs permission mode when root approval configuration changes', async () => {
3484-
const { session, mockSession, setRootValue, fireRootConfigChange } = await createAgentSession(disposables);
3483+
test('managed policy clamps a live allow-all session', async () => {
3484+
const { session, mockSession, setRootValue, fireRootConfigChange } = await createAgentSession(disposables, {
3485+
configValues: { [SessionConfigKey.AutoApprove]: 'autoApprove' },
3486+
});
34853487
await session.syncPermissionMode('turn-start');
3486-
setRootValue(AgentHostGlobalAutoApproveEnabledConfigKey, true);
3488+
setRootValue(AgentHostManagedPermissionsConfigKey, { disableBypassPermissionsMode: 'disable' });
34873489

34883490
fireRootConfigChange();
34893491
await timeout(0);
34903492

3491-
assert.deepStrictEqual(mockSession.permissionModeSetCalls, ['off', 'on']);
3493+
assert.deepStrictEqual(mockSession.permissionModeSetCalls, ['on', 'off']);
34923494
});
34933495

34943496
test('aborts when a live permission mode update fails', async () => {

0 commit comments

Comments
 (0)