fix(coding-agent/hindsight): reacted to live bank scope changes and flushed before dispose
Mid-session edits to hindsight.bankId / bankIdPrefix / scoping kept the active HindsightSessionState pinned to the bank selected at session start, so retain/recall/reflect calls landed in the stale bank. Settings hooks now fire onHindsightScopeChanged; the backend rebuilds the primary state against the recomputed scope, disposing the previous one after flushing its queue so queued tool-initiated retains still land in the bank they were enqueued for. Also: - Renamed ensureBankMission to ensureBankExists. The old version skipped creation entirely when bankMission was blank, so the first mental-model POST (auto-seed) could land against a never-PUT bank. Bank creation is now idempotent and unconditional, and runs before mental-model bootstrap. - Fixed AgentSession.dispose to flush the retain queue BEFORE clearing the session state pointer. Reversed, HindsightRetainQueue.#doFlush's identity guard would see the cleared pointer and drop the spliced batch with a 'session vanished' warning. - Snapshotted hindsightScopeCallbacks before iterating because each rebuild subscribes a fresh callback inside the same fire; iterating the live Set would spin. Fixes #1902
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
||||
import { logger, untilAborted } from "@oh-my-pi/pi-utils";
|
||||
import * as z from "zod/v4";
|
||||
import { ensureBankMission } from "../hindsight/bank";
|
||||
import { ensureBankExists } from "../hindsight/bank";
|
||||
import reflectDescription from "../prompts/tools/reflect.md" with { type: "text" };
|
||||
import type { ToolSession } from ".";
|
||||
|
||||
@@ -67,7 +67,7 @@ export class MemoryReflectTool implements AgentTool<typeof memoryReflectSchema>
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureBankMission(state.client, state.bankId, state.config, state.missionsSet);
|
||||
await ensureBankExists(state.client, state.bankId, state.config, state.banksSet);
|
||||
const response = await state.client.reflect(state.bankId, params.query, {
|
||||
context: params.context,
|
||||
budget: state.config.recallBudget,
|
||||
|
||||
Reference in New Issue
Block a user