@@ -186,6 +186,11 @@ def generate(self, n_sessions: int = 10) -> dict[str, Any]:
186186 # 5-6 new_info tasks
187187 n_info = self .rng .randint (5 , 6 )
188188 for i in range (n_info ):
189+ # Pull fact_counter ahead of any ids the mixin minted via
190+ # graph._counter so new_info doesn't overwrite a previously
191+ # registered fact (e.g., a version-update fact from
192+ # version_random_facts).
193+ fact_counter = max (fact_counter , graph ._counter )
189194 fact = self ._generate_info_fact (fact_counter , block )
190195 facts_registry .append (fact )
191196
@@ -246,35 +251,35 @@ def generate(self, n_sessions: int = 10) -> dict[str, Any]:
246251 update = self ._generate_update (old_fact , block )
247252 old_fact ["updated" ] = True
248253 block_tasks .append (update )
249- # Update the fact registry with new values
250- new_fact_id = f"fact_{ fact_counter } "
251- facts_registry .append ({
252- "id" : new_fact_id ,
253- "session_block" : block ,
254- "keywords" : update ["new_keywords" ],
255- "recall_question" : old_fact ["recall_question" ],
256- "prompt" : update ["prompt" ],
257- "replaces" : old_fact ["id" ],
258- })
259- # Also update in the FactGraph if the old fact was registered
254+ # Let the FactGraph allocate the new id. Hand-rolling
255+ # `fact_{fact_counter}` here collides with ids the mixin
256+ # already minted via graph._counter (version_random_facts,
257+ # inject_interference), which produces dangling
258+ # replaces/replaced_by pointers.
260259 if old_fact ["id" ] in graph .facts :
261- graph .update_fact (
260+ new_fact = graph .update_fact (
262261 old_id = old_fact ["id" ],
263262 new_content = update ["prompt" ],
264263 new_keywords = update ["new_keywords" ],
265264 session = block ,
266- new_id = new_fact_id ,
267265 )
268266 else :
269- graph .register_fact (
267+ new_fact = graph .register_fact (
270268 session = block ,
271269 domain = self .domain ,
272270 content = update ["prompt" ],
273271 keywords = update ["new_keywords" ],
274- fact_id = new_fact_id ,
275272 )
276- fact_counter += 1
277- graph ._counter = max (graph ._counter , fact_counter )
273+ new_fact_id = new_fact .id
274+ facts_registry .append ({
275+ "id" : new_fact_id ,
276+ "session_block" : block ,
277+ "keywords" : update ["new_keywords" ],
278+ "recall_question" : old_fact ["recall_question" ],
279+ "prompt" : update ["prompt" ],
280+ "replaces" : old_fact ["id" ],
281+ })
282+ fact_counter = max (fact_counter , graph ._counter )
278283
279284 # 1 cross_reference task (if enough facts)
280285 if block >= 1 and len (facts_registry ) >= 4 :
0 commit comments