fix(compact): address manual compaction review

This commit is contained in:
Hypatia May
2026-07-30 22:00:34 +08:00
parent df0c108e1b
commit db1cbf0bcc
16 files changed
+130 -24

No files matched your search

+21 -5
View File
@@ -79,9 +79,25 @@ async function executeCompact(
* @param ctx - context carrying the command registry and the compaction seam.
*/
export function apply(ctx: Context): void {
ctx.commands.register({
name: 'compact',
description: 'Compact older conversation history',
handler: invocation => executeCompact(ctx, invocation),
})
const active = new Set<Promise<CommandResult>>()
const handler = (invocation: CommandInvocation): Promise<CommandResult> => {
const operation = executeCompact(ctx, invocation)
active.add(operation)
const retire = (): void => { active.delete(operation) }
// Both branches retire without rethrowing, so the derived observer promise
// cannot become an unhandled mirror of an expected handler rejection.
void operation.then(retire, retire)
return operation
}
ctx.effect(function* () {
// Yield drain before registration: composite teardown is LIFO, so no new
// invocation can enter while already-started handler promises quiesce.
yield async () => { await Promise.allSettled(active) }
yield ctx.commands.register({
name: 'compact',
description: 'Compact older conversation history',
handler,
})
}, 'command-compact lifecycle')
}