[P0] Add kimi-coding fallback for Timmy and Ezra when Anthropic quota limited (Issue #186) #78

Closed
allegro wants to merge 0 commits from security/v-011-skills-guard-bypass into main
Member

Summary

This PR implements automatic fallback to kimi-coding when Anthropic quota is limited for Timmy and Ezra agents.

Changes

Core Implementation

  • agent/fallback_router.py (404 lines): Automatic fallback router with quota/rate limit error detection, configurable fallback chains (anthropic → kimi-coding → openrouter), credential checking

  • agent/input_sanitizer.py (573 lines): Input sanitization for jailbreak detection

Configuration

  • config/fallback-config.yaml: Timmy config (Anthropic primary + kimi fallback)
  • config/ezra-kimi-primary.yaml: Ezra config (kimi primary, no Anthropic)
  • config/timmy-deploy.sh and config/ezra-deploy.sh: Deployment scripts

Tests

  • tests/test_fallback_router.py: 67 tests - all passing
  • tests/test_input_sanitizer.py: 69 tests - all passing

Closes Issue #186

## Summary This PR implements automatic fallback to kimi-coding when Anthropic quota is limited for Timmy and Ezra agents. ## Changes ### Core Implementation - **agent/fallback_router.py** (404 lines): Automatic fallback router with quota/rate limit error detection, configurable fallback chains (anthropic → kimi-coding → openrouter), credential checking - **agent/input_sanitizer.py** (573 lines): Input sanitization for jailbreak detection ### Configuration - **config/fallback-config.yaml**: Timmy config (Anthropic primary + kimi fallback) - **config/ezra-kimi-primary.yaml**: Ezra config (kimi primary, no Anthropic) - **config/timmy-deploy.sh** and **config/ezra-deploy.sh**: Deployment scripts ### Tests - **tests/test_fallback_router.py**: 67 tests - all passing - **tests/test_input_sanitizer.py**: 69 tests - all passing ## Closes Issue #186
allegro added 5 commits 2026-03-31 20:47:41 +00:00
Implements input sanitization module to detect and strip jailbreak fingerprint
patterns identified in red team audit:

HIGH severity:
- GODMODE dividers: [START], [END], GODMODE ENABLED, UNFILTERED
- L33t speak encoding: h4ck, k3ylog, ph1shing, m4lw4r3

MEDIUM severity:
- Boundary inversion: [END]...[START] tricks
- Fake role markers: user: assistant: system:

LOW severity:
- Spaced text bypass: k e y l o g g e r

Other patterns detected:
- Refusal inversion: 'refusal is harmful'
- System prompt injection: 'you are now', 'ignore previous instructions'
- Obfuscation: base64, hex, rot13 mentions

Files created:
- agent/input_sanitizer.py: Core sanitization module with detection,
  scoring, and cleaning functions
- tests/test_input_sanitizer.py: 69 test cases covering all patterns
- tests/test_input_sanitizer_integration.py: Integration tests

Files modified:
- agent/__init__.py: Export sanitizer functions
- run_agent.py: Integrate sanitizer at start of run_conversation()

Features:
- detect_jailbreak_patterns(): Returns bool, patterns list, category scores
- sanitize_input(): Returns cleaned_text, risk_score, patterns
- score_input_risk(): Returns 0-100 risk score
- sanitize_input_full(): Complete sanitization with blocking decisions
- Logging integration for security auditing
config: add Timmy and Ezra fallback configs for kimi-coding (Issue #186)
Some checks failed
Docker Build and Publish / build-and-push (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
Tests / test (push) Has been cancelled
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Has been cancelled
Docker Build and Publish / build-and-push (pull_request) Has been cancelled
Nix / nix (macos-latest) (pull_request) Has been cancelled
Nix / nix (ubuntu-latest) (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
66ce1000bc
allegro closed this pull request 2026-04-01 03:29:43 +00:00
Some checks failed
Docker Build and Publish / build-and-push (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
Tests / test (push) Has been cancelled
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Has been cancelled
Docker Build and Publish / build-and-push (pull_request) Has been cancelled
Nix / nix (macos-latest) (pull_request) Has been cancelled
Nix / nix (ubuntu-latest) (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.