Skip to content

fix(audit): grow writeAuditEntry 412 backoff to exponential jitter - #277

Merged
kptdobe merged 1 commit into
mainfrom
fix/audit-412-backoff-exponential
May 12, 2026
Merged

kptdobe merged 1 commit into
mainfrom
fix/audit-412-backoff-exponential

Conversation

@kptdobe

@kptdobe kptdobe commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace linear 412-retry jitter with exponential jitter in writeAuditEntry.
  • Per-attempt window grows from 0-50/0-100/0-150/0-200ms (~500ms total) to 0-50/0-100/0-200/0-400ms (~750ms total).
  • Retry count unchanged (4 retries, 5 total attempts).

Why

Daily DA worker log review on 2026-05-12 measured writeAuditEntry failed / PreconditionFailed at 5011/24h (and climbing in-flight). The previous day was 1929/24h. Two consecutive days > 250/24h is the explicit re-tune trigger from the monitoring issue. The merged #274 backoff (~500ms total) is not enough headroom during burst contention.

Test plan

  • New unit test: stubs setTimeout + Math.random to capture per-retry delays, asserts per-attempt exponential upper bounds and total elapsed sleep is in range (500ms, 750ms).
  • npm test -- 390 passing, 0 failing.
  • npm run lint (via lint-staged on commit) -- clean on touched files.
  • Post-deploy: re-run the writeAuditEntry failed Coralogix query for last 1h and last 6h. Expect rate to drop materially.

Out of scope

  • Schema/ordering changes to the audit entry write (contention is structural to per-file If-Match writes).
  • The paired da-collab docroom 412 log -- resolves once da-admin race rate drops.

References

Bursts of PreconditionFailed on the per-file audit.txt If-Match write
hit 5011/24h on 2026-05-12 (1929/24h the day before) - the existing linear
0-50/0-100/0-150/0-200 ms jitter (~500 ms total) does not spread retries
far enough across the contention window.

Switch to exponential jitter 0-50/0-100/0-200/0-400 ms (~750 ms total,
i.e. Math.random() * 50 * 2**attempt). Retry count unchanged (4 retries,
5 total attempts). Early retries stay cheap; late retries get the headroom.

New test stubs setTimeout + Math.random to capture per-retry delays and
asserts the per-attempt upper bounds plus that total elapsed sleep exceeds
the prior linear worst-case (500 ms). All 390 existing tests continue to pass.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kptdobe
kptdobe requested a review from bosschaert May 12, 2026 08:08
@kptdobe
kptdobe merged commit 17aac95 into main May 12, 2026
6 checks passed
@kptdobe
kptdobe deleted the fix/audit-412-backoff-exponential branch May 12, 2026 14:55
adobe-bot pushed a commit that referenced this pull request May 12, 2026
## [1.8.2](v1.8.1...v1.8.2) (2026-05-12)

### Bug Fixes

* **audit:** grow writeAuditEntry 412 backoff to exponential jitter ([#277](#277)) ([17aac95](17aac95))
@adobe-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kptdobe

kptdobe commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Post-deploy verification (release v1.8.2)

Re-ran the canonical Coralogix query for da-admin writeAuditEntry failed and the paired da-collab signal after merge + deploy:

Window da-admin writeAuditEntry failed da-collab [docroom] Failed to update document
last 30m 0 (not queried, expected ~0)
last 1h 0 0
last 2h 2097 n/a
last 3h 2496 n/a
last 6h 4942 16
last 24h 6018 n/a

The 24h / 6h totals are dominated by the pre-merge burst. The cutover is sharp: rate goes to 0 between the 2h and 1h windows, which lines up with the v1.8.2 release deploy after this PR merged.

Before/after:

  • da-admin writeAuditEntry failed: 5011/24h (2026-05-12 pre-merge burst) -> 0/1h post-deploy.
  • da-collab [docroom] Failed to update document (paired): 209/24h baseline -> 0/1h post-deploy.

Both signals materially dropped, which is the COR-26 acceptance criterion.

kptdobe added a commit that referenced this pull request May 21, 2026
…282)

* fix(audit): grow writeAuditEntry 412 backoff to 6 retries / ~3050 ms

The previous mitigation (PR #277) widened the backoff from linear (~500 ms)
to exponential jitter (~750 ms worst-case) but kept the 4-retry cap. Six days
after that deploy the writeAuditEntry PreconditionFailed rate is still
sustained at ~5614/24h on a hot audit ledger key, indicating that the
contention window is wider than the per-write latency: every retry inside a
short window observes the same losing-etag generation, so timing knobs alone
have not converged.

This change adds two more retry hops to the same exponential jitter formula,
so the worst-case sleep ladder per attempt is now:

  50, 100, 200, 400, 800, 1600 ms (~3050 ms total)

The intent is reversible diagnostic data: if the rate does not drop below
the <250/24h target after this, the next escalation is an append-only ledger
layout (one S3 object per audit entry under the existing audit dir prefix)
which eliminates the read-modify-write race entirely.

Tests updated to assert the new contract (7 total attempts, 6 retries, new
exponential ceiling) and an additional lockdown that delay[5] reaches the
new ~800 ms floor on the final hop.

Co-Authored-By: Paperclip <noreply@paperclip.ing>

* test(audit): align conditionals PUT-with-If-Match test with 6-retry budget

The audit retry bump (4 -> 6 with exponential jitter, PR #282) raised the
worst-case write-audit budget from ~750 ms to ~3050 ms.

"PUT with If-Match: returns 412 when ETag does not match and does not
retry" mocks every PutObjectCommand to 412 so the audit writer exhausts its
full retry budget. Two consequences after the bump:

- Total PutObjectCommand calls: 6 -> 8 (1 main PUT + 7 audit attempts =
  1 initial + 6 retries).
- Wall time exceeds mocha's 2000 ms default, causing a timeout failure.

Updated the count assertion and added `this.timeout(8000)` so the test
covers the new 6-retry path without flaking.

Co-Authored-By: Paperclip <noreply@paperclip.ing>

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
adobe-bot pushed a commit that referenced this pull request May 21, 2026
## [1.9.1](v1.9.0...v1.9.1) (2026-05-21)

### Bug Fixes

* **audit:** grow writeAuditEntry 412 backoff to 6 retries / ~3050 ms ([#282](#282)) ([bc49409](bc49409)), closes [#277](#277)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants