Skip to content

fix(autopatch): prevent chi route-context reuse in internal requests#1049

Merged
wolveix merged 1 commit into
mainfrom
fix/autopatch-internal-context-hook
Jun 18, 2026
Merged

fix(autopatch): prevent chi route-context reuse in internal requests#1049
wolveix merged 1 commit into
mainfrom
fix/autopatch-internal-context-hook

Conversation

@wolveix

@wolveix wolveix commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

PR #1019 propagated the incoming request context to autopatch's internal GET/PUT sub-requests. With the chi adapter that also carried chi's matched route state (chi.RouteCtxKey), which chi reuses instead of routing again, so the bodyless internal GET was routed back into the generated PATCH handler, recursing and panicking on io.ReadAll(nil).

Add an optional internalContextSanitizer hook: autopatch asks the adapter to sanitize the context used for internal sub-requests, staying router-agnostic (no chi import). The chi adapter implements it by shadowing chi.RouteCtxKey so internal requests route fresh, while preserving all other context values, deadlines, and cancellation. Other adapters are unaffected.

Includes a chi-backed regression test that panics on io.ReadAll(nil) without the fix.

PR #1019 propagated the incoming request context to autopatch's internal
GET/PUT sub-requests. With the chi adapter that also carried chi's matched
route state (chi.RouteCtxKey), which chi reuses instead of routing again, so
the bodyless internal GET was routed back into the generated PATCH handler,
recursing and panicking on io.ReadAll(nil).

Add an optional internalContextSanitizer hook: autopatch asks the adapter to
sanitize the context used for internal sub-requests, staying router-agnostic
(no chi import). The chi adapter implements it by shadowing chi.RouteCtxKey so
internal requests route fresh, while preserving all other context values,
deadlines, and cancellation. Other adapters are unaffected.

Includes a chi-backed regression test that panics on io.ReadAll(nil) without
the fix.
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (c7b2231) to head (bee0e6e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1049   +/-   ##
=======================================
  Coverage   93.14%   93.14%           
=======================================
  Files          23       23           
  Lines        4901     4905    +4     
=======================================
+ Hits         4565     4569    +4     
  Misses        272      272           
  Partials       64       64           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wolveix
wolveix merged commit 34b2d39 into main Jun 18, 2026
7 checks passed
@wolveix
wolveix deleted the fix/autopatch-internal-context-hook branch June 18, 2026 22:31
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.

1 participant