Skip to content

fix: eliminate Location double-wrap 500 on document PUT (v1.4.1) - #13

Merged
cursor[bot] merged 1 commit into
mainfrom
feat/location-double-wrap-82a7
Jul 24, 2026
Merged

fix: eliminate Location double-wrap 500 on document PUT (v1.4.1)#13
cursor[bot] merged 1 commit into
mainfrom
feat/location-double-wrap-82a7

Conversation

@PeterBaker0

@PeterBaker0 PeterBaker0 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

Intermittent client 500 on successful document PUT/COPY when Couch returns an absolute Location (e.g. http://couchdb:5984/...). Root cause: fetchFromCouch wrapped the upstream Response to rewrite Location, then toClientResponse wrapped the same body again — undici occasionally throws TypeError: Response body object should not be disturbed or locked, which app.onError maps to Couch-shaped internal_server_error.

Fixed

  • Intermittent 500 on document PUT/COPY when Couch returns an absolute Location header. The proxy no longer double-wraps the upstream Response body when rewriting Location to a relative path (undici "body disturbed or locked").

Changes

  • Remove Location rewrite / new Response(...) from fetchFromCouch (returns raw upstream).
  • Add toClientResponseFromCouch so every client-facing upstream body rewrite happens once, with Couch-origin Location → path-only.
  • Audit actors.ts call sites to use the helper (including docDelete / docUpdate / error short-circuits that previously omitted rewriteLocation).
  • Unit coverage in test/unit/forward-location.test.ts; integration PUT Location + 20-create stress loop in test/integration/acl.test.ts.

Follow-up after merge

  • Cut release with ./scripts/release.sh 1.4.1 (GHCR 1.4.1 + sha-<short>).
  • FAIMS can then bump imageTag 1.4.01.4.1 and drop putWithRetry if desired.

Test plan

  • pnpm fmt:check && pnpm lint && pnpm typecheck && pnpm test
  • docker compose up -d --build && pnpm test:integration (151 passed)
  • Manual smoke: Basic PUT → 201 with Location: /acldemo/doc-location-probe (no Couch origin)
Open in Web Open in Cursor 

Rewrite absolute same-origin Location headers only in
toClientResponse/toClientResponseFromCouch. fetchFromCouch now returns
the raw upstream Response so undici no longer intermittently throws
"body disturbed or locked" on successful PUT/COPY (client 500).

Co-authored-by: Peter Baker <PeterBaker0@users.noreply.github.com>
@cursor
cursor Bot marked this pull request as ready for review July 24, 2026 12:19
@cursor
cursor Bot merged commit f1dd6bd into main Jul 24, 2026
2 checks passed
@cursor
cursor Bot deleted the feat/location-double-wrap-82a7 branch July 24, 2026 12:19
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.

2 participants