Skip to content

The agent that grows with you

fix(api): let the store replay an acknowledged /v1/runs resolve-unknown retry

Tekniumee338b8a4600
diff --git a/gateway/platforms/api_server_authority_runs.py b/gateway/platforms/api_server_authority_runs.py
index 2460efb0469..b4bb66b60c1 100644
--- a/gateway/platforms/api_server_authority_runs.py
+++ b/gateway/platforms/api_server_authority_runs.py
@@ -124,8 +124,8 @@ async def resolve_unknown_run(adapter, run_id, body):
if body['admission_id'] != row['admission_id']:
raise RuntimeStoreError('not_found')
generation = body['execution_generation']
- if row['status'] != 'unknown' or type(generation) is not int or generation != row['generation']:
- raise RuntimeStoreError('stale_generation')
+ # Status/generation are the store's decision (``resolve_unknown_session_input``): it also replays the
+ # committed receipt to an exact retry whose acknowledgement was lost, which a pre-check here refused.
actor = Principal(
'api', authority.profile_id, frozenset({'session:submit', 'session:control'}),
'api-run:' + run_id)
diff --git a/tests/gateway/test_api_unknown_resolution.py b/tests/gateway/test_api_unknown_resolution.py
index b235f1d63f6..b3dc1cbb119 100644
--- a/tests/gateway/test_api_unknown_resolution.py
+++ b/tests/gateway/test_api_unknown_resolution.py
@@ -180,10 +180,15 @@ async def test_http_resolve_unknown_releases_follower_once_without_replaying_hea
assert statuses[unknown["admission_id"]] == ("terminal", "interrupted")
assert statuses[follower["admission_id"]] == ("terminal", "completed")
+ # A lost-ack retry of the exact resolution replays its committed receipt; nothing runs twice.
again = await client.post(path, json=body, headers=_AUTH_HEADERS)
- assert again.status == 409
- assert (await again.json())["error"]["code"] == "stale_generation"
+ assert again.status == 200, await again.text()
+ assert await again.json() == result
+ await owner.sessions["api-session"].task
assert executed == ["FOLLOWER"]
+ stale = await client.post(path, json=body | {"execution_generation": unknown["generation"] + 1},
+ headers=_AUTH_HEADERS)
+ assert stale.status == 409 and (await stale.json())["error"]["code"] == "stale_generation"
finally:
await _close_fixture(client, adapters, store, tasks)
diff --git a/tests/gateway/test_unknown_receipt_boundaries.py b/tests/gateway/test_unknown_receipt_boundaries.py
index ecbcbb3e810..cd1774aec78 100644
--- a/tests/gateway/test_unknown_receipt_boundaries.py
+++ b/tests/gateway/test_unknown_receipt_boundaries.py
@@ -1,34 +1,22 @@
"""Receipt retries preserve transcript boundaries, successor ownership and media identity."""
-
from pathlib import Path
-
-
-
from types import SimpleNamespace
-
-
import pytest
-
-
from gateway.session_authority import LiveSession
-
-
-
from gateway.session_contract import Principal, SessionRef, Submission
-
-
-
from gateway.session_results import admission_result, finish_result
-
-
-
-from hermes_state_runtime import (RuntimeStoreError, admit_session_input, begin_runtime_epoch,
- claim_session_input, get_session_admission, recover_session_inputs)
-
+from hermes_state_runtime import (
+ RuntimeStoreError,
+ admit_session_input,
+ begin_runtime_epoch,
+ claim_session_input,
+ get_session_admission,
+ recover_session_inputs,
+)
@pytest.mark.asyncio