fix(router): preserve fang order#655
Merged
Merged
Conversation
kanarus
approved these changes
Apr 12, 2026
Member
kanarus
left a comment
There was a problem hiding this comment.
- After further thought, the root cause wasn't actually the fangs order during compression, but rather a bug in
router::base::Router::apply_fangsitself (which is called fromOhkami::into_router). - Thanks for catching this! Your feedback helped me realize that the logic for adding fangs in apply_fangs shouldn't just be a simple push; they actually need to be added to the outside.
- Since this wasn't an issue with your code, I went ahead and committed the fix myself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes fang ordering during final router compression for single-child static chains.
Without this change, request context written by a parent fang could become invisible to a nested top-level fang on a child
Ohkamiafter compression.Problem
I added two regression tests (/src/ohkami/mod.rs):
parent_context_auth_is_visible_to_nested_top_level_fang_in_realistic_orderparent_context_auth_is_visible_to_nested_local_route_fangs_in_realistic_orderThe first test failed before this change:
Ohkamitries to read itThe second test passed:
This showed that the issue was specific to nested top-level fang composition, not local per-route fangs.
Root cause
In
router/final.rs, compression of a node with its single static child merged fang lists in the wrong order:base.fangses.append(child.fangses)That inverted the intended outer/inner behavior for compressed nested top-level fangs.
Fix
During compression, merge fang lists in the correct order so that:
This preserves the expected execution order and makes compressed behavior consistent with the non-compressed case.
Validation
Ran:
Both regression tests pass, and the relevant
ohkamilibrary test suite passes as well.