fix(agy): separate model and effort selection (#2244)

* fix(agy): separate model families and reasoning effort

* fix(agy): report startup before model discovery
This commit is contained in:
SSU-WEI HUANG
2026-10-30 07:36:13 +08:00
committed by GitHub
parent 75aa3d929a
commit 5fcd4a067a
31 changed files with 906 additions and 98 deletions
+64
View File
@@ -170,6 +170,70 @@ function triggerIncomingUserMessage(
})
}
describe('ApiSessionClient input buffered during initialization', () => {
function message(text: string, localId: string, seq: number) {
return {
id: `message-${seq}`, seq, localId,
content: { role: 'user', content: { type: 'text', text }, meta: { sentFrom: 'webapp' } },
}
}
it.each([false, true])('cancels buffered input before a user-message handler is ready (callback=%s)', async (withCallback) => {
socketHarness.sockets.length = 0
const client = new ApiSessionClient('token', createSession({ namespace: 'default' }))
const socket = socketHarness.sockets[0]!
const update = socket.listeners.get('update')![0]!
const cancel = vi.fn(() => false)
if (withCallback) client.onCancelQueuedMessage(cancel)
await update({ body: { t: 'new-message', message: message('cancel me', 'local-1', 1) } })
await update({ body: { t: 'new-message', message: message('keep me', 'local-2', 2) } })
const ack = vi.fn()
await update({ body: { t: 'cancel-queued-message', localId: 'local-1' } }, ack)
expect(ack).toHaveBeenCalledWith({ removed: true, inFlight: false, indeterminate: false, consumed: false })
expect(cancel).not.toHaveBeenCalled()
const onMessage = vi.fn()
client.onUserMessage(onMessage)
expect(onMessage).toHaveBeenCalledTimes(1)
expect(onMessage).toHaveBeenCalledWith(expect.objectContaining({ content: { type: 'text', text: 'keep me' } }), 'local-2')
client.close()
})
it.each([false, true])('replaces buffered input on retry without flushing twice (callback=%s)', async (withCallback) => {
socketHarness.sockets.length = 0
const client = new ApiSessionClient('token', createSession({ namespace: 'default' }))
const socket = socketHarness.sockets[0]!
const update = socket.listeners.get('update')![0]!
const cancel = vi.fn(() => 'consumed' as const)
if (withCallback) client.onCancelQueuedMessage(cancel)
await update({ body: { t: 'new-message', message: message('original', 'local-1', 1) } })
const ack = vi.fn()
await update({ body: { t: 'retry-queued-message', localId: 'local-1', message: message('replacement', 'local-1', 1) } }, ack)
expect(ack).toHaveBeenCalledWith({ removed: false, accepted: true })
expect(cancel).not.toHaveBeenCalled()
const onMessage = vi.fn()
client.onUserMessage(onMessage)
expect(onMessage).toHaveBeenCalledTimes(1)
expect(onMessage).toHaveBeenCalledWith(expect.objectContaining({ content: { type: 'text', text: 'replacement' } }), 'local-1')
client.close()
})
it.each(['in-flight', 'consumed', 'indeterminate'] as const)('keeps %s cancellation semantics after input leaves the buffer', async (result) => {
socketHarness.sockets.length = 0
const client = new ApiSessionClient('token', createSession({ namespace: 'default' }))
const update = socketHarness.sockets[0]!.listeners.get('update')![0]!
const cancel = vi.fn(async () => result)
client.onCancelQueuedMessage(cancel)
const ack = vi.fn()
await update({ body: { t: 'cancel-queued-message', localId: 'local-1' } }, ack)
expect(cancel).toHaveBeenCalledWith('local-1')
expect(ack).toHaveBeenCalledWith({
removed: false, inFlight: result === 'in-flight', indeterminate: result === 'indeterminate', consumed: result === 'consumed',
})
client.close()
})
})
describe('ApiSessionClient lazy materialization', () => {
it('does not connect or materialize without a real user message', async () => {
socketHarness.sockets.length = 0
+13 -4
View File
@@ -467,8 +467,8 @@ export class ApiSessionClient extends EventEmitter {
// Explicit user retry: release any held in-memory
// reservation and bypass the normal message-id dedup.
let accepted = true
if (data.body.localId && this.cancelQueuedMessageCallback) {
const cancellation = this.cancelQueuedMessageCallback(data.body.localId)
if (data.body.localId) {
const cancellation = this.cancelQueuedMessage(data.body.localId)
const cancelled = cancellation instanceof Promise ? await cancellation : cancellation
accepted = cancelled !== 'in-flight' && cancelled !== 'consumed'
if (cancelled === 'indeterminate') {
@@ -487,8 +487,8 @@ export class ApiSessionClient extends EventEmitter {
}
if (data.body.t === 'cancel-queued-message') {
const cancellation = (data.body.localId && this.cancelQueuedMessageCallback)
? this.cancelQueuedMessageCallback(data.body.localId)
const cancellation = data.body.localId
? this.cancelQueuedMessage(data.body.localId)
: false
const result = cancellation instanceof Promise ? await cancellation : cancellation
// 'in-flight' = the row is inside an async steer: not
@@ -737,6 +737,15 @@ export class ApiSessionClient extends EventEmitter {
this.retryQueuedMessageCallback = callback
}
private cancelQueuedMessage(localId: string): QueueCancelResult | Promise<QueueCancelResult> {
const remaining = this.pendingMessages.filter((pending) => pending.localId !== localId)
if (remaining.length !== this.pendingMessages.length) {
this.pendingMessages = remaining
return true
}
return this.cancelQueuedMessageCallback?.(localId) ?? false
}
private enqueueUserMessage(message: UserMessage, localId?: string): void {
if (this.pendingMessageCallback) {
this.pendingMessageCallback(message, localId)