Title: bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev
X Title: bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev
Description: Trigger.dev – build and deploy durable AI agents and workflows - bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev
Open Graph Description: Trigger.dev – build and deploy durable AI agents and workflows - bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev
X Description: Trigger.dev – build and deploy durable AI agents and workflows - bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev
Opengraph URL: https://github.com/triggerdotdev/trigger.dev
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: `retry.fetch` strips headers set by HTTP client libraries","articleBody":"### Provide environment information\n\n System:\n OS: Windows 11 10.0.26100\n CPU: (24) x64 Intel(R) Core(TM) i7-14650HX\n Memory: 21.86 GB / 63.78 GB\n Binaries:\n Node: 22.11.0 - C:\\Program Files\\nodejs\\node.EXE\n npm: 10.9.0 - C:\\Program Files\\nodejs\\npm.CMD\n bun: 1.1.38 - C:\\Program Files\\nodejs\\bun.CMD\n\n\n### Describe the bug\n\n## Summary\nThe `retry.fetch` wrapper from `@trigger.dev/sdk` doesn't preserve headers that are set by HTTP client libraries like `openapi-fetch`. This causes API requests to fail with \"Missing or incorrect Content-Type header\" errors when using retry functionality.\n\n## Environment\n- **@trigger.dev/sdk version**: [your version]\n- **Runtime**: Bun 1.1.38\n- **OS**: Windows\n- **HTTP Client**: openapi-fetch\n\n## Expected Behavior\nWhen using `retry.fetch` as a custom fetch implementation with HTTP client libraries, headers set by the client (either in initial config or middleware) should be preserved across retry attempts.\n\n## Actual Behavior\nHeaders set by HTTP client libraries are stripped during retry attempts, causing requests to fail with missing headers.\n\n## Reproduction Steps\n\n1. Create an `openapi-fetch` client with headers in config:\n```typescript\nimport createClient from \"openapi-fetch\";\nimport { retry } from \"@trigger.dev/sdk\";\n\nconst client = createClient({\n baseUrl: \"https://api.example.com\",\n headers: {\n \"Authorization\": \"Bearer token\",\n \"Content-Type\": \"application/json\",\n },\n fetch: retry.fetch, // Using retry.fetch\n});\n```\n\n2. Make a request that triggers a retry (e.g., to an endpoint that returns 500):\n```typescript\nconst result = await client.POST(\"/api/endpoint\", {\n body: { data: \"test\" }\n});\n```\n\n3. Observe that the retry attempts are missing the `Authorization` and `Content-Type` headers.\n\n## Root Cause Analysis\nLooking at the `retry.fetch` source code, the issue is in the `doFetchRequest` function:\n\n```typescript\nconst response = await fetch(input, {\n ...init,\n headers: {\n ...init?.headers, // Only preserves ORIGINAL headers from init\n \"x-retry-count\": attemptCount.toString(),\n },\n});\n```\n\nThe retry mechanism only spreads `init?.headers` (the original headers), completely ignoring any headers that were modified by HTTP client middleware or merged by the client library.\n\n## Workaround\nWe had to create a custom fetch wrapper:\n\n```typescript\nconst retryFetchWithHeaders = async (\n input: RequestInfo | URL,\n init?: RequestInit\n): Promise\u003cResponse> => {\n const headers = new Headers(init?.headers);\n \n // Ensure required headers are present\n if (!headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${API_TOKEN}`);\n }\n if (!headers.has('Content-Type')) {\n headers.set('Content-Type', 'application/json');\n }\n\n // Convert Headers to plain object for retry.fetch\n const headersObj: Record\u003cstring, string> = {};\n headers.forEach((value, key) => {\n headersObj[key] = value;\n });\n\n return retry.fetch(input, {\n ...init,\n headers: headersObj,\n });\n};\n```\n\n## Suggested Fix\nThe `doFetchRequest` function should preserve all headers from the incoming request, not just the original `init?.headers`. Consider:\n\n```typescript\nconst response = await fetch(input, {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init?.headers).entries()),\n \"x-retry-count\": attemptCount.toString(),\n },\n});\n```\n\nOr better yet, use the Headers API properly to merge headers without losing any that were set by middleware.\n\n## Impact\nThis affects any HTTP client library that:\n- Sets headers in middleware (like `openapi-fetch`, `axios` interceptors, etc.)\n- Merges headers from multiple sources\n- Relies on dynamic header setting\n\n## Additional Context\nThis is particularly problematic for OpenAPI-based clients where type-safe headers and authentication are crucial for API functionality. The current behavior makes `retry.fetch` incompatible with modern HTTP client libraries.\n\n\n\n### Reproduction repo\n\nIncluded in description\n\n### To reproduce\n\nIncluded in description\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/nickwang0808","@type":"Person","name":"nickwang0808"},"datePublished":"2025-09-09T18:55:21Z","url":"https://github.com/triggerdotdev/trigger.dev/issues/2490"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:e07fe0fd-279e-ee6e-bbb0-353b299f6b29 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD02:27EABE:5CD5BDC:7C073AD:6AFAD87E |
| html-safe-nonce | 19805806a1fe9bc53834a7706f68da5e0ef91fb6b58eb0bac15e132cc29058f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDAyOjI3RUFCRTo1Q0Q1QkRDOjdDMDczQUQ6NkFGQUQ4N0UiLCJ2aXNpdG9yX2lkIjoiMjAzNDg2OTgzNDkyNjk3MTAwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ab6dcf7977e1661191ab6b75676df5d01ba931bf3880c273837c3a0b5a05f7c4 |
| hovercard-subject-tag | repository:572570113 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/issues/2490 |
| twitter:image | https://repository-images.githubusercontent.com/572570113/0ef45e42-bd78-4810-9397-4e6147be9329 |
| twitter:card | summary_large_image |
| og:image | https://repository-images.githubusercontent.com/572570113/0ef45e42-bd78-4810-9397-4e6147be9329 |
| og:image:alt | Trigger.dev – build and deploy durable AI agents and workflows - bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 02f4c00e74911c7cd779fc232c3130cee49eb39fd0ed4bfe3eea3b82c7c18084 |
| turbo-cache-control | no-cache |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 33c41e9d150e44415272934d676dc63c57d89c3b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width