perf(compaction): reuse message update parts for no-text tails
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -43,6 +43,7 @@ interface ClientLike {
|
||||
export interface AssistantCompactionMessageInfo {
|
||||
sessionID: string
|
||||
id?: string
|
||||
parts?: unknown
|
||||
}
|
||||
|
||||
async function withTimeout<TValue>(
|
||||
@@ -185,6 +186,7 @@ export function createPostCompactionDegradationMonitor(args: {
|
||||
sessionID: info.sessionID,
|
||||
messageID: info.id,
|
||||
directory,
|
||||
parts: info.parts,
|
||||
})
|
||||
|
||||
if (!isNoTextTail) {
|
||||
|
||||
@@ -46,8 +46,13 @@ export async function resolveNoTextTailFromSession(args: {
|
||||
sessionID: string
|
||||
messageID?: string
|
||||
directory: string
|
||||
parts?: unknown
|
||||
}): Promise<boolean> {
|
||||
const { client, sessionID, messageID, directory } = args
|
||||
const { client, sessionID, messageID, directory, parts } = args
|
||||
|
||||
if (Array.isArray(parts)) {
|
||||
return isStepOnlyNoTextParts(parts)
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await client.session.messages({
|
||||
|
||||
@@ -192,4 +192,28 @@ describe("preemptive-compaction post-compaction degradation monitor", () => {
|
||||
// then
|
||||
expect(ctx.client.session.summarize).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("uses message update parts without refetching session messages", async () => {
|
||||
// given
|
||||
const sessionHistory: AssistantHistoryMessage[] = []
|
||||
const ctx = createMockCtx(sessionHistory)
|
||||
const hook = createPreemptiveCompactionHook(ctx as never, {} as never)
|
||||
const sessionID = "ses_tail_update_parts"
|
||||
const stepOnlyParts = [{ type: "step-start" }, { type: "step-finish" }]
|
||||
|
||||
await hook.event({
|
||||
event: {
|
||||
type: "session.compacted",
|
||||
properties: { sessionID },
|
||||
},
|
||||
})
|
||||
|
||||
// when
|
||||
await hook.event(buildAssistantUpdate({ sessionID, id: "msg_1", parts: stepOnlyParts }))
|
||||
await hook.event(buildAssistantUpdate({ sessionID, id: "msg_2", parts: stepOnlyParts }))
|
||||
|
||||
// then
|
||||
expect(ctx.client.session.messages).not.toHaveBeenCalled()
|
||||
expect(ctx.client.session.summarize).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -76,6 +76,7 @@ export function createPreemptiveCompactionHook(
|
||||
modelID?: string
|
||||
finish?: boolean
|
||||
tokens?: TokenInfo
|
||||
parts?: unknown
|
||||
} | undefined
|
||||
|
||||
if (!info || info.role !== "assistant" || !info.finish || !info.sessionID) return
|
||||
@@ -92,6 +93,7 @@ export function createPreemptiveCompactionHook(
|
||||
await postCompactionMonitor.onAssistantMessageUpdated({
|
||||
sessionID: info.sessionID,
|
||||
id: info.id,
|
||||
parts: info.parts,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user