Repository navigation
Description
Problem and impact
An exec session can end without a durable closing audit event. ExecSessionRegistry.ended removes the session from its in-memory registry before attempting the tenant audit transaction. If that transaction fails, it logs an error and forgets the pending write. Recovery of the database does not retry the event.
This leaves a recorded session opening without a reliably recorded end and weakens the project's audit guarantee. Closing a connection cannot be rolled back like an HTTP mutation; the lifecycle therefore needs an explicit durable recovery policy.
Priority: P2, from the 2026-11-25 architecture audit of main 1295e534d7a1c3cd0a492449de8806aa532a4924. Related feature: #232; audit guarantees: #23. This is distinct from the transport/input issues #478 and #479.
Evidence and reproduction
- The process-local registry owns active sessions in memory.
- The ending path deletes the relay, attempts the audit write once, catches failure, then removes that write from its pending set.
- Shutdown settlement only waits for the existing promises; it is not a persistent retry mechanism.
A bounded unit probe used the actual registry with a transaction adapter that initially rejected writes:
- Register a session and end it with
browser_leftwhile the adapter reports storage unavailable. - Observe that the session is absent, one transaction was attempted, and no event was published.
- Restore the adapter, advance the fake clock by five minutes, then invoke shutdown and settlement.
- Observe that the transaction attempt count remains one and the event is still absent.
This reproduces the missing retry in isolation. It did not crash a real API process or interrupt a real PostgreSQL server. An abrupt process exit also loses the in-memory lifecycle, but its end time/reason cannot necessarily be recovered exactly.
Proposed correction
Persist enough session lifecycle information to reconcile unfinished sessions after a write failure or restart. Define retryable, idempotent recording of known endings and an explicit interrupted/unknown outcome for sessions whose exact ending cannot be observed. Keep the live connection cleanup bounded even when storage is down; do not keep the shell alive merely to wait for audit storage.
Acceptance criteria
- A transient audit-write failure followed by storage recovery eventually produces one durable closing outcome for the session.
- Restart reconciliation identifies orphaned sessions and records a truthful interrupted/unknown outcome where necessary.
- Duplicate endings and retries do not create contradictory or duplicate logical lifecycle records.
- Closure, revocation and shutdown still release transport resources promptly during storage failure.
- Tests cover successful closure, transient write failure, retry, duplicate callbacks and restart reconciliation.
- Persisted lifecycle data and diagnostics contain identifiers and necessary metadata only, never terminal input/output or secrets.
Publication check: main advanced to 2ee78ff1e96118b1732b98bc54c99f5f91b95a32 through #469, which changes only an exec-session test. The production paths above are unchanged.
Activity
fix(api): every exec session gets exactly one recorded closing (closes …
samuelmbabhazi commentedon Nov 27, 2026
Reopening for a remaining P3 concurrency gap in the existing acceptance criterion: “Duplicate endings and retries do not create contradictory or duplicate logical lifecycle records.” This is a follow-up to this issue, not a duplicate issue or a claim that the original durability fix failed.
At main deff5f6, retries and durable reconciliation address the original missing-closing-event problem. However, recovery checks read closed() and then publish in separate steps, without an atomic per-session closing claim. Two concurrent checks can both observe no closure and publish distinct interrupted events.
A plausible overlap exists because startup registers the worker before sweeping queued jobs: the worker can claim a job after the sweep selected it. Ending retries also use a check-then-publish sequence, allowing another reconciliation overlap.
A bounded local probe ran the real check/registry classes with fake transaction, reader and event ports. A barrier made two concurrent checks both read an empty closing-event history; both published exec.session.interrupted, with distinct event IDs and the same session target. This demonstrates the command-level race, not a PostgreSQL/process-restart reproduction. No live TLS, shell, load or storage outage was tested.
Impact is audit reliability: duplicate logical closure records, potentially conflicting outcomes in other overlap schedules. No privilege escalation, continued exec access or renewed complete loss of the closing trace was established.
Please make the closing decision atomic per session, using a durable unique lifecycle record or equivalent serialization. Acceptance: PostgreSQL tests racing recovery/recovery and ending/recovery produce exactly one truthful logical closing outcome; lost-response retries remain idempotent; restart recovery still works; transport cleanup stays prompt during audit-storage failure.
Publication check (2026-11-27): main advanced to
817f6ac3b00fdb0e81331e519abc5668a1560aeethrough #539. The affected production paths cited above are unchanged; the source links retain the audited revision.