Repository navigation
feat!: tw-breaker, one circuit-breaker state machine for both gateways; hidden-text scan in tw-guard - #155
Merged
Conversation
fylorn
force-pushed
the
feat/tw-breaker
branch
2 times, most recently
from
September 24, 2026 02:30
4b6dd65 to
22c0ff6
Compare
…s; hidden-text scan in tw-guard The desktop's upstream health, the server edition's route health and its MCP breaker each carried their own state machine. Their premises differ — one user in one process that fails open, versus replicas sharing Redis that filter a tripped route out — but the machine is the same: closed, open, half-open once the cooldown is over, and a probe deciding. tw-breaker is that machine and nothing else: - `Breaker` is plain, serialisable data; transitions are pure functions of it, a `Policy` and a time the caller supplies. Where it lives — a mutex, a Redis key — is the caller's business. `Breakers<K>` is the in-process keyed set. - A `Trip` is either N consecutive failures or an error rate over a window; the window is counted by whoever stores the samples. - A cooled breaker reads as half-open with nobody nudging it. The server edition moved a route from open to half-open only when a request on that route completed, and an open route is never picked — it stayed open until its Redis key expired. - Half-open admits; `probes` successes close it, one failure reopens it. A late result while open still counts. The desktop's `health` runs on it with the same policy (3 failures, 60 s, one probe) and keeps its own rules on top: fail open when every candidate is down, bypass a single candidate. A half-open provider still reads "ok" on the upstreams page. `hidden` (invisible and look-alike characters) moves from tw-scan into tw-guard, for the server edition to scan requests with. `Kind::smuggles` names the two kinds with no legitimate use in any text — tag characters and bidi overrides; zero-width joiners make emoji and Cyrillic is Russian. The config scan grades by it too. BREAKING: tw_gateway::health::State is tw_breaker::State (adds HalfOpen); tw_scan::hidden is tw_guard::hidden. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
force-pushed
the
feat/tw-breaker
branch
from
September 24, 2026 02:45
22c0ff6 to
032f81b
Compare
This was referenced Sep 24, 2026
Merged
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.
tw-breaker
The desktop's upstream health, the server edition's route health and its MCP breaker each had their own state machine. Their premises differ:
The machine is the same, so it is now shared:
Breakeris plain, serialisable data. Transitions are pure functions of it, aPolicy, and a time the caller supplies. Storage is the caller's: a mutex (Breakers<K>) or a Redis key.Tripis either N consecutive failures or an error rate over a window. The window is counted by whoever stores the samples; the machine only needs the tally.probessuccesses close it, and one failure reopens it and restarts the cooldown. A late result that arrives while open still counts.The desktop's
healthruns on it with the same policy as before: 3 failures, 60 s cooldown, one probe. Its own rules stay on top: fail open when every candidate is down, and bypass the breaker for a single candidate. A half-open provider still reads "ok" on the upstreams page.hidden → tw-guard
hidden(invisible and look-alike characters) moves from tw-scan into tw-guard, so the server edition can scan requests with it.Kind::smugglesnames the two kinds with no legitimate use in any text: tag characters and bidi overrides. Zero-width joiners build emoji, and Cyrillic is just Russian. The config scan grades by the same method.Tests
admit, error-rate thresholds, a JSON round trip, and keyed breakers on a controllable clock.smuggles: emoji, Russian and Arabic text are not flagged.cargo test --workspace, clippy andscripts/smoke.sh(55 passed, 0 failed) all pass.Breaking:
tw_gateway::health::Stateis nowtw_breaker::State, which addsHalfOpen;tw_scan::hiddenis nowtw_guard::hidden.🤖 Generated with Claude Code