The fix I closed

· Reliability is a feature · Testing comes before trust

While porting a retry fix to all eight Kiota SDKs, I found a separate bug in the TypeScript one: after a redirect, the retry handler can resend a request to the wrong URL. I reported it in microsoft/kiota-typescript#2233 on November 16 and opened a fix a week later.

The day after that, I closed my pull request in favor of one from the maintainers. Theirs merged that afternoon and closed my issue. This post is about why closing mine was the right call, and why I could have gotten there sooner.

The bug

In the default Node pipeline, the retry handler runs before the redirect handler. When the redirect handler follows a redirect, it updates the shared request options in place: for a 303, it changes the method to GET and drops the body. But it keeps the new URL to itself. If the redirect target then returns a retryable status, the retry handler resends the updated options to the URL it was called with:

POST /send        body    → 303, Location: /redirected
GET /redirected   no body → 504
GET /send         no body → the retry

The retry is a bodyless GET to an endpoint that was only ever sent a POST. The browser pipeline doesn’t have this problem, because the browser’s fetch follows redirects itself without touching Kiota’s request options.

The fix I wrote

My pull request made the smallest change I could see: the redirect handler recorded the URL it followed, and the retry handler resent to that URL. The order of the handlers stayed the same.

I knew there was another way. The Python, Java, PHP and Ruby SDKs already run the redirect handler before the retry handler, which I’d seen while porting. With that order, the retry handler only ever sees one hop, so the bug can’t happen. But the default order is behavior every TypeScript client inherits, and I assumed each SDK had its own history and reasons for the order it uses. Rearchitecting that felt like a maintainer decision. As a contributor, I just wanted my issue fixed, so I didn’t propose it.

Four rounds of review

An automated reviewer looked at the pull request four times in under an hour, and found a new problem each time:

  1. Two requests sharing one options object could read each other’s redirect. I made the retry handler work on its own copy of the options.
  2. The copy still shared the caller’s headers, so after a 303 the caller’s object lost its Content-Type. I copied the headers too.
  3. The copy dropped headers created by another fetch implementation, and options inherited from a prototype. I narrowed what the copy touched.
  4. The copy could drop options defined as getters on a class.

Each fix was correct, and each one made the next problem possible. The copying only existed because two handlers had to share state about a request that one of them was rewriting.

That’s the signal I should have read earlier.

The better fix

The next morning, the maintainer requested changes: put the redirect handler before the retry handler. The retry handler would then resend the current hop’s URL, method and body together, with no redirect state to share. Each hop would also get its own retry budget, so a 503 before a redirect and another after it can both be retried.

That was the fix I’d ruled out as not mine to make. I was right that it was the maintainers’ call. I was wrong to treat that as a reason not to raise it. A paragraph in the pull request description laying out both options would have let them choose on day one, and saved four rounds of review.

I started reworking the pull request to the new order, and the diff shrank to reordering one array, plus tests. While I was reworking mine, the maintainers opened #2239, an independent fix that aligns the whole built-in middleware order with a design proposal shared across the SDKs. It put redirect before retry, as mine did, and went further: it reordered the other handlers too, tested a redirect against a real local HTTP server, and handled compression interacting with redirects.

Closing it

I had working code that hadn’t been pushed. I could have pushed it and asked the maintainers to choose, or argued that mine came first. But mine was a subset of theirs. Two open pull requests for one bug ask the maintainers to compare them, and the only person that comparison helps is whoever wrote the losing one.

So I closed mine about an hour and a half after theirs opened, with one comment saying that #2239 covered my fix and more, and naming what it added. #2239 merged that afternoon and closed #2233.

It didn’t sting. I’m helping out where I can, and while it’s exciting when a fix for an issue I found uses my code, it’s also fine when the maintainers can do it better. The bug report started the work, #2239 links back to my pull request, and the review discussion is where the order change was asked for. Part of working with other people is recognizing the quality of their work, crediting them, and encouraging their solution when it’s better than your own.

What I’d do differently

  • Propose the clean fix even when it isn’t yours to make. If the right change touches something you don’t own, put it in the description next to the change you made, and let the people who own it choose.
  • Read a run of review findings as a design signal. One finding is a bug. Four in the same mechanism mean the mechanism is wrong.
  • When someone else’s fix covers yours, say so and close quickly. The longer two fixes sit side by side, the more work you create for the people reviewing them.

If you use the TypeScript SDK

The fix shipped in @microsoft/kiota-http-fetchlibrary 1.0.0-preview.115 on November 26. On Node, earlier versions can resend a redirected request to the original URL when the redirect target returns a retryable status. If you use the default middleware, update to preview.115 or later. If you build your own middleware list, the update leaves your order alone, so put RedirectHandler before RetryHandler yourself. Browser clients aren’t affected.

← All writing