From 6e70647e699117b44f962b84e332976e241a01e4 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Sat, 23 May 2026 08:09:14 +0200 Subject: [PATCH] fix(db): sort corp-HQ body iteration for determinism (#951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review (Tyre) caught a determinism hole: corp-HQ→city matching iterated a Python set (sys_body_ids), so on a name collision across bodies in the same system, which row received corp_id depended on set order — nondeterministic output landing in the committed DB (violates D-010 #4). Iterate sorted(). Co-Authored-By: Claude Opus 4.7 (1M context) --- tooling/economy-db/import_economics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tooling/economy-db/import_economics.py b/tooling/economy-db/import_economics.py index be7c80887..3c055fb19 100755 --- a/tooling/economy-db/import_economics.py +++ b/tooling/economy-db/import_economics.py @@ -1374,7 +1374,9 @@ def populate_atlas_city_names_corps(conn: sqlite3.Connection, dry_run: bool) -> # Try to find a matching atlas_city_names row in the same system body_ids_in_sys = sys_body_ids.get(headquarters_system, set()) match_id: int | None = None - for body_id in body_ids_in_sys: + # sorted() for determinism: on a name collision across bodies in the + # same system, set iteration order is not stable (D-010 #4). + for body_id in sorted(body_ids_in_sys): key = (body_id, city_name.lower()) if key in existing: match_id = existing[key]