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 {
|
export interface AssistantCompactionMessageInfo {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
id?: string
|
id?: string
|
||||||
|
parts?: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withTimeout<TValue>(
|
async function withTimeout<TValue>(
|
||||||
@@ -185,6 +186,7 @@ export function createPostCompactionDegradationMonitor(args: {
|
|||||||
sessionID: info.sessionID,
|
sessionID: info.sessionID,
|
||||||
messageID: info.id,
|
messageID: info.id,
|
||||||
directory,
|
directory,
|
||||||
|
parts: info.parts,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!isNoTextTail) {
|
if (!isNoTextTail) {
|
||||||
|
|||||||
@@ -46,8 +46,13 @@ export async function resolveNoTextTailFromSession(args: {
|
|||||||
sessionID: string
|
sessionID: string
|
||||||
messageID?: string
|
messageID?: string
|
||||||
directory: string
|
directory: string
|
||||||
|
parts?: unknown
|
||||||
}): Promise<boolean> {
|
}): Promise<boolean> {
|
||||||
const { client, sessionID, messageID, directory } = args
|
const { client, sessionID, messageID, directory, parts } = args
|
||||||
|
|
||||||
|
if (Array.isArray(parts)) {
|
||||||
|
return isStepOnlyNoTextParts(parts)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await client.session.messages({
|
const response = await client.session.messages({
|
||||||
|
|||||||
@@ -192,4 +192,28 @@ describe("preemptive-compaction post-compaction degradation monitor", () => {
|
|||||||
// then
|
// then
|
||||||
expect(ctx.client.session.summarize).not.toHaveBeenCalled()
|
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
|
modelID?: string
|
||||||
finish?: boolean
|
finish?: boolean
|
||||||
tokens?: TokenInfo
|
tokens?: TokenInfo
|
||||||
|
parts?: unknown
|
||||||
} | undefined
|
} | undefined
|
||||||
|
|
||||||
if (!info || info.role !== "assistant" || !info.finish || !info.sessionID) return
|
if (!info || info.role !== "assistant" || !info.finish || !info.sessionID) return
|
||||||
@@ -92,6 +93,7 @@ export function createPreemptiveCompactionHook(
|
|||||||
await postCompactionMonitor.onAssistantMessageUpdated({
|
await postCompactionMonitor.onAssistantMessageUpdated({
|
||||||
sessionID: info.sessionID,
|
sessionID: info.sessionID,
|
||||||
id: info.id,
|
id: info.id,
|
||||||
|
parts: info.parts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user