fix(reasoning): preserve ready material question target
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user