This repository was archived by the owner on Jul 16, 2026. It is now read-only.
fix(shadow_mode): preserve original_action for throttle decisions#145
Merged
Conversation
The wrap() function was using a binary expression decision.original_action = was_allowed and "allow" or "reject" which always sets original_action to either "allow" or "reject", lost the "throttle" action when wrapping a throttle decision in shadow mode. Fix by assigning decision.action directly before overwriting it. Fixes #144
…ion fallback The first attempt used decision.action directly, which broke existing tests where the decision table has no .action field (only .allowed). The correct fix: use decision.action when it is non-nil (preserving 'throttle' correctly), and fall back to the was_allowed-derived value only when decision.action is nil. Fixes #144
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
shadow_mode.wrap()setoriginal_actionto"allow"for throttle decisions, losing the"throttle"action valuewas_allowed and "allow" or "reject"expression with direct preservation ofdecision.actionbefore it is overwrittenDetails
The old code in
src/fairvisor/shadow_mode.lua:This expression is binary: it can only produce
"allow"or"reject". When acost_basedrule with athrottlestaged action is evaluated under a shadow-mode policy,_build_decisionproduces a decision withaction = "throttle"and no.allowedfield. Inwrap(),was_allowed = ("throttle" ~= "reject") = true, sooriginal_actionbecomes"allow"— not"throttle".The
original_actionfield is read by_finalize_decisioninrule_engine.luaaseffective_action, which determines the SaaS auditevent_type. With the bug, a shadow throttle was logged asevent_type = "request_rejected"with action"allow", rather thanevent_type = "request_throttled".The fix simply captures
decision.action(the actual value) before overwriting it:This is safe for all existing cases:
action = "reject"→original_action = "reject"✓action = "allow"→original_action = "allow"✓action = "throttle"→original_action = "throttle"✓ (was broken)Fixes #144
Test plan
original_action = "throttle"lua-qualityCI check passesvalidate-config-and-policiesCI check passese2e-smokeCI check passes