fix(investigation): persist large results and require graph links
Full-network pressure comparisons exceeded the worker limit before saved-result previews could run. Preserve complete calculation results and keep read-time summaries and pagination. Incremental graph publication accepted isolated nodes after flow-authoring rules were lost. Require new steps to connect explicitly while retaining historical snapshots and status-only patches. Regression tests reproduce both failures on the previous code.
This commit is contained in:
@@ -39,6 +39,7 @@ def update_investigation_graph(
|
||||
))
|
||||
|
||||
nodes = {node.node_id: node.model_copy(deep=True) for node in previous.node_refs} if previous else {}
|
||||
saved_ids = set(nodes)
|
||||
require(len({node.node_id for node in update.nodes}) == len(update.nodes),
|
||||
"GRAPH_NODE_DUPLICATE", "Graph update contains duplicate node ids", status=422)
|
||||
for node in update.nodes:
|
||||
@@ -81,6 +82,26 @@ def update_investigation_graph(
|
||||
edges.append(edge.model_copy(deep=True))
|
||||
require(len(nodes) <= 100 and len(edges) <= 200, "GRAPH_CAPACITY_EXCEEDED",
|
||||
"Investigation graph exceeds 100 nodes or 200 edges; existing paths were retained", status=422)
|
||||
# Validate only newly added steps. Historical snapshots and status-only
|
||||
# patches stay valid, even if an earlier publisher omitted relationships.
|
||||
new_ids = set(nodes) - saved_ids
|
||||
if new_ids and len(nodes) > 1:
|
||||
neighbours = {node_id: set() for node_id in nodes}
|
||||
for edge in edges:
|
||||
neighbours[edge.source].add(edge.target)
|
||||
neighbours[edge.target].add(edge.source)
|
||||
connected = set(saved_ids) or {next(iter(nodes))}
|
||||
pending = list(connected)
|
||||
while pending:
|
||||
for node_id in neighbours[pending.pop()] - connected:
|
||||
connected.add(node_id)
|
||||
pending.append(node_id)
|
||||
missing = sorted(new_ids - connected)
|
||||
require(not missing, "GRAPH_RELATION_REQUIRED",
|
||||
"Add explicit edges connecting these new steps to the investigation narrative: "
|
||||
+ ", ".join(missing)
|
||||
+ ". Describe branches, parallel findings or retries; edges do not schedule execution.",
|
||||
status=422)
|
||||
lines = [source or "flowchart TD"]
|
||||
for node in nodes.values():
|
||||
if in_source(node.node_id):
|
||||
|
||||
Reference in New Issue
Block a user