Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/reactor/src/cycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export interface ConsumedReceiptEdge {
export interface CycleDetectionResult {
readonly cycle_checked: true;
readonly has_cycle: boolean;
/**
* The detected cycle represented as a closed walk array of node content addresses
* (e.g. `[A, B, C, A]`), where the starting node is repeated at the end to record the closing edge.
* If `has_cycle` is false, this array is empty (`[]`).
*/
readonly cycle: readonly ContentAddress[];
}

Expand All @@ -36,6 +41,9 @@ export interface CycleDetectionResult {
* acyclicity check Forme runs over the topology world-model's edges
* (architecture.md §6.3, §3.1). Total and order-stable: the same edge set
* yields the same cycle regardless of input order.
*
* If a cycle is detected, `cycle` returns a closed walk array (e.g., `[A, B, C, A]`)
* where the final element repeats the initial node to explicitly record the closing edge.
*/
export function detectReceiptCycles(
edges: readonly ConsumedReceiptEdge[],
Expand Down Expand Up @@ -270,7 +278,7 @@ function visitCycleNode(

const existingIndex = path.indexOf(node);
if (visiting.has(node) && existingIndex >= 0) {
return [...path.slice(existingIndex), node];
return path.slice(existingIndex);
}

visiting.add(node);
Expand Down