fix(auction): harden lifecycle and durable bid storage

Serialize lifecycle changes and make cancellation, deadlines, and match side effects recoverable and idempotent.

Archive accepted bids durably, quarantine invalid payloads, and preserve compatibility with empty round IDs. Synchronize HTTP polling and socket state with scoped resync events.

Add cancellation cleanup index migration and regression coverage. Validated with 744 API tests, 65 Redis integration tests, and 28 Mongo integration tests.
This commit is contained in:
dahyeon committed 2026-11-09 23:24:11 +09:00
1 parent f2eec479d9
commit f649490cd2
55 files changed
+5374 -522

No files matched your search

+53
View File
@@ -62,8 +62,61 @@ $ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
# auction cancellation/undo transactions against a real local MongoDB replica set
$ pnpm run test:mongodb
```
`test:mongodb` requires `mongod` on PATH, or `MONGODB_TEST_SERVER` set to its
executable path. The runner starts an isolated replica set on a random loopback
port, uses a temporary database directory, and removes it after the tests. It
does not use the application's database connection settings.
## Auction durability
Accepted Redis bids now enter `auction:bidArchivePayloads` and
`auction:bidArchiveQueue` atomically with the bid. The durability scheduler saves
them to `auctionBidRecords` using deterministic IDs before removing queue entries.
Recent state snapshots remain capped at 1000 bids; the archive is not capped and
retains accepted bids across undo/cancellation for audit. These records begin with
this deployment; bids already discarded by an older version cannot be recovered.
`GET /communities/:communityId/matches/:matchId/auction/bids/history` pages through
the current lifecycle's persisted archive using `afterRevision` and `limit` (1–200).
Persistence is asynchronous, so an empty last page may gain entries afterward.
Invalid archive entries are moved atomically to `auction:bidArchiveDeadLetterQueue`
and `auction:bidArchiveDeadLetterPayloads`. The payload stores the original text
(or `null` for a missing payload), error, ID, and quarantine time. Monitor these
keys and review quarantined data before repairing/requeuing it; it is not retried
automatically or expired. Other bids continue to persist. Mongo write failures
leave valid entries in the pending queue for idempotent retries.
Older in-flight rounds can produce `bidRoundId: ''`; the archive treats this as
an absent optional round ID. Empty player IDs and other invalid field types
remain validation errors.
Cancellation commits its completion marker and pending cleanup fields in Match.
The scheduler retries cleanup after restarts, with a delay capped at 60 seconds.
Reset notifications include the lifecycle to protect a newly started auction.
Dead-letter status notifications use `auction:deadLetterStatusQueue`; failures to
persist or mirror the terminal status are retried without rerunning the side effect.
Older side-effect dead letters are also reconciled automatically.
Before deploying the cleanup worker, create its partial Match index using the
additive, repeatable migration below. Schema declarations alone do not create
indexes when `MONGODB_AUTO_INDEX` is disabled (the default). Choose the target
environment explicitly; dry-run does not create indexes or modify documents.
```bash
pnpm --filter api auction:indexes -- --env staging --dry-run
pnpm --filter api auction:indexes -- --env staging --apply
# Use --env prod for production.
```
The index is `{ auctionCancellationCleanupRetryAt: 1 }`, restricted to
`{ auctionCancellationCleanupPending: true }`. The worker only reads due pending
entries; it no longer scans legacy cancellation markers without a pending flag.
## Deployment
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.