Skip to content

The agent that grows with you

fix: record physical admission assignment before later compression

Teknium7b9dc45444f3
diff --git a/gateway/session_worker_reservation.py b/gateway/session_worker_reservation.py
index 4405e596bd0..e9f3461532a 100644
--- a/gateway/session_worker_reservation.py
+++ b/gateway/session_worker_reservation.py
@@ -80,6 +80,9 @@ def reserve_admission_worker(authority, *, admission_id, process, principal_id,
# The private worker fence follows its physical assignment; admission/FIFO
# generation and identity remain on the logical owner.
conn.execute('UPDATE sessions SET runtime_generation=? WHERE id=?', (generation, sid))
+ if sid != owner:
+ conn.execute("UPDATE session_admissions SET lineage_json=json_insert(lineage_json,'$[#]',?) "
+ "WHERE admission_id=?", (sid, admission_id))
scope = dict(profile_id=authority.profile_id, session_id=sid, execution_id=execution_id,
generation=generation, pid=pid, birth=birth, secret=secret)
claim = admission_fingerprint(canonical_target=sid, payload=scope | {'principal': principal_id})
diff --git a/tests/gateway/test_managed_worker_lineage.py b/tests/gateway/test_managed_worker_lineage.py
index 66374a84944..1ee930fb5e6 100644
--- a/tests/gateway/test_managed_worker_lineage.py
+++ b/tests/gateway/test_managed_worker_lineage.py
@@ -100,6 +100,8 @@ def test_worker_lineage_and_settlement(tmp_path, mode, invariant):
assert 'AFTER_RESET' in json.dumps(snap['messages'])
assert query("SELECT session_id FROM messages WHERE role='user' AND content LIKE '%AFTER_RESET%'") == [(target,)]
assert query('SELECT DISTINCT target_session_id FROM session_admissions') == [(sid,)]
+ if mode != 'normal':
+ assert query("SELECT json_extract(lineage_json,'$[#-1]') FROM session_admissions WHERE request_id='after'") == [(target,)]
else:
await asyncio.sleep(.5)
rows = query("SELECT id FROM messages WHERE session_id=? AND role='user'", (target,))