mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
fix(plugins): pass session context to before_compaction hook in subscribe handler
The handleAutoCompactionStart handler was calling runBeforeCompaction with only messageCount and an empty hook context. Plugins receiving this hook could not identify the session or snapshot the transcript during auto-compaction. The other call site in compact.ts already passes the full payload (messages, sessionFile, sessionKey). This aligns the subscribe handler to do the same using ctx.params.session and ctx.params.sessionKey.
This commit is contained in:
@@ -24,8 +24,12 @@ export function handleAutoCompactionStart(ctx: EmbeddedPiSubscribeContext) {
|
||||
.runBeforeCompaction(
|
||||
{
|
||||
messageCount: ctx.params.session.messages?.length ?? 0,
|
||||
messages: ctx.params.session.messages,
|
||||
sessionFile: ctx.params.session.sessionFile,
|
||||
},
|
||||
{
|
||||
sessionKey: ctx.params.sessionKey,
|
||||
},
|
||||
{},
|
||||
)
|
||||
.catch((err) => {
|
||||
ctx.log.warn(`before_compaction hook failed: ${String(err)}`);
|
||||
|
||||
@@ -41,7 +41,11 @@ describe("compaction hook wiring", () => {
|
||||
hookMocks.runner.hasHooks.mockReturnValue(true);
|
||||
|
||||
const ctx = {
|
||||
params: { runId: "r1", session: { messages: [1, 2, 3] } },
|
||||
params: {
|
||||
runId: "r1",
|
||||
sessionKey: "agent:main:web-abc123",
|
||||
session: { messages: [1, 2, 3], sessionFile: "/tmp/test.jsonl" },
|
||||
},
|
||||
state: { compactionInFlight: false },
|
||||
log: { debug: vi.fn(), warn: vi.fn() },
|
||||
incrementCompactionCount: vi.fn(),
|
||||
@@ -53,10 +57,16 @@ describe("compaction hook wiring", () => {
|
||||
expect(hookMocks.runner.runBeforeCompaction).toHaveBeenCalledTimes(1);
|
||||
|
||||
const beforeCalls = hookMocks.runner.runBeforeCompaction.mock.calls as unknown as Array<
|
||||
[unknown]
|
||||
[unknown, unknown]
|
||||
>;
|
||||
const event = beforeCalls[0]?.[0] as { messageCount?: number } | undefined;
|
||||
const event = beforeCalls[0]?.[0] as
|
||||
| { messageCount?: number; messages?: unknown[]; sessionFile?: string }
|
||||
| undefined;
|
||||
expect(event?.messageCount).toBe(3);
|
||||
expect(event?.messages).toEqual([1, 2, 3]);
|
||||
expect(event?.sessionFile).toBe("/tmp/test.jsonl");
|
||||
const hookCtx = beforeCalls[0]?.[1] as { sessionKey?: string } | undefined;
|
||||
expect(hookCtx?.sessionKey).toBe("agent:main:web-abc123");
|
||||
});
|
||||
|
||||
it("calls runAfterCompaction when willRetry is false", () => {
|
||||
|
||||
Reference in New Issue
Block a user