fix(codex): wait for manual compaction to finish (#1038)

* test: reproduce issue #982

* fix: wait for Codex manual compaction (closes #982)

* test: cover Codex compaction turn completion
This commit is contained in:
SSU-WEI HUANG
2026-07-16 12:30:04 +08:00
committed by GitHub
parent c87720ab4d
commit 553b3492f1
4 changed files with 259 additions and 2 deletions
@@ -833,6 +833,29 @@ describe('AppServerEventConverter', () => {
]);
});
it('maps completed contextCompaction items and preserves the turn boundary', () => {
const converter = new AppServerEventConverter();
const events = converter.handleNotification('item/completed', {
threadId: 'thread-1',
turnId: 'turn-compact',
item: { id: 'compact-item-1', type: 'contextCompaction' }
});
expect(events).toEqual([
{
type: 'thread_compacted',
thread_id: 'thread-1',
turn_id: 'turn-compact',
await_turn_completion: true
},
{
type: 'context_compacted',
thread_id: 'thread-1',
turn_id: 'turn-compact'
}
]);
});
it('ignores compacted notifications without thread ids', () => {
const converter = new AppServerEventConverter();
@@ -866,6 +866,23 @@ export class AppServerEventConverter {
return events;
}
if (itemType === 'contextcompaction') {
if (method === 'item/completed') {
const threadId = asString(eventScope.thread_id);
const turnId = asString(eventScope.turn_id);
if (threadId) {
events.push({
type: 'thread_compacted',
thread_id: threadId,
...(turnId ? { turn_id: turnId } : {}),
await_turn_completion: true
});
events.push(scoped({ type: 'context_compacted' }));
}
}
return events;
}
if (itemType === 'agentmessage') {
if (method === 'item/completed') {
if (this.completedAgentMessageItems.has(itemId)) {