fix(reasoning): preserve ready material question target

This commit is contained in:
2026-08-13 09:36:10 +01:00
parent 854c3aa002
commit 54bc48342b
4 changed files with 705 additions and 12 deletions
+64
View File
@@ -1982,6 +1982,41 @@ function selectPatternCompatibleUnknownCandidate({
]);
}
function hasUnresolvedSameProposalDependsOnPrerequisite({
graph,
proposal,
targetNodeId,
}) {
const addedNodeIds = new Set(
(proposal?.addedNodes || []).map((node) => node.id),
);
if (!addedNodeIds.has(targetNodeId)) return false;
const targetNode = findNodeById(graph, targetNodeId);
if (!targetNode) return false;
const directPrerequisiteIds = new Set();
for (const dependencyId of targetNode.dependsOn || []) {
directPrerequisiteIds.add(dependencyId);
}
for (const edge of graph.edges || []) {
if (
edge.relationship === "depends_on" &&
edge.fromNodeId === targetNodeId &&
edge.toNodeId
) {
directPrerequisiteIds.add(edge.toNodeId);
}
}
return [...directPrerequisiteIds].some(
(nodeId) =>
addedNodeIds.has(nodeId) && isSelectableUnresolvedUnknown(graph, nodeId),
);
}
function collectPatternCompatibilityDiagnostics({
graph,
activePattern,
@@ -3677,6 +3712,35 @@ export function applyValidatedProposal({
const interactionSummary = propagationResult.interactionSummary;
const propagationReason = propagationResult.reason;
// Bounded model-selection honour: prefer a model-selected target only when it
// is still valid, was added in this proposal turn, and has no unresolved
// same-proposal-added unknown prerequisite via depends_on. Otherwise fall
// through to existing deterministic selection unchanged.
if (validatedProposal.selectedQuestion?.nodeId) {
const candidateNodeId = validatedProposal.selectedQuestion.nodeId;
const candidateWasAddedThisProposal = (
validatedProposal.addedNodes || []
).some((node) => node.id === candidateNodeId);
if (
isSelectableUnresolvedUnknown(updatedSituationGraph, candidateNodeId) &&
candidateWasAddedThisProposal &&
!hasUnresolvedSameProposalDependsOnPrerequisite({
graph: updatedSituationGraph,
proposal: validatedProposal,
targetNodeId: candidateNodeId,
})
) {
deterministicSelection = {
status: "selected",
nodeId: candidateNodeId,
reason:
"Honoured the model-selected unresolved unknown as preferred target because it was added in this proposal and has no unresolved same-proposal depends_on prerequisite.",
};
}
}
if (
deterministicSelection?.status === "selected" &&
deterministicSelection?.nodeId