fix(native-chat): rotate settled handoff operations

This commit is contained in:
Brennan Benson
2026-08-12 17:04:49 -07:00
parent 7f4a1d13f7
commit d82d807180
6 changed files with 160 additions and 5 deletions
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'
import type { AgentSessionWireRefusalCode } from './agent-session-wire'
import { agentSessionRefusalOperationState } from './agent-session-refusal-retry'
const HANDOFF_SETTLED_CODES = [
'structured_agent_session_unsupported',
'agent_session_checkpoint_stale',
'agent_session_conflict',
'agent_session_operation_conflict'
] as const satisfies readonly AgentSessionWireRefusalCode[]
describe('agentSessionRefusalOperationState', () => {
it.each(HANDOFF_SETTLED_CODES)('classifies handoff %s as settled', (code) => {
expect(agentSessionRefusalOperationState('agentSession.requestHandoff', code)).toBe(
'settled-rejected'
)
})
it.each(['agentSession.setOption', 'agentSession.send'])(
'keeps %s admission refusals pending',
(method) => {
for (const code of HANDOFF_SETTLED_CODES) {
expect(agentSessionRefusalOperationState(method, code)).toBe('pending-admission')
}
}
)
})
+10
View File
@@ -3,8 +3,18 @@ import type { AgentSessionWireRefusalCode } from './agent-session-wire'
export type AgentSessionRefusalOperationState = 'settled-rejected' | 'pending-admission' | 'unknown'
export function agentSessionRefusalOperationState(
method: string,
code: AgentSessionWireRefusalCode
): AgentSessionRefusalOperationState {
if (method === 'agentSession.requestHandoff') {
switch (code) {
case 'structured_agent_session_unsupported':
case 'agent_session_checkpoint_stale':
case 'agent_session_conflict':
case 'agent_session_operation_conflict':
return 'settled-rejected'
}
}
switch (code) {
case 'agent_session_operation_invalid':
case 'agent_session_item_revision_stale':