Skip to content

fix: treat versionsource 412 as success, eliminating ~860 500s/day#271

Merged
kptdobe merged 1 commit intomainfrom
fix-version-412
Apr 30, 2026
Merged

fix: treat versionsource 412 as success, eliminating ~860 500s/day#271
kptdobe merged 1 commit intomainfrom
fix-version-412

Conversation

@kptdobe
Copy link
Copy Markdown
Contributor

@kptdobe kptdobe commented Apr 30, 2026

Problem

Worker logs show ~860 500 responses per 24 hours, all from POST /versionsource/adobecom/da-cc/{locale}/… endpoints hit by the localization pipeline.

Every entry has:

warn: "An error was encountered in a non-retryable streaming request."

A subset also have:

error: "writeAuditEntry failed"
      "PreconditionFailed: At least one of the pre-conditions you specified did not hold."

Root cause

The localization pipeline processes many locales in parallel. Multiple concurrent workers read the same source document, all obtain the same Version UUID from the object's metadata, and all call POST /versionsource with a label at the same moment.

putVersion uses If-None-Match: * to write the version object (so it can only be created once per key). The first caller wins and gets 200. Every subsequent concurrent caller gets a 412 PreconditionFailed from R2, because the version key already exists.

In putObjectWithVersion:

versionCreated = versionResp.status === 200;  // false on 412

Then in postObjectVersionWithLabel:

if (!resp.versionCreated) return { status: 500, error: 'Version was not created' };

This returns 500 even though the version was created — by the first concurrent request.

Fix

Treat 412 from putVersion as "version already exists = created by a concurrent call":

// 412 means the version key already exists — a concurrent request created it first.
// The version IS persisted in R2, so treat it as created.
versionCreated = versionResp.status === 200 || versionResp.status === 412;

Test plan

  • Existing test putObjectWithVersion sets versionCreated true when version already existed (putVersion 412 = concurrent race) — updated to assert versionCreated === true
  • Existing test postObjectVersion returns 201 when version already exists in R2 (putVersion 412 concurrent race) — updated to expect 201 instead of 500
  • New test returns 201 when version PUT gets 412 (concurrent race — version already exists in R2) via postObjectVersionWithLabel — verifies end-to-end that the caller gets 201
  • All 368 tests pass, lint clean

🤖 Generated with Claude Code

When multiple concurrent POST /versionsource requests target the same
document (e.g. the localization pipeline processing many locales in
parallel), the second caller's R2 PUT for the version object gets a 412
PreconditionFailed because the first caller already wrote it with
If-None-Match:*. The version IS in R2 — returning 500 "Version was not
created" is incorrect.

Fixes ~860 spurious 500 errors per 24h on /versionsource/adobecom/da-cc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

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 April 30, 2026 06:57
@kptdobe kptdobe merged commit e92b916 into main Apr 30, 2026
6 checks passed
@kptdobe kptdobe deleted the fix-version-412 branch April 30, 2026 11:54
adobe-bot pushed a commit that referenced this pull request Apr 30, 2026
## [1.7.1](v1.7.0...v1.7.1) (2026-04-30)

### Bug Fixes

* handle KV 414 error when IMS auth fragment leaks into org path ([#270](#270)) ([db2b4c8](db2b4c8))
* treat putVersion 412 as version-already-exists, not failure ([#271](#271)) ([e92b916](e92b916))
@adobe-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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