Repository navigation
Closed
Labels
Description
Problem
The exact-head rc.4 adoption CI exposed a production-relevant PostgreSQL progress failure in the installed VCS/PG lane.
Observed on PR #1193, head 71c2bc0f0d1a2bf783f001fdbba29801cefd9825:
- workflow run: https://github.com/adcontextprotocol/adcp-client-python/actions/runs/35510429312
- job: https://github.com/adcontextprotocol/adcp-client-python/actions/runs/35510429312/job/106077250302
- failing test:
test_floor_installed_production_contract[pg-vcs] - inner stage:
vcs-pg-installed-production - result: 1,800.114-second deadline; child terminated cleanly with no stdout/stderr
- local exact-head VCS/PG lane had passed 1,160 tests in 1,416.56 seconds
- the fresh CI PG/sdist sibling passed
The PostgreSQL service log also recorded a deadlock between:
- the reporting configuration lease-acquisition
UPDATE ... FOR UPDATE SKIP LOCKED, and - the reporting status scope-checkpoint
INSERT ... ON CONFLICT DO NOTHING,
with reporting_materializer_source_dirty() taking an account-scoped advisory transaction lock.
The log does not yet prove that this deadlock caused the later timeout. It does prove that production lock paths can deadlock during the production contract, while the installed process subsequently failed to demonstrate bounded forward progress.
Required investigation
- Reproduce under the installed VCS/PG production contract with phase-level tracing.
- Establish the lock-order graph for lease acquisition, checkpoint creation, materializer triggers, and account advisory locks.
- Determine whether PostgreSQL deadlock cancellation is handled and retried safely.
- Identify the exact phase/process that remained live until the outer deadline.
- Compare VCS and sdist install paths; they must be behaviorally equivalent.
Acceptance criteria
- Conflicting production operations have a documented consistent lock order or a bounded, safe retry strategy.
- A forced deadlock/cancellation cannot leave the worker or harness waiting indefinitely.
- A regression test deterministically exercises the conflicting paths and proves forward progress.
- Installed VCS and sdist PostgreSQL lanes both pass repeatedly.
- Failure diagnostics identify the active phase, process state, database wait state, and cleanup result without exposing customer data.
- The fix does not weaken lease fencing, checkpoint integrity, or receipt immutability.
Activity
bokelley commentedon Sep 20, 2026
Triage
Classification: Bug — PostgreSQL deadlock causing unbounded worker timeout in production contract
Bucket(s): middleware (reporting lease acquisition / checkpoint / materializer coordination)
Status: ready-for-human
What the experts said:
pg_advisory_xact_lockfirst, thenFOR UPDATE SKIP LOCKEDlease, then checkpointINSERT; 40P01 retry is safe given idempotent semantics; notes that_idempotency.py:379generates a fresh UUID on non-pinned retry sosync_reporting_statusretries are treated as new calls (should appear in release notes); assessed as implementable without architectural review.FOR UPDATE SKIP LOCKED; verdict: flag for human review before any implementation — requires proof that lease re-acquisition after rollback is serialized and checkpoint insert remains idempotent under concurrent retry.My take: Experts disagree on whether the fix is security-sensitive: the protocol expert sees a well-understood DB pattern; the security reviewer sees a concrete path to double-payout via naive retry-on-deadlock. Per triage rules, expert disagreement on a blocker escalates to human. The security reviewer's concern is not theoretical —
FOR UPDATE SKIP LOCKEDreleases on rollback, so re-entry timing must be proven safe, not assumed.Implementation brief for the assigned engineer:
pg_advisory_xact_lock(account_id)→ leaseFOR UPDATE SKIP LOCKED→ checkpointINSERT ... ON CONFLICT DO NOTHING. Existing signing path (replay_store.py:184) already uses transaction-scopedpg_advisory_xact_lock; the materializer path must match exactly (session-scopedpg_advisory_locksurvives rollback in a pool and defeats retry).40P01(PostgreSQL deadlock_detected) at each acquire site and retry with bounded backoff (2–3 attempts). Prove that after rollback the lease is not already held by another worker before re-entering acquisition._idempotency.py:379generates a fresh UUID on non-pinned retry;sync_reporting_statusretries will not be collapsed by the idempotency cache. Confirm this is acceptable and document in release notes.Triaged by Claude Code. Session: https://claude.ai/code/session_01Q3ppsy5p29FxMvEijwZpad
Generated by Claude Code
bokelley commentedon Sep 20, 2026
Code reviewer follow-up (findings arrived after initial triage):
The code-reviewer examined the source and found the VCS/sdist discrepancy root cause:
reporting_materializer_source_dirty()is absent from the checked-in Python source — it is almost certainly a PostgreSQL trigger/stored procedure installed by VCS test fixtures but not published in the sdist package. This means the third party in the deadlock cycle is a DB-level function, and its lock acquisition order cannot be fixed without first locating and auditing that function.Specific files with confirmed lock paths:
src/adcp/reporting/ledger/pg.py:1083—lease_period_close()issuesUPDATE reporting_configurations ... FOR UPDATE SKIP LOCKEDwith nolock_timeout; a hung acquisition here produces the 1800s hangsrc/adcp/reporting/ledger/pg.py:175-178—_lock_account()callspg_advisory_xact_lockwith no timeout; a hung advisory lock blocks indefinitelyproducer.py:264—run_worker()has noDeadlockDetected/LockNotAvailablehandler; the deadlock victim's connection is silently abandoned with no retryThree-part fix required (all three are necessary; any single part is insufficient):
SET LOCAL lock_timeout = '5s'beforeFOR UPDATE SKIP LOCKEDandpg_advisory_xact_lockcalls (converts hang into fast retryable failure)DeadlockDetected/LockNotAvailablecatch with bounded exponential retry inrun_worker()— absence of this is what produced the silent 1800s hang rather than a fast failureThe code-reviewer confirms the security assessment:
commit_revisionretry after deadlock cancellation must re-raise if the aborted transaction's content differs from what is now stored (receipt immutability).Generated by Claude Code