Skip to content

The agent that grows with you

fix: compose main's DELETE already_absent with the exact-retry receipt contract

Teknium971fa6c25992
diff --git a/hermes_cli/web_routers/sessions.py b/hermes_cli/web_routers/sessions.py
index d6599d43915..c1dcf4f92aa 100644
--- a/hermes_cli/web_routers/sessions.py
+++ b/hermes_cli/web_routers/sessions.py
@@ -850,7 +850,9 @@ async def delete_session_endpoint(session_id: str, request: Request, profile: Op
except HTTPException as exc:
# Already-absent is an idempotent success: the desktop optimistically removes the row
# and RESTORES it on any error, so a 404 resurrected ghost rows (a row deleted by
- # another client between the sidebar snapshot and this DELETE).
+ # another client between the sidebar snapshot and this DELETE). An exact retry of the
+ # caller's own committed request never reaches here: mutate_session checks the receipt
+ # before resolving the id, so it replays that receipt (or 409s on a changed digest).
if exc.status_code == 404 and exc.detail == 'not_found':
return {"ok": True, "already_absent": True}
raise
diff --git a/tests/gateway/test_session_mutation_retirement.py b/tests/gateway/test_session_mutation_retirement.py
index 82044f405e1..e688ed2848e 100644
--- a/tests/gateway/test_session_mutation_retirement.py
+++ b/tests/gateway/test_session_mutation_retirement.py
@@ -41,10 +41,13 @@ def test_native_delete_exact_retry_survives_owner_restart(tmp_path):
assert retry.status_code == 200 and retry.json() == receipt, retry.text
changed = client.delete(path, params=params | {'expected_revision': 99}, headers=headers(ticket(home, descriptor)))
assert changed.status_code == 409 and 'admission_conflict' in changed.text
+ # Without this principal's exact receipt, a delete of the gone id is main's idempotent
+ # ``already_absent`` (Desktop ghost-row contract, #48641): never the receipt, never a write.
+ absent = {'ok': True, 'already_absent': True}
fresh = client.delete(path, params=params | {'request_id': 'different'}, headers=headers(ticket(home, descriptor)))
- assert fresh.status_code != 200
+ assert fresh.status_code == 200 and fresh.json() == absent, fresh.text
foreign = client.delete(path, params=params, headers={'Authorization': 'Bearer normal-http-owner'})
- assert foreign.status_code != 200
+ assert foreign.status_code != 200 or foreign.json() == absent, foreign.text
print(json.dumps({'native_delete_restart': receipt, 'changed_retry': changed.json(),
'fresh_request_status': fresh.status_code, 'foreign_status': foreign.status_code}))
diff --git a/tests/gateway/test_used_delete_restart.py b/tests/gateway/test_used_delete_restart.py
index 95f5a515754..222d41ce90c 100644
--- a/tests/gateway/test_used_delete_restart.py
+++ b/tests/gateway/test_used_delete_restart.py
@@ -121,7 +121,9 @@ def test_used_api_and_native_delete_restart_exact_retry(tmp_path):
changed = client.delete(path, params=params | {'expected_revision': 999}, headers=native_headers(ticket(home, desc)))
assert changed.status_code == 409 and 'admission_conflict' in changed.text
foreign = client.delete(path, params=params, headers={'Authorization': 'Bearer foreign-dashboard-owner'})
- assert foreign.status_code != 200, foreign.text
+ # Another principal never replays this receipt; for the gone id it gets main's
+ # idempotent ``already_absent`` (Desktop ghost-row contract, #48641) at most.
+ assert foreign.status_code != 200 or foreign.json() == {'ok': True, 'already_absent': True}, foreign.text
assert asyncio.run(api_request()) == first
asyncio.run(stale_native(desc, native_sid))
with sqlite3.connect(home / 'state.db') as db: