fix: report AgentExecutionBlocked in non-interactive programmatic modes (#26262)

This commit is contained in:
Coco Sheng
2026-04-30 16:41:35 -04:00
committed by GitHub
parent a03ec92436
commit 2f0c7518ad
11 changed files with 488 additions and 24 deletions
@@ -378,7 +378,7 @@ describe('translateEvent', () => {
expect(err.type).toBe('error');
expect(err.fatal).toBe(false);
expect(err._meta?.['code']).toBe('AGENT_EXECUTION_BLOCKED');
expect(err.message).toBe('Agent execution blocked: Policy violation');
expect(err.message).toBe('Policy violation');
});
it('uses systemMessage in the final error message when available', () => {
@@ -393,9 +393,7 @@ describe('translateEvent', () => {
};
const result = translateEvent(event, state);
const err = result[0] as AgentEvent<'error'>;
expect(err.message).toBe(
'Agent execution blocked: Blocked by policy hook',
);
expect(err.message).toBe('Blocked by policy hook');
});
});
+1 -1
View File
@@ -210,7 +210,7 @@ export function translateEvent(
out.push(
makeEvent('error', state, {
status: 'PERMISSION_DENIED',
message: `Agent execution blocked: ${event.value.systemMessage?.trim() || event.value.reason}`,
message: event.value.systemMessage?.trim() || event.value.reason,
fatal: false,
_meta: { code: 'AGENT_EXECUTION_BLOCKED' },
}),
@@ -647,7 +647,7 @@ describe('LegacyAgentSession', () => {
e.type === 'error' && e._meta?.['code'] === 'AGENT_EXECUTION_BLOCKED',
);
expect(blocked?.fatal).toBe(false);
expect(blocked?.message).toBe('Agent execution blocked: Blocked by hook');
expect(blocked?.message).toBe('Blocked by hook');
const messages = events.filter(
(e): e is AgentEvent<'message'> =>