Skip to content

feat(jobstore): Postgres Outbox (contract b) and outbox conformance suite - #22447

Merged
Git-on-my-level merged 19 commits into
integration/legacy-retirefrom
lr/12-outbox
Oct 19, 2026
Merged

Git-on-my-level merged 19 commits into
integration/legacy-retirefrom
lr/12-outbox

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Lane 12 slice 2: contract (b) Postgres Outbox. Stacked on #22434: base is lr/12-postgres so the diff shows only this slice; the captain retargets to integration/legacy-retire once #22434 merges.

  • database/jobstore/outbox_pg.py + migrations 0003 (wake_pending): coalescing enqueue (min/max), FOR UPDATE SKIP LOCKED pull claims, claim_key (STALE/BUSY/DISCARDED/DEFERRED), fenced heartbeat/ack/defer/release, sweep.
  • Per the lead's wake rulings: the outbox owns wake creation on defer and on a not-due delivery (returns DEFERRED), and wake(row_id, wake_token) is idempotent for post-commit callers. A failed task create leaves the token pending; sweep retries it.
  • testing/outbox_sim.py (executable reference model) and tests/integration/test_outbox_conformance.py: 24 invariants on sim | postgres | emulator (emulator leg skips until lane 9's Firestore outbox is wired into build_outbox_backend).
  • Not selected anywhere: outbox_for still belongs to lane 9/1. No deploy.

Verified (local m5, integration layer): emulator + sim + postgres required, 134 passed across the store and outbox suites. Postgres is not in GitHub CI (S6).

View guided diff Turn on auto-fix

Product invariants affected: INV-DATA-1. This PR adds an IAM-auth connector and operator entry for the staging job-store database (python -m database.jobstore). It is not wired into any production-family artifact or runtime selector: nothing here routes Stable, mobile or Beta to development or staging, and the connector takes its host, database and user only from the operator's own environment. Prod and dev data planes are untouched; the test namespaces are batch_pipeline_test_*.

Failure-Class: none
(The only fix: subject in the range is lane 9's fix(batch): key the callback-pending expected retry..., which arrives through the integration merge; this PR adds no fix.)

Git-on-my-level and others added 15 commits October 19, 2026 13:19
…end Store conformance

Adds database/jobstore (connection pool capped at 4, expand-only versioned
migrations with checksum + advisory lock, PostgresStore over the batch Store
protocol, SERIALIZABLE with bounded retry), testing/store_fixtures.py (the
store_backend fixture over sim, Firestore emulator and Postgres, local PG16
on a private unix socket) and tests/integration/test_store_conformance.py.
Postgres in CI needs an unnamed .github change (S6), so the postgres
parameter skips in GitHub CI and is proven locally.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…he modules reachable

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…sor, validation, conversation writes and projection scan

Closes the four gaps the Store conformance suite had strict-xfailed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…uite on sim, Postgres and emulator

The outbox owns wake creation (defer, not-due claim_key -> DEFERRED), wake(row_id, wake_token)
is idempotent, wake_pending (migration 0003) makes a failed task create sweep-retryable.
The emulator leg skips until lane 9's Firestore outbox is wired into build_outbox_backend.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t ignore to its imports

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… connector and operator entry

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Base automatically changed from lr/12-postgres to integration/legacy-retire October 19, 2026 09:12
Git-on-my-level and others added 4 commits October 19, 2026 16:46
…nst Cloud SQL with IAM auth

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…endpoint only under OMI_TEST_POSTGRES_IAM

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r OMI_TEST_POSTGRES_IAM

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T12:41:34.927390Z fbb7432 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level merged commit f0ee775 into integration/legacy-retire Oct 19, 2026
26 checks passed
@Git-on-my-level
Git-on-my-level deleted the lr/12-outbox branch October 19, 2026 12:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbb7432a4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +100 to +101
with self.store.pool.connection() as conn, conn.transaction():
return self._enqueue(conn, dedupe_key, owner_id, payload, available_at, policy_id, coalesce, now)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Create the wake after nontransactional enqueue

When tx is None, this path commits the durable row and immediately returns without calling wake, even though the Outbox.enqueue contract says nontransactional enqueues create their wake before returning. Direct producers therefore create no Cloud Task and the work remains idle until a later sweep happens to repair it; store the result, leave the transaction, and invoke wake when it contains a token.

Useful? React with 👍 / 👎.

Comment on lines +242 to +243
f'UPDATE outbox SET {sets} WHERE id = %s AND namespace = %s AND lease_token = %s '
f'AND done_at IS NULL {guard} RETURNING id',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fence acknowledgements against coalesced revisions

If another enqueue coalesces into a row while it has a live lease, _enqueue increments the version and may mint a new wake token, but this settlement guard checks only the unchanged lease token. The older worker can consequently call ack and close the row, discarding the newly coalesced obligation; defer can similarly overwrite its new schedule. Coalescing must invalidate the old lease or settlement must also verify the claimed revision/token.

Useful? React with 👍 / 👎.


return OutboxHarness(
name,
outbox_cls(kind, client=harness.customer.client, privacy_blocked=probe, create_wake=wake),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Adapt callbacks to the Firestore outbox signature

For the emulator backend, FirestoreOutbox invokes create_wake with one row mapping and privacy_blocked with one row ID, but this passes the generic three-argument wake and two-argument _privacy_probe callbacks. The first nontransactional enqueue therefore raises TypeError, and any claim would do the same in the privacy check, so the emulator leg cannot run the advertised conformance suite; provide Firestore-specific adapters here.

Useful? React with 👍 / 👎.

Comment on lines +283 to +285
'AND ((lease_until > 0 AND lease_until <= %s) OR (wake_pending AND lease_until <= %s) '
'OR (available_at <= %s AND lease_until <= %s)) '
'ORDER BY available_at, id LIMIT %s FOR UPDATE SKIP LOCKED',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exclude inert due rows from the bounded sweep

This predicate admits every due, unleased row even when wake_pending is false, but the loop has no branch for such a row unless it is privacy-fenced. Once limit older successfully-woken tasks remain open—for example during a Cloud Tasks backlog—each sweep repeatedly selects those same no-op rows and can indefinitely starve later pending wakes or expired leases that actually need repair.

Useful? React with 👍 / 👎.

Comment on lines +263 to +264
_postgres_state['dsn'] = f'iam:{target[0]}/{target[1]}' # a label, never a credential
return _postgres_state['dsn']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not return a non-DSN from postgres_dsn

When OMI_TEST_POSTGRES_IAM is enabled, this returns an iam:host/database display label rather than a psycopg DSN. The existing tests/integration/test_jobstore_migrations_postgres.py still passes postgres_dsn() directly to dial, so the migration integration suite fails to parse/connect precisely in the new staging-IAM mode; that caller must use the IAM connection factory, or this API must continue returning a usable connection target.

Useful? React with 👍 / 👎.

Comment on lines +448 to +456
return OutboxHarness(
name,
outbox_cls(kind, client=harness.customer.client, privacy_blocked=probe, create_wake=wake),
harness,
wakes,
fail_wakes,
key=lambda owner, label: enrichment_outbox.key(owner, label),
payload=lambda label, **extra: {'conversation_id': label, 'language': 'en', **extra},
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove global Firestore outbox state during fixture cleanup

This reuses make_emulator() for an outbox that writes the fixed sync_reprocess_outbox collection, but that harness only cleans its namespaced batch collections. Because every parametrized case gets a new harness while old open or leased outbox rows remain, later claim() calls query the global collection with a limit and can have their page filled by rows from previous cases, making the emulator suite order-dependent; register cleanup for the outbox rows and its scan state before returning this harness.

Useful? React with 👍 / 👎.

Comment on lines +85 to +88
queued = put(ob)
assert ob.outbox.claim_key(queued.row_id, 'not-the-token', LEASE, now=T0) is Outcome.STALE
assert ob.outbox.claim_key('999999', queued.wake_token, LEASE, now=T0) is Outcome.STALE
assert ob.outbox.claim_key('not-a-number', queued.wake_token, LEASE, now=T0) is Outcome.STALE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Supply valid unknown IDs for the Firestore conformance leg

The emulator implementation requires a 64-hex row ID and a 32-hex wake token and raises ValueError for malformed task bindings. Consequently this test fails on its first assertion with not-the-token, and both hardcoded unknown row IDs are malformed as well, rather than exercising the expected STALE outcomes; use backend-adapted, syntactically valid unknown IDs/tokens and keep malformed-input expectations backend-specific.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant