fix(agent): preserve lifecycle recovery boundaries (PR3 round 2)

This commit is contained in:
Hypatia May
2026-07-15 17:43:33 +08:00
parent dffe51dbf0
commit d66c926d7a
6 changed files with 151 additions and 42 deletions

View File

@@ -45,6 +45,7 @@ export function registerAutomaticCompaction(
_step: number,
signal: AbortSignal,
) => {
if (signal.aborted) return
try {
const result = await service.compactIfNeeded(agent, 'pressure', signal)
if (result !== null) logResult(result, 'post-step pressure')

View File

@@ -848,6 +848,21 @@ describe('automatic listener and loader composition', () => {
expect(compact.calls).toHaveLength(1)
})
it('skips post-step pressure when the step signal is already aborted', async () => {
const ctx = createContext()
const compact = new TestCompactService(ctx, {
models: { [MODEL]: { thresholdRatio: 0.5, retainTokens: 18 } },
})
const pressured = conversation(4)
const compactIfNeeded = vi.spyOn(compact, 'compactIfNeeded')
await expect(postStep(ctx, agent(pressured, MODEL), AbortSignal.abort('step aborted')))
.resolves.toBeUndefined()
expect(compactIfNeeded).not.toHaveBeenCalled()
expect(pressured.events.some(event => event.type === 'compact/start')).toBe(false)
})
it('warns and continues after operational failures, including non-Errors', async () => {
const ctx = createContext()
const warnings: string[] = []