Skip to content

Define fail open#1587

Open
Chigybillionz wants to merge 9 commits into
Stellar-Mail:mainfrom
Chigybillionz:define-fail-open
Open

Define fail open#1587
Chigybillionz wants to merge 9 commits into
Stellar-Mail:mainfrom
Chigybillionz:define-fail-open

Conversation

@Chigybillionz

Copy link
Copy Markdown

Close #1552

Summary of the issue
Define fail-open and fail-closed behavior for abuse-service outages (#1552) so that dependency failures do not accidentally grant universal access (fail-open when it should be risk-controlled) or universally deny requests without an explicit risk decision.

Root cause
Dependency-failure policy for the abuse checks was not consistently established/documented such that each protected abuse decision could deterministically fall back (allow vs deny) with observable reasoning when the dependency (rate-counter storage) was unavailable.

Solution implemented

Classified abuse checks by outage policy (fail_open vs fail_closed) per protected route.
Wrapped each abuse dependency operation with a shared fallback mechanism that:
chooses the correct fail-open/fail-closed behavior,
attaches outage metadata to the decision,
emits metrics and audit events so the fallback choice is observable.
Ensured high-risk mutation behavior fails closed by propagating the abuse fallback outage decision to the API layer as a dependency-unavailable error.

Affected files

src/server/api/abuse-service.ts
src/server/api/postage-service.ts
src/server/api/metrics.ts
tests/unit/api/abuse-service.test.ts
Fix explanation

Explicit outage policy per protected route
ABUSE_OUTAGE_POLICIES explicitly assigns an outage policy for every AbuseCheck under the protected postage_submit route.
Deterministic fail-open / fail-closed fallback
withOutagePolicy(route, check, operation) catches dependency errors and returns:
fail_open => allowed: true, flagged: true, and outage metadata
fail_closed => allowed: false, retryAfterSeconds: 60, and outage metadata
Fallback decisions are observable
observeAbuseFallback(...) emits:
metrics.incrementCounter("abuse_dependency_fallback", fields)
metrics.recordAuditEvent("abuse.dependency_fallback", fields)
Fields include route, check, policy, decision, and errorType.
High-risk mutations fail closed where required
submitPostage routes dependency-unavailable fallout into a 503 dependency_unavailable error using the abuse decision’s outagePolicy / outageRoute.
For fail_closed checks, abuse decisions become denies, preventing accidental acceptance during outage conditions.

Code changes

src/server/api/abuse-service.ts
Added/used ABUSE_OUTAGE_POLICIES
Added/used withOutagePolicy and observeAbuseFallback for deterministic fallback + observability
src/server/api/postage-service.ts
Mapped abuse outage decisions to an explicit 503 dependency_unavailable response (with outage metadata)
src/server/api/metrics.ts
Existing stubs used by unit tests for emitted metrics/audit verification
tests/unit/api/abuse-service.test.ts
Added/kept tests for outage policy coverage, fail_open/fail_closed behaviors, and timeout/dependency failure handling
Testing steps (how to verify the fix)

Run unit tests:
npm test
Specifically validate:
tests/unit/api/abuse-service.test.ts
ensures outage policy coverage
ensures fail_open vs fail_closed behavior
ensures metrics + audit events are emitted
ensures timeout/dependency failure paths behave as fail_closed where required

Please kindly review this task. If there are any corrections, improvements, adjustments, or merge conflicts that you notice regarding my implementation, I'd really appreciate your feedback. I'd also love to hear your overall review of my work on this branch. Thank you!

@kryputh

kryputh commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

@Chigybillionz tell your agent to run bun command with prettier to format the code

Then check ✅ it again with bun after with bun prettier check ✅...

That the case for all your issues. If you have CODEX try using it or just connect your GitHub with GPT and use chatGPT work with the GitHub mcp

It should also solve it

@Chigybillionz

Chigybillionz commented Jul 21, 2026 via email

Copy link
Copy Markdown
Author

@Chigybillionz

Chigybillionz commented Jul 21, 2026 via email

Copy link
Copy Markdown
Author

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.

Define fail-open and fail-closed behavior for abuse-service outages

2 participants