Skip to content

S5a-es: draw Elm purchases of batch offers from the live batch (fail-soft) - #78

Merged
lucca65 merged 2 commits into
masterfrom
feat/s5a-es
Oct 17, 2026
Merged

lucca65 merged 2 commits into
masterfrom
feat/s5a-es

Conversation

@lucca65

@lucca65 lucca65 commented Oct 16, 2026

Copy link
Copy Markdown
Member

Plan §9 (D2). The backend half (the frozen public.shop_draw_from_batch and order_items.draw_outcome) is cambiatus/backend#525. Deploy only after that backend is live.

  • transferSale: a batches offer draws at block time, in a savepoint with lock_timeout = '2s'. Deadlock, serialization and lock-timeout errors retry ×3; anything else records the order unassigned (draw_outcome = 'error') and the block commits, so the indexer keeps running. Every other offer's insert is unchanged.
  • At startup, and after every draw error, a check logs S5 draw function missing to stderr when the function or the column is absent.
  • A deleted offer is still recorded. A product that truly doesn't exist raises ResolveError (skip, re-indexable) instead of crash-looping.
  • First test runner: mocha, 15 cases, green on Node 16.20.2 and 26. The schema fixture is generated from written_columns.json, byte-identical to the backend's.
  • .github/workflows/test.yml is added; it won't run until GitHub Actions has credits.

🤖 Generated with Claude Code

https://claude.ai/code/session_017TeHsQCwWCBJzuob6cYEPo

lucca65 and others added 2 commits October 16, 2026 23:56
… batch

Plan §9 (D2). Inside transferSale's existing transaction, after the replay
guard: a `batches` offer calls the backend's frozen
public.shop_draw_from_batch(product, units, block time) in a savepoint
with SET LOCAL lock_timeout = '2s' (the caller's timeout is restored, since
SET LOCAL outlives a released savepoint). Deadlock / serialization / lock
timeouts retry 3× 50 ms apart; anything else, or a 4th failure, rolls back
only the savepoint and records the order unassigned with
draw_outcome = 'error' — the block commits and the indexer keeps running.
batch_id and draw_outcome are written only for batch offers; every other
insert is unchanged.

A startup check (and again after every draw error) logs
"S5 draw function missing" to stderr when the function or
order_items.draw_outcome is absent. The product lookup no longer filters
is_deleted, and a product that truly doesn't exist is a ResolveError
(skip, re-indexable) instead of a crash loop.

First test runner (mocha): a scratch DB built from written_columns.json
(byte-identical to the backend's) plus the migration's definitions; 15
cases incl. window edges in São Paulo and Costa Rica, a forced deadlock,
a held product lock, the function dropped, replay, and "transferSale
writes only manifest columns". Green on Node 16.20.2 and 26. CI workflow
added (GitHub Actions is out of credits, so it won't run yet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TeHsQCwWCBJzuob6cYEPo
…. tables)

The backend's S5a-core migration now refuses a zero or negative quantity
and schema-qualifies its tables; the fixture copy follows, regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TeHsQCwWCBJzuob6cYEPo
@lucca65
lucca65 marked this pull request as ready for review October 17, 2026 09:38
@lucca65
lucca65 merged commit 11f7e53 into master Oct 17, 2026
3 checks passed
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