Skip to content

Fix race condition and stale references in stripOAIGen#162

Open
fkollmann wants to merge 1 commit intogo-openapi:masterfrom
smartpricer:master
Open

Fix race condition and stale references in stripOAIGen#162
fkollmann wants to merge 1 commit intogo-openapi:masterfrom
smartpricer:master

Conversation

@fkollmann
Copy link
Contributor

@fkollmann fkollmann commented Feb 20, 2026

Fixes non-deterministic behavior in flatten.go by:

  1. Sorting keys when iterating newRefs.
  2. Reloading spec analysis before stripOAIGen to fix stale references.
  3. Updating parents list of target definitions when handling transitive merges to prevent dangling references.

Fixes the following errors when running go-swagger flatten:

  • object has no key "XXXXOAIGen": JSON pointer error
  • object has no key "XXXXOAIGen1": JSON pointer error

Note: This PR was created using gemini-3-pro-preview.

- object has no key "XXXXOAIGen": JSON pointer error
- object has no key "XXXXOAIGen1": JSON pointer error

Signed-off-by: Felix Kollmann <mail@fkollmann.de>
@fredbi
Copy link
Member

fredbi commented Mar 3, 2026

Interesting. Could you elaborate on the issue this PR is supposed to fix?

I've no doubt this is fixing a bug (there are likely many still out of this kind), I'd like to have an understanding of what is being fixed. For example, you could add a test case that demonstrates the failure and your fix.

@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.49%. Comparing base (3beae5a) to head (5c7e54b).
⚠️ Report is 9 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
flatten.go 75.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #162      +/-   ##
==========================================
- Coverage   91.67%   91.49%   -0.18%     
==========================================
  Files          17       17              
  Lines        2017     2034      +17     
==========================================
+ Hits         1849     1861      +12     
- Misses        111      115       +4     
- Partials       57       58       +1     

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

Copy link
Member

@fredbi fredbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case to showcase the bug this PR is fixing and demonstrate the fix.

fredbi added a commit that referenced this pull request Mar 3, 2026
chore: relint, tests, doc, ci

Onboards #162 (credit https://github.com/fkollmann) with proper integration test that managed to reproduce the issue (on windows only, on go1.26 only) and demonstrate the fix.

NOTE: CI timeout has been raised to 30m - integration tests now take 26m, since we don't have a minimal repro case available to cover the bug fixed thanks to #162.
@fredbi
Copy link
Member

fredbi commented Mar 3, 2026

@fkollmann I've managed (by luck!) to find a test that reproduces a behavior similar to the one that you describe.
Hopefully this is a correct guess. The fix that you propose indeed repairs this issue. However, my test case (flattening of the expanded version of the full Azure API) doesn't manage to cover all your changes.

I agree that there was a bug or latent bug there and that it is super hard to reproduce.

Besides, I've observed some interesting, yet mysterious patterns:

  • could only be triggered with go1.26, on windows for which my flatten failed consistently, while correct on all other environments in the CI matrix

I've cherry-picked your commit (you are credited) to put it together with the added test.

The issue I have now is that the CI needs almost 30m to create the conditions of the test. So, if you have a smaller repro case than what I've used (Azure spec is huge), you're more than welcome to push a CI-friendly test case.

Thanks for the thorough bug sleuthing anyway

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