-- Bridges research artifacts into loops. A loop can be "based on" a -- published research topic; each iteration prepends the artifact -- markdown to the coordinator prompt so the team executes ONE -- integration item per iteration (INT-XX from the integrations outcome). -- -- source_research_topic_id — nullable pointer. When set, the loop's -- enqueue path re-reads the topic's latest outcome and prepends it -- as context. NULL means "standalone loop" (legacy behavior). -- -- consumed_int_ids — free-form list of INT-XX ids the loop has already -- completed. Advances when topology_worker parses "COMPLETED: INT-XX" -- markers out of the run's final output. Coordinator uses this to -- pick the NEXT unconsumed item. -- -- current_int_index — monotonic pointer for order-sequential iteration -- ("option b" in the design discussion). Coordinator addresses -- INT- unless it has unmet prereqs, in which case it -- works on the smallest unblocking INT-XX and logs the reorder -- rationale to run_events. ALTER TABLE loops ADD COLUMN source_research_topic_id UUID REFERENCES research_topics (id) ON DELETE SET NULL, ADD COLUMN consumed_int_ids TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[], ADD COLUMN current_int_index INT NOT NULL DEFAULT 0; CREATE INDEX loops_source_research_idx ON loops (source_research_topic_id) WHERE source_research_topic_id IS NOT NULL;