Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ export function mutateWithChatStop<TValue>(
clientOperationId: envelope.clientOperationId,
...named,
stopChild: () => context.stopAgent(sessionId),
onStopChildError: (error) => context.deps.onEventSinkError?.({ sessionId, error }),
onStopChildError: (error) =>
context.deps.logger.warn('ending the agent after its interrupt failed did not finish', {
scope: 'chat-stop',
sessionId,
error
}),
// The host drops its child only once the exit is proven, and nothing else runs meanwhile.
childReleased: () => context.sessions.get(sessionId)?.child !== child,
endSession: (owed) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
resetHostTestOperationIds
} from './structured-agent-session-host-test-data'
import { openTestJournalHostDatabase } from '../agent-session-journal/journal-host-database-test-support'
import { createStructuredAgentSessionLogger } from './structured-agent-session-logger'
import {
createStructuredAgentSessionLogger,
type StructuredAgentSessionLogger
} from './structured-agent-session-logger'

const CALLER = { callerKey: 'client-1' }

Expand All @@ -42,7 +45,7 @@ let acknowledgeSessionRelease: Mock<
>
/** Codex's answer by default: its Stop keeps the child. */
let stopEndsSession: boolean
let onEventSinkError: Mock<(failure: { sessionId: string; error: unknown }) => void>
let warn: Mock<StructuredAgentSessionLogger['warn']>
let events: StructuredAgentSessionEventSink | undefined

function eventually(assertion: () => void | Promise<void>): Promise<void> {
Expand All @@ -59,10 +62,10 @@ beforeEach(async () => {
closeSession = vi.fn(async () => true)
acknowledgeSessionRelease = vi.fn()
stopEndsSession = false
onEventSinkError = vi.fn()
warn = vi.fn()
store = await openTestAgentSessionRecordStore(root)
host = new StructuredAgentSessionHost({
logger: createStructuredAgentSessionLogger(),
logger: { ...createStructuredAgentSessionLogger(), warn },
store,
adapter: {
acquire: async ({ fence, spawnToken, events: sink }) => {
Expand Down Expand Up @@ -97,7 +100,6 @@ beforeEach(async () => {
journalDatabase: openTestJournalHostDatabase(root),
claimKeyId: 'key-1',
mintSpawnToken: () => 'spawn-1',
onEventSinkError,
now: () => NOW
})
expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true })
Expand Down Expand Up @@ -288,7 +290,10 @@ describe('a Stop that names no turn', () => {
expect(await stop()).toMatchObject({ ok: true, value: { cancelled: false } })

expect(closeSession).toHaveBeenCalledExactlyOnceWith(SESSION, 'user-stop')
expect(onEventSinkError).toHaveBeenCalledWith(expect.objectContaining({ sessionId: SESSION }))
expect(warn).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ scope: 'chat-stop', sessionId: SESSION })
)
expect(await statusRows()).toEqual(["Codex didn't stop: failed to interrupt turn."])
})

Expand All @@ -304,7 +309,10 @@ describe('a Stop that names no turn', () => {
expect(await stop()).toMatchObject({ ok: true, value: { cancelled: true } })

expect(closeSession).toHaveBeenCalledExactlyOnceWith(SESSION, 'user-stop')
expect(onEventSinkError).toHaveBeenCalledWith(expect.objectContaining({ sessionId: SESSION }))
expect(warn).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ scope: 'chat-stop', sessionId: SESSION })
)
expect(await statusRows()).toEqual(['Cancellation requested.'])
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
hostTestOperationId,
resetHostTestOperationIds
} from './structured-agent-session-host-test-data'
import { createStructuredAgentSessionLogger } from './structured-agent-session-logger'

const CALLER = { callerKey: 'client-1' }

Expand All @@ -42,6 +43,7 @@ beforeEach(async () => {
cancelTurn = vi.fn(async () => ({ cancelled: true }))
store = await openTestAgentSessionRecordStore(root)
host = new StructuredAgentSessionHost({
logger: createStructuredAgentSessionLogger(),
store,
adapter: {
acquire: async ({ fence, spawnToken }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
HOST_TEST_THREAD as THREAD
} from './structured-agent-session-host-test-data'
import { startAgent } from './structured-agent-session-restart-interruption-test-harness'
import { createStructuredAgentSessionLogger } from './structured-agent-session-logger'

const REQUESTED = 'Cancellation requested.'

Expand Down Expand Up @@ -101,6 +102,7 @@ describe('a Stop pressed again', () => {
await store.renewLeases([])
const relaunchedStore = await openTestAgentSessionRecordStore(root)
const relaunched = new StructuredAgentSessionHost({
logger: createStructuredAgentSessionLogger(),
store: relaunchedStore,
adapter: adapter(),
journalDatabase: openTestJournalHostDatabase(root),
Expand Down
Loading