fix: decouple HTTP status from body code in Zuul BlockResponse - #3639
fix: decouple HTTP status from body code in Zuul BlockResponse#3639userofthefreedom wants to merge 1 commit into
Conversation
ZuulBlockFallbackProvider reused BlockResponse#code as both the response body's business code and the actual HTTP status code, so a custom fallback provider could not set body code (e.g. 10018) while keeping HTTP status 200. Add a separate `status` field for the HTTP status, keep `code` for the body only, and keep the old 3-arg constructor for backward compatibility (status defaults to code). Fixes alibaba#2985
BitDive Runtime Review - PR #3639PR: #3639 SummaryThis PR adds a separate Runtime Verification Matrix
How to read BitDive evidenceBehavior Δ in the matrix and the red/green
GitHub strips Review scope and validation coverage
Not covered at runtime: All 4 changed production files are in adapter modules not deployed in the sentinel-dashboard Docker runtime. The deployed JVM cannot load or invoke Change #1 - Decouple HTTP status from body code in BlockResponseAdds a Behavior contract# BlockResponse — Zuul/Zuul2 fallback: HTTP status decoupled from body code
- BlockResponse(int code, String message, String route)
- this.status = code // HTTP status conflated with business code
- SentinelZuulPreFilter.run(): setStatusCode(response.getCode())
- SentinelZuulEndpoint.apply(): response.getCode() → HTTP status
+ BlockResponse(int status, int code, String message, String route)
+ this.status = status // independent HTTP status field
+ BlockResponse(int code, String message, String route) [@Deprecated]
+ → this(code, code, message, route) // backward compat: status = code
+ SentinelZuulPreFilter.run(): setStatusCode(response.getStatus())
+ SentinelZuulEndpoint.apply(): response.getStatus() → HTTP status
+ toString(): unchanged — body serialization preserves business code only
# unit tests: 4/4 pass (2 per adapter module)
# runtime trace: adapter modules not deployed — deploy canary shows zero dashboard drift# GET /version — deploy canary (dashboard runtime, not adapter code)
HTTP 200 → 200
body: {success:true,code:0,msg:success,data:1.8.11} — byte-identical
SQL: none → none
writes: none → none
downstream REST: none → none
execution tree: 1 node → 1 node
# first divergence: NONE — both baselines CLEAN
# scope: proves deploy health only; adapter modules not on classpathScenario matrix
Trace evidence
Contract delta
Key trace deltaFirst meaningful divergence: NONE — deploy canary trace pair shows equivalent contracts.
Follow-Ups
RecommendationApprove with notes. The change is correct, minimal, backward-compatible, and symmetric across both adapter modules. Unit tests verify both backward compatibility and the new independent status/code feature. Two runtime checks confirm the dashboard is unaffected. The main limitation: because adapter modules are not deployed in the test stack, the actual fix is verified only at the unit-test level — an end-to-end Zuul filter-chain test would strengthen confidence but is not blocking. |
oss-sentinel-ai
left a comment
There was a problem hiding this comment.
Summary
This PR modifies 6 file(s) with 222 lines of changes. Providing observations for the author to consider.
Automated review by github-manager-bot
ZuulBlockFallbackProvider reused BlockResponse#code as both the response body's business code and the actual HTTP status code, so a custom fallback provider could not set body code (e.g. 10018) while keeping HTTP status 200.
Add a separate
statusfield for the HTTP status, keepcodefor the body only, and keep the old 3-arg constructor for backward compatibility (status defaults to code).Fixes #2985
Describe what this PR does / why we need it
Zuul adapter's ZuulBlockFallbackProvider reused BlockResponse#code as both the
response body's business code and the actual HTTP status code, so a custom
fallback provider could not set the body code (e.g. 10018) while keeping the
HTTP status 200.
Does this pull request fix one issue?
Fixes #2985
Describe how you did it
Added a separate
statusfield toBlockResponse(used for the real HTTPstatus) and kept
codepurely as the body's business code. The old 3-argconstructor is kept for backward compatibility (status defaults to code).
Applied the same change symmetrically to sentinel-zuul-adapter and
sentinel-zuul2-adapter.
Describe how to verify it
See new
BlockResponseTestin both modules: a custom provider can now returnnew BlockResponse(200, 10018, ...)to get HTTP status 200 with body{"code":10018,...}.Special notes for reviews
Existing 3-arg constructor is unchanged in behavior (deprecated but not
removed), so no breaking change for current users.