Finding (SigNoz, last 24 h): tenant-registry-stage logged ~11,100 failed usage.record items ("tenant has no ERP customer yet") behind 36 failed customer.upsert items: duplicate key value violates unique constraint "tenants_erp_customer_id_key". Prod has none: it talks to the real ERPNext.
Cause: the ERP mock (stage's erpnext-mock, same image as the registry) keeps its documents in memory. It restarts with every registry deploy on stage, so its counter began at CUST-00001 again and handed new tenants customer names that older tenants in the registry are still linked to. Those tenants never got linked, and their usage records were retried forever (1 h cap, no limit).
Fix
ERP mock:Config.NameToken goes into every name it assigns. cmd/erpmock sets one per boot (CUST-<yymmddHHMMSS>-00001), so names stay unique across restarts. Tests leave it empty and keep CUST-00001. After this deploys, the stuck stage upserts succeed on their next retry, and the usage behind them drains.
Outbox safety net: after maxOutboxAttempts (170, about a week at the 1 h cap), an item is dead-lettered instead of retried forever:
done_at is set and last_error becomes dead letter: <err>;
the payload is kept, so it can be re-queued with done_at = NULL, attempts = 0;
an ERROR line goes out, "outbox item dead-lettered" with id, kind and tenant_id, so the prod error-log alert fires.
A week is long enough that an ERP outage never drops prod usage. New Store.DeadLetterOutbox (memory + postgres); no migration.
Tests
TestOutbox_deadLettersAfterMaxAttempts: memory and postgres (run locally through podman/testcontainers). The item stays pending up to the last attempt, is done after it, and is never claimed again.
Backlog t25.
**Finding (SigNoz, last 24 h):** tenant-registry-stage logged ~11,100 failed `usage.record` items ("tenant has no ERP customer yet") behind 36 failed `customer.upsert` items: `duplicate key value violates unique constraint "tenants_erp_customer_id_key"`. Prod has none: it talks to the real ERPNext.
**Cause:** the ERP mock (stage's `erpnext-mock`, same image as the registry) keeps its documents in memory. It restarts with every registry deploy on stage, so its counter began at `CUST-00001` again and handed new tenants customer names that older tenants in the registry are still linked to. Those tenants never got linked, and their usage records were retried forever (1 h cap, no limit).
**Fix**
- **ERP mock:** `Config.NameToken` goes into every name it assigns. `cmd/erpmock` sets one per boot (`CUST-<yymmddHHMMSS>-00001`), so names stay unique across restarts. Tests leave it empty and keep `CUST-00001`. After this deploys, the stuck stage upserts succeed on their next retry, and the usage behind them drains.
- **Outbox safety net:** after `maxOutboxAttempts` (170, about a week at the 1 h cap), an item is dead-lettered instead of retried forever:
- `done_at` is set and `last_error` becomes `dead letter: <err>`;
- the payload is kept, so it can be re-queued with `done_at = NULL, attempts = 0`;
- an ERROR line goes out, "outbox item dead-lettered" with id, kind and tenant_id, so the prod error-log alert fires.
A week is long enough that an ERP outage never drops prod usage. New `Store.DeadLetterOutbox` (memory + postgres); no migration.
**Tests**
- `TestOutbox_deadLettersAfterMaxAttempts`: memory **and postgres** (run locally through podman/testcontainers). The item stays pending up to the last attempt, is done after it, and is never claimed again.
- `erpmock.TestNameToken`.
- The full suite passes with postgres.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
Stage logged ~11,100 failed usage.record items a day ('tenant has no ERP
customer yet') behind 36 customer.upsert failures on the unique
tenants_erp_customer_id_key (backlog t25). The ERP mock keeps its docs
in memory and restarts with every registry deploy on stage: its counter
began at CUST-00001 again and handed new tenants names older tenants are
still linked to, so they never got linked and their usage waited
forever.
- erpmock: Config.NameToken goes into every assigned name; cmd/erpmock
sets one per boot (CUST-<yymmddHHMMSS>-00001). Tests keep plain names.
- outbox: after maxOutboxAttempts (170, about a week at the 1 h cap) an
item is dead-lettered instead of retried forever: done_at set,
last_error 'dead letter: <err>', payload kept for a re-queue, and an
ERROR line (the prod error alert sees it). Store gains
DeadLetterOutbox (memory + postgres).
Tests: dead letter after the last attempt and nothing claimed after,
memory and postgres; mock names carry the token.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
sharang
merged commit 43731da8f1 into main2026-10-30 07:22:30 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Backlog t25.
Finding (SigNoz, last 24 h): tenant-registry-stage logged ~11,100 failed
usage.recorditems ("tenant has no ERP customer yet") behind 36 failedcustomer.upsertitems:duplicate key value violates unique constraint "tenants_erp_customer_id_key". Prod has none: it talks to the real ERPNext.Cause: the ERP mock (stage's
erpnext-mock, same image as the registry) keeps its documents in memory. It restarts with every registry deploy on stage, so its counter began atCUST-00001again and handed new tenants customer names that older tenants in the registry are still linked to. Those tenants never got linked, and their usage records were retried forever (1 h cap, no limit).Fix
ERP mock:
Config.NameTokengoes into every name it assigns.cmd/erpmocksets one per boot (CUST-<yymmddHHMMSS>-00001), so names stay unique across restarts. Tests leave it empty and keepCUST-00001. After this deploys, the stuck stage upserts succeed on their next retry, and the usage behind them drains.Outbox safety net: after
maxOutboxAttempts(170, about a week at the 1 h cap), an item is dead-lettered instead of retried forever:done_atis set andlast_errorbecomesdead letter: <err>;done_at = NULL, attempts = 0;A week is long enough that an ERP outage never drops prod usage. New
Store.DeadLetterOutbox(memory + postgres); no migration.Tests
TestOutbox_deadLettersAfterMaxAttempts: memory and postgres (run locally through podman/testcontainers). The item stays pending up to the last attempt, is done after it, and is never claimed again.erpmock.TestNameToken.🤖 Generated with Claude Code
https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
Stage logged ~11,100 failed usage.record items a day ('tenant has no ERP customer yet') behind 36 customer.upsert failures on the unique tenants_erp_customer_id_key (backlog t25). The ERP mock keeps its docs in memory and restarts with every registry deploy on stage: its counter began at CUST-00001 again and handed new tenants names older tenants are still linked to, so they never got linked and their usage waited forever. - erpmock: Config.NameToken goes into every assigned name; cmd/erpmock sets one per boot (CUST-<yymmddHHMMSS>-00001). Tests keep plain names. - outbox: after maxOutboxAttempts (170, about a week at the 1 h cap) an item is dead-lettered instead of retried forever: done_at set, last_error 'dead letter: <err>', payload kept for a re-queue, and an ERROR line (the prod error alert sees it). Store gains DeadLetterOutbox (memory + postgres). Tests: dead letter after the last attempt and nothing claimed after, memory and postgres; mock names carry the token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4