The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Revert "fix(gateway): the worker reservation always binds the owner's OS subject"
Tekniume5ea5fd9ccdf
diff --git a/gateway/session_managed_worker.py b/gateway/session_managed_worker.pyindex cf672513369..9a7d81e771a 100644--- a/gateway/session_managed_worker.py+++ b/gateway/session_managed_worker.py@@ -15,7 +15,7 @@ import sysimport timefrom agent.managed_worker import accept_result, encode_frame, read_frame-from gateway.session_worker_reservation import reserve_admission_worker+from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_workerfrom hermes_state_runtime import RuntimeStoreError# The interpreter only imports psutil before it introduces itself; a child silent this long@@ -627,7 +627,8 @@ async def execute_managed(authority, ref, row, policy):# psutil + BEGIN IMMEDIATE: off-loop and retirement-tracked, like admission and claim.from gateway.session_runtime_workers import tracked_writescope = await tracked_write(authority, partial(reserve_admission_worker, authority,- admission_id=row['admission_id'], process=process, principal_id=row['principal_id'], hello=hello))+ admission_id=row['admission_id'], process=process, principal_id=row['principal_id'], hello=hello,+ worker_subject=owner_worker_subject()))worker.worker = (scope['pid'], scope['birth'])# The child reads nothing else until the exact reservation has committed.frame = await asyncio.to_thread(_bootstrap, authority, ref, row, policy, scope, text)diff --git a/gateway/session_worker_reservation.py b/gateway/session_worker_reservation.pyindex 2c2e196ec37..4d996ec261f 100644--- a/gateway/session_worker_reservation.py+++ b/gateway/session_worker_reservation.py@@ -59,22 +59,21 @@ def owner_worker_subject():return f'uid:{os.getuid()}' # windows-footgun: ok — POSIX branch-def reserve_admission_worker(authority, *, admission_id, process, principal_id, hello):+def reserve_admission_worker(authority, *, admission_id, process, principal_id, hello, worker_subject=None):"""Return a private bootstrap scope; never accept caller-selected kind/target.Only the owner process may reserve its live direct exec child. The admissionsupplies physical session and generation; its durable principal must matchthe producer. Do not publish the returned secret on any client event stream.- The adoption claim binds ``owner_worker_subject()``, the only identity a worker ticket can- carry, never the admission's principal: an automation principal is a route- (``automation:<session key>``), not a ticket subject, so a claim bound to it refused every+ The adoption claim binds ``worker_subject``, the identity the worker will authenticate+ as (``owner_worker_subject``), when given. An automation admission's principal is a route+ (``automation:<session key>``), never a ticket subject, so a claim bound to it refused everyadopt and each bot DM or completion wake on a managed session ended interrupted (#144139)."""authority._require_admission_open()pid, birth = verify_worker_identity(process, hello)secret = secrets.token_urlsafe(32)- subject = owner_worker_subject()def write(conn):_epoch(conn, authority.epoch)@@ -101,7 +100,7 @@ def reserve_admission_worker(authority, *, admission_id, process, principal_id,"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': subject})+ claim = admission_fingerprint(canonical_target=sid, payload=scope | {'principal': worker_subject or principal_id})conn.execute("INSERT INTO worker_executions(execution_id,session_id,kind,owner_epoch,generation,status,adoption_digest) ""VALUES(?,?,'compute',?,?,'registered',?)",(execution_id, sid, authority.epoch, generation, _secret_digest(claim)))diff --git a/tests/gateway/test_managed_worker_drain.py b/tests/gateway/test_managed_worker_drain.pyindex 808bf00c4e7..ef411dc261f 100644--- a/tests/gateway/test_managed_worker_drain.py+++ b/tests/gateway/test_managed_worker_drain.py@@ -10,7 +10,7 @@ import pytest@pytest.mark.asyncioasync def test_reserved_worker_persists_while_runtime_drains(tmp_path):from gateway.session_worker import worker_request- from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_worker+ from gateway.session_worker_reservation import reserve_admission_workerfrom tests.gateway.test_worker_admission_reservation import hellofrom hermes_state import SessionDBfrom hermes_state_runtime import admit_session_input, begin_runtime_epoch, claim_session_input, RuntimeStoreError@@ -26,7 +26,7 @@ async def test_reserved_worker_persists_while_runtime_drains(tmp_path):claim_session_input(db, epoch=epoch, session_id='owned')scope = reserve_admission_worker(authority, admission_id=row['admission_id'], process=process,principal_id='human', hello=hello(process))- actor = SimpleNamespace(subject=owner_worker_subject(), profile_id=str(tmp_path), capabilities={'worker:adopt'})+ actor = SimpleNamespace(subject='human', profile_id=str(tmp_path), capabilities={'worker:adopt'})connection = SimpleNamespace(authority=authority, actor=actor)identity = {k: v for k, v in scope.items() if k != 'epoch'}await worker_request(connection, None, identity, operation='adopt')diff --git a/tests/gateway/test_managed_worker_fencing.py b/tests/gateway/test_managed_worker_fencing.pyindex c7f62552905..dd410c3562b 100644--- a/tests/gateway/test_managed_worker_fencing.py+++ b/tests/gateway/test_managed_worker_fencing.py@@ -53,7 +53,7 @@ async def test_late_bootstrap_handshake_cannot_rearm_a_recovered_admission(tmp_p(which refuses the foreign epoch and exits), stranding the FIFO where Discard cannot reach it."""import hermes_state_runtime as rtfrom gateway.session_worker import worker_request- from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_worker+ from gateway.session_worker_reservation import reserve_admission_workerwith closing(SessionDB(tmp_path / 'state.db')) as db:db.create_session('owned', 'cli')epoch = begin_runtime_epoch(db, instance_id='owner')@@ -69,7 +69,7 @@ async def test_late_bootstrap_handshake_cannot_rearm_a_recovered_admission(tmp_prestarted = begin_runtime_epoch(db, instance_id='restarted')rt.recover_session_inputs(db, epoch=restarted)owner = SimpleNamespace(db=db, epoch=restarted, profile_id=str(tmp_path), _require_admission_open=lambda: None)- actor = SimpleNamespace(subject=owner_worker_subject(), profile_id=str(tmp_path), capabilities={'worker:adopt'})+ actor = SimpleNamespace(subject='human', profile_id=str(tmp_path), capabilities={'worker:adopt'})identity = {k: v for k, v in scope.items() if k != 'epoch'}with pytest.raises(rt.RuntimeStoreError, match='stale_epoch'):await worker_request(SimpleNamespace(authority=owner, actor=actor), None, identity, operation='adopt')diff --git a/tests/gateway/test_worker_admission_reservation.py b/tests/gateway/test_worker_admission_reservation.pyindex 245ba6d3130..154093ec8d4 100644--- a/tests/gateway/test_worker_admission_reservation.py+++ b/tests/gateway/test_worker_admission_reservation.py@@ -58,7 +58,7 @@ def test_started_admission_binds_only_exact_owned_process_and_principal(tmp_path@pytest.mark.asyncioasync def test_reserved_process_uses_existing_authenticated_adoption_and_persistence(tmp_path):from gateway.session_worker import worker_request- from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_worker+ from gateway.session_worker_reservation import reserve_admission_workerdb = SessionDB(tmp_path / 'state.db')process = subprocess.Popen([sys.executable, '-c', 'import sys; sys.stdin.read()'], stdin=subprocess.PIPE, # noqa: ASYNC220 -- Popen returns immediately; the test drives the child through its handlestdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)@@ -70,7 +70,7 @@ async def test_reserved_process_uses_existing_authenticated_adoption_and_persistadmitted = admit_session_input(db, epoch=epoch, principal_id='human', session_id='owned', request_id='input', payload={})claim_session_input(db, epoch=epoch, session_id='owned')scope = reserve_admission_worker(authority, admission_id=admitted['admission_id'], process=process, principal_id='human', hello=hello(process))- actor = SimpleNamespace(subject=owner_worker_subject(), profile_id=str(tmp_path), capabilities={'worker:adopt'})+ actor = SimpleNamespace(subject='human', profile_id=str(tmp_path), capabilities={'worker:adopt'})connection = SimpleNamespace(authority=authority, actor=actor)identity = {k: v for k, v in scope.items() if k != 'epoch'}with pytest.raises(Exception, match='permission_denied'):diff --git a/tests/gateway/test_worker_reservation_automation_principal.py b/tests/gateway/test_worker_reservation_automation_principal.pyindex d9a7c026971..fec5825a53a 100644--- a/tests/gateway/test_worker_reservation_automation_principal.py+++ b/tests/gateway/test_worker_reservation_automation_principal.py@@ -51,7 +51,8 @@ async def test_worker_adopts_an_automation_admission_as_the_owner_user(reserved)from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_workerauthority, admitted, process = reservedscope = reserve_admission_worker(authority, admission_id=admitted['admission_id'], process=process,- principal_id=AUTOMATION, hello=_hello(process))+ principal_id=AUTOMATION, hello=_hello(process),+ worker_subject=owner_worker_subject())identity = {k: v for k, v in scope.items() if k != 'epoch'}receipt = await worker_request(_connection(authority, owner_worker_subject()), None, identity, operation='adopt')assert receipt['execution_id'] == scope['execution_id']@@ -60,10 +61,11 @@ async def test_worker_adopts_an_automation_admission_as_the_owner_user(reserved)@pytest.mark.asyncioasync def test_the_claim_still_refuses_any_other_subject(reserved):from gateway.session_worker import worker_request- from gateway.session_worker_reservation import reserve_admission_worker+ from gateway.session_worker_reservation import owner_worker_subject, reserve_admission_workerauthority, admitted, process = reservedscope = reserve_admission_worker(authority, admission_id=admitted['admission_id'], process=process,- principal_id=AUTOMATION, hello=_hello(process))+ principal_id=AUTOMATION, hello=_hello(process),+ worker_subject=owner_worker_subject())identity = {k: v for k, v in scope.items() if k != 'epoch'}for subject in (AUTOMATION, 'uid:999999'):with pytest.raises(Exception, match='permission_denied'):