test(confidence-engine): align deep investigation episode seam
This commit is contained in:
@@ -268,7 +268,7 @@ async function runLiveExperiment({ graph, previousQuestion, answer, findings = [
|
||||
* - currentUnderstanding from the synthesis result
|
||||
* - findingsCheckpoint with accurate post-episode accumulated findings count
|
||||
*/
|
||||
async function composeDeepInvestigationCheckpoint({ situationGraph, previousQuestion, answer, findings = [] }) {
|
||||
async function composeDeepInvestigationCheckpoint({ situationGraph, previousQuestion, answer, findings = [], targetNodeId, episodeMode }) {
|
||||
dotenv.config({ path: ".env.local" });
|
||||
|
||||
const baseUrl = assertRequiredEnv("OLLAMA_BASE_URL");
|
||||
@@ -282,7 +282,7 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
|
||||
}
|
||||
|
||||
/* ── Step 1: episode done (mirrors executeEpisodeDone server seam) ─── */
|
||||
const { updateCase } = await import(
|
||||
const { updateCase, reconsiderCompletedEpisode } = await import(
|
||||
"../../lib/graph/orchestrator.js"
|
||||
);
|
||||
const { getProvider } = await import("../../lib/llm/provider.js");
|
||||
@@ -302,10 +302,64 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
|
||||
};
|
||||
|
||||
const endToEndStartedAt = Date.now();
|
||||
const episodeResult = await updateCase(
|
||||
{ situationGraph, previousQuestion, answer },
|
||||
{ provider: timedProvider },
|
||||
);
|
||||
|
||||
let episodeResult;
|
||||
|
||||
/* ── Production-equivalent focused-episode seam: targetNodeId triggers the same path as executeEpisodeDone → handleEpisodeMode ─── */
|
||||
if (episodeMode === true && targetNodeId) {
|
||||
// Mirrors produceEpisodeAwareGraph: prepareCompletedEpisode → reconsiderCompletedEpisode → applyValidatedProposal
|
||||
const { prepareCompletedEpisode } = await import("../../lib/graph/episode-preparation.js");
|
||||
const { applyValidatedProposal } = await import("../../lib/graph/apply-proposal.js");
|
||||
|
||||
const prepared = prepareCompletedEpisode({
|
||||
situationGraph,
|
||||
targetNodeId,
|
||||
contributions: [], // no focused contributions in checkpoint helper (mirrors production when called without explicit contributions)
|
||||
findings,
|
||||
});
|
||||
|
||||
if (!prepared?.turns?.length && !prepared?.eligibleCanonicalFindings?.length) {
|
||||
throw new Error("no_episodic_content: prepared episode has no turns or eligible findings");
|
||||
}
|
||||
|
||||
const reasoning = await reconsiderCompletedEpisode(prepared);
|
||||
if (!reasoning.success) {
|
||||
throw new Error(`reconsiderCompletedEpisode failed: ${reasoning.error}`);
|
||||
}
|
||||
|
||||
const application = await applyValidatedProposal({
|
||||
situationGraph,
|
||||
proposal: reasoning.proposal,
|
||||
evidenceContext: {
|
||||
isCompletedEpisode: true,
|
||||
episodeEvidence: prepared,
|
||||
},
|
||||
});
|
||||
|
||||
if (!application.success) {
|
||||
throw new Error(`applyValidatedProposal failed: ${application.error}`);
|
||||
}
|
||||
|
||||
const resolvedNodeIds = new Set(application.updatedSituationGraph.resolvedNodeIds ?? []);
|
||||
resolvedNodeIds.add(targetNodeId);
|
||||
|
||||
episodeResult = {
|
||||
success: true,
|
||||
updatedSituationGraph: {
|
||||
...application.updatedSituationGraph,
|
||||
resolvedNodeIds: [...resolvedNodeIds],
|
||||
},
|
||||
appendedFindings: [], // no regular update findings in episode path
|
||||
proposal: reasoning.proposal,
|
||||
};
|
||||
} else {
|
||||
const result = await updateCase(
|
||||
{ situationGraph, previousQuestion, answer },
|
||||
{ provider: timedProvider },
|
||||
);
|
||||
episodeResult = result;
|
||||
}
|
||||
|
||||
const endToEndElapsedMs = Date.now() - endToEndStartedAt;
|
||||
|
||||
/* ── Step 2: Current Understanding synthesis (mirrors production synthesizeFn) ─── */
|
||||
|
||||
Reference in New Issue
Block a user