Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions packages/core/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ import type { SkillConfig } from '../skills/types.js';
import { createSkillScopedAgentConfig } from '../memory/skillReviewAgentPlanner.js';
import { maybeRunAutoSkillCurator } from '../skills/skill-curator.js';
import { HookSystem } from '../hooks/index.js';
import { GOAL_HOOK_ID_OUTPUT_KEY } from '../goals/goalHook.js';
import type { FileHistorySnapshot } from '../services/fileHistoryService.js';
import type {
ChatRecord,
Expand Down Expand Up @@ -13091,78 +13090,6 @@ describe('Model Switching and Config Updates', () => {
});
});

describe('Stop dispatch through the hook execution bridge', () => {
it.each([
{
name: 'ignores non-blocking outputs',
otherOutput: { continue: true },
expected: false,
expectedReason: undefined,
},
{
name: 'detects another blocking output',
otherOutput: {
decision: 'block',
reason: 'Policy review is still required',
},
expected: true,
expectedReason: 'Policy review is still required',
},
{
name: 'preserves a stop reason',
otherOutput: {
continue: false,
stopReason: 'External stop hook feedback',
},
expected: true,
expectedReason: 'External stop hook feedback',
},
])(
'$name when a goal hook blocks',
async ({ otherOutput, expected, expectedReason }) => {
const config = new Config({ ...baseParams });
await config.initialize();
const goalOutput = {
decision: 'block' as const,
reason: 'Keep working',
hookSpecificOutput: {
[GOAL_HOOK_ID_OUTPUT_KEY]: 'goal-hook-id',
},
};
const fireStopEvent = vi.fn().mockResolvedValue({
finalOutput: {
...goalOutput,
...otherOutput,
},
allOutputs: [goalOutput, otherOutput],
});
// @ts-expect-error - accessing private for testing
config['hookSystem'] = { fireStopEvent };

const response = await config
.getMessageBus()!
.request<HookExecutionRequest, HookExecutionResponse>(
{
type: MessageBusType.HOOK_EXECUTION_REQUEST,
eventName: 'Stop',
input: {
stop_hook_active: true,
last_assistant_message: 'last response',
},
},
MessageBusType.HOOK_EXECUTION_RESPONSE,
);

expect(response.error).toBeUndefined();
expect(response).toMatchObject({
success: true,
hasNonGoalBlockingStopHook: expected,
});
expect(response.nonGoalBlockingStopReason).toBe(expectedReason);
},
);
});

describe('MessageDisplay dispatch through the hook execution bridge', () => {
it('extracts message_id/displayed_text/is_final from the request input and forwards them positionally', async () => {
const config = new Config({ ...baseParams });
Expand Down
31 changes: 0 additions & 31 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ import {
type PostToolBatchToolCall,
} from '../hooks/types.js';
import { fireNotificationHook } from '../core/toolHookTriggers.js';
import { GOAL_HOOK_ID_OUTPUT_KEY } from '../goals/goalHook.js';
import {
createGoalRuntime,
GoalPersistenceUnavailableError,
Expand Down Expand Up @@ -3277,8 +3276,6 @@ export class Config {
// Execute the appropriate hook based on eventName
let result;
let stopHookCount: number | undefined;
let hasNonGoalBlockingStopHook: boolean | undefined;
let nonGoalBlockingStopReason: string | undefined;
const input = request.input || {};
const signal = request.signal;
switch (request.eventName) {
Expand Down Expand Up @@ -3317,32 +3314,6 @@ export class Config {
? createHookOutput('Stop', stopResult.finalOutput)
: undefined;
stopHookCount = stopResult.allOutputs.length;
const goalHookId =
stopResult.finalOutput?.hookSpecificOutput?.[
GOAL_HOOK_ID_OUTPUT_KEY
];
if (typeof goalHookId === 'string') {
const nonGoalBlockingOutputs = stopResult.allOutputs.filter(
(output) =>
output.hookSpecificOutput?.[GOAL_HOOK_ID_OUTPUT_KEY] !==
goalHookId &&
(output.decision === 'block' ||
output.decision === 'deny' ||
output.continue === false),
);
hasNonGoalBlockingStopHook =
nonGoalBlockingOutputs.length > 0;
if (hasNonGoalBlockingStopHook) {
nonGoalBlockingStopReason = nonGoalBlockingOutputs
.map(
(output) =>
output.stopReason ||
output.reason ||
'No reason provided',
)
.join('\n');
}
}
break;
}
case 'MessageDisplay': {
Expand Down Expand Up @@ -3471,8 +3442,6 @@ export class Config {
output: result,
// Include stop hook count for Stop events
stopHookCount,
hasNonGoalBlockingStopHook,
nonGoalBlockingStopReason,
} as HookExecutionResponse);
} catch (error) {
this.debugLogger.warn(`Hook execution failed: ${error}`);
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/confirmation-bus/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ export interface HookExecutionResponse {
error?: Error;
/** Number of stop hooks that were executed */
stopHookCount?: number;
/** Whether a blocking Stop output came from outside the active goal hook. */
hasNonGoalBlockingStopHook?: boolean;
/** Continuation reason from blocking Stop outputs outside the active goal. */
nonGoalBlockingStopReason?: string;
}

export type Message =
Expand Down
139 changes: 1 addition & 138 deletions packages/core/src/core/client-goal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { Config } from '../config/config.js';
import type { LlmChat } from './llm-chat.js';
import {
Expand All @@ -27,12 +27,6 @@ import {
} from '../goals/goal-protocol.js';
import type { ChatRecord } from '../services/chatRecordingService.js';
import { ApprovalMode } from '../config/config.js';
import {
__resetActiveGoalStoreForTests,
clearActiveGoal,
setActiveGoal,
} from '../goals/activeGoalStore.js';
import { GOAL_HOOK_ID_OUTPUT_KEY } from '../goals/goalHook.js';
import type { PendingGoalProposal } from '../goals/goal-tools.js';

const turnMocks = vi.hoisted(() => ({
Expand Down Expand Up @@ -291,7 +285,6 @@ function setupGoalClient() {

describe('LlmClient Goal admission', () => {
beforeEach(() => {
__resetActiveGoalStoreForTests();
turnMocks.constructors.length = 0;
turnMocks.pendingToolCalls.length = 0;
turnMocks.run.mockReset().mockImplementation(emptyStream);
Expand All @@ -300,10 +293,6 @@ describe('LlmClient Goal admission', () => {
});
});

afterEach(() => {
__resetActiveGoalStoreForTests();
});

it('sets an approved propose_goal proposal once the turn ends without tool calls', async () => {
const { client, config, runtime } = setupGoalClient();
nextSpeakerMocks.check.mockResolvedValue({ next_speaker: 'user' });
Expand Down Expand Up @@ -422,76 +411,6 @@ describe('LlmClient Goal admission', () => {
});
});

it('settles an approved proposal when a cleared Goal removes the Stop continuation', async () => {
const { client, config, runtime } = setupGoalClient();
vi.mocked(runtime.getSnapshot).mockReturnValue({
v: 2,
activity: 'idle',
goal: null,
});
setActiveGoal('goal-test-session', {
condition: 'finish the old goal',
iterations: 1,
setAt: 1,
tokensAtStart: 1,
hookId: 'old-goal-hook',
});
let pending: { objective: string; turnKey: string } | undefined;
const takePendingGoalProposal = vi.fn(() => {
const proposal = pending;
pending = undefined;
return proposal;
});
Object.assign(config, {
takePendingGoalProposal,
getDisableAllHooks: vi.fn(() => false),
hasHooksForEvent: vi.fn((event) => event === 'Stop'),
getMessageBus: vi.fn(() => ({
request: vi.fn(async () => ({
output: {
decision: 'block',
reason: 'Keep working',
hookSpecificOutput: {
[GOAL_HOOK_ID_OUTPUT_KEY]: 'old-goal-hook',
},
},
stopHookCount: 1,
hasNonGoalBlockingStopHook: false,
})),
})),
getMaxSessionTurns: vi.fn(() => 0),
getUsageStatisticsEnabled: vi.fn(() => false),
});
turnMocks.run.mockImplementationOnce(() => {
pending = { objective: 'ship it', turnKey: 'stop-clear-key' };
return emptyStream();
});
const getSteerInput = vi
.fn()
.mockResolvedValueOnce(undefined)
.mockImplementationOnce(async () => {
clearActiveGoal('goal-test-session');
return undefined;
});

await drain(
client.sendMessageStream(
[{ text: 'set a goal for this' }],
new AbortController().signal,
'stop-clear-key',
{ type: SendMessageType.UserQuery, getSteerInput },
),
);

expect(turnMocks.run).toHaveBeenCalledOnce();
expect(getSteerInput).toHaveBeenCalledTimes(2);
expect(takePendingGoalProposal).toHaveBeenCalledTimes(2);
expect(runtime.dispatch).toHaveBeenCalledWith({
action: 'create',
objective: 'ship it',
});
});

it('discards an approved proposal when settlement starts already aborted', async () => {
const { client, config, runtime } = setupGoalClient();
const controller = new AbortController();
Expand Down Expand Up @@ -2117,8 +2036,6 @@ describe('LlmClient Goal admission', () => {
);
});

afterEach(() => __resetActiveGoalStoreForTests());

it('admits a runtime Goal turn to steer input at a hit session cap', async () => {
// Second half of the session-cap exclusion: runtime Goal turns skip the
// count increment (pinned by the 75-turn test above) and must also be
Expand All @@ -2143,58 +2060,4 @@ describe('LlmClient Goal admission', () => {

expect(getSteerInput).toHaveBeenCalled();
});

it('does not decrement the caller recursion budget inside a legacy hook Goal chain', async () => {
// A legacy /goal chain recurses inside one sendMessageStream call. With
// the caller budget of 2 preserved at every hop, two blocked stops still
// run three model turns; a decremented budget would refuse the third.
// Unsupported Goal runtime: the legacy hook chain owns the send, so the
// branch under test is the one that keys the budget on the active goal.
const { client, config } = setupGoalClient();
vi.mocked(config.getGoalRuntimeReady).mockRejectedValue(
new GoalPersistenceUnavailableError('legacy-only session'),
);
vi.mocked(config.getSkipNextSpeakerCheck).mockReturnValue(true);
vi.mocked(config.getDisableAllHooks).mockReturnValue(false);
vi.mocked(config.getMaxSessionTurns).mockReturnValue(0);
vi.mocked(config.hasHooksForEvent).mockImplementation(
(event) => event === 'Stop',
);
let stopRequestCount = 0;
const messageBus = {
request: vi.fn(async () => {
stopRequestCount += 1;
if (stopRequestCount <= 2) {
return {
output: { decision: 'block', reason: 'keep going' },
stopHookCount: 1,
};
}
return { output: undefined, stopHookCount: 1 };
}),
};
vi.mocked(config.getMessageBus).mockReturnValue(
messageBus as unknown as ReturnType<Config['getMessageBus']>,
);
setActiveGoal('goal-test-session', {
condition: 'ship',
iterations: 0,
setAt: 1,
tokensAtStart: 0,
hookId: 'goal-hook:test',
});

await drain(
client.sendMessageStream(
[{ text: 'start the chain' }],
new AbortController().signal,
'legacy-goal-chain',
undefined,
2,
),
);

expect(messageBus.request).toHaveBeenCalledTimes(3);
expect(turnMocks.run).toHaveBeenCalledTimes(3);
});
});
Loading
Loading