Skip to content

Merge - #99

Open
imranq2 wants to merge 1057 commits into
imranq2:mainfrom
icanbwell:main
Open

Merge#99
imranq2 wants to merge 1057 commits into
imranq2:mainfrom
icanbwell:main

Conversation

@imranq2

@imranq2 imranq2 commented Dec 23, 2025

Copy link
Copy Markdown
Owner

No description provided.

imranq2 and others added 30 commits April 21, 2026 14:17
…egration and enhance .gitignore for cache management
…n options and enhance comments for better understanding
Co-authored-by: aikido-pr-checks[bot] <169896070+aikido-pr-checks[bot]@users.noreply.github.com>
…onment variables for marketplace integration
imranq2 added 30 commits July 15, 2026 07:53
BAI-315 Document Bedrock transport options
BAI-316 Add MODEL_ROUTING_QWEN_ENABLE_THINKING env var
…ey're recorded instead of surfacing as unhandled 500s
BAI-317 Make native Bedrock connect/read timeouts explicit env vars
…nippet

Opening marker used <<< instead of >>>, matching docs/coding_model_router.md convention.
BAI-318 Move model_routing_guide.md from language-model-gateway-configuration
…gn docs

router.py's and coding_model_router.md's docstrings claimed this router is
deployed per-user/local, which justified an otherwise-spoofable custom-header
user_id fallback. That assumption no longer holds (shared multi-tenant
deployment) -- flagged as a known gap rather than silently left stale.

Also fixes a pre-existing bug in pre-commit-hook (line 12 executed
$GIT_PROJECT_ROOT as a command instead of cd-ing into it, breaking every
commit in this repo since the initial commit) and adds the design spec and
implementation plan for a session-savings statusline endpoint, to be
implemented task-by-task on this branch.
format_savings_line() now wraps all field-access and formatting in
try-except, returning None silently on any TypeError, ValueError,
AttributeError, or KeyError. This ensures the statusline command never
prints a raw error string or traceback that would break Claude Code's UI,
regardless of whether the gateway returns wrong field types
(total_savings_usd as string, tier cost_usd as non-numeric, tiers as
non-dict, etc.).

Add 3 test cases covering the previously-crashing malformed-type inputs.
Adds a Prerequisites/Setup/Troubleshooting walkthrough (absolute path,
chmod +x, manual test before wiring into settings.json, restart requirement)
and ties MODEL_ROUTING_GATEWAY_URL to the same gateway_url local var as
ANTHROPIC_BASE_URL in the claude-router() shell function, so the two env
vars can't drift apart when swapping between local and production.
Corrects the collection-name default (usage_sessions -> model-router-sessions)
in SessionSavingsReader/SessionSavingsRouter and their docstrings, plus stale
usage_sessions and curl references in the session-savings-statusline design
doc and plan doc. No runtime behavior change: api.py already passes the
correct env-var-driven collection name to both reader and writer.
…g a repo clone

Moves claude_code_statusline.py into language_model_gateway/static/, which
is already copied into the runtime Docker image and mounted at /static by
create_app() -- so it's now downloadable via
$MODEL_ROUTING_GATEWAY_URL/static/claude_code_statusline.py with no new
route, no Dockerfile change, and no new auth surface. Updates the test's
file path accordingly and rewrites the docs/model_routing_guide.md setup
walkthrough to curl the script instead of cloning this repo.
Adds a shell function alongside claude-router() in the ~/.zshrc snippet
that downloads the statusline script from the gateway, chmods it, and
prints the exact settings.json snippet (with resolved absolute path) to
add -- automating the manual curl/chmod/realpath steps in the Statusline
setup walkthrough. The manual steps stay documented as the explicit
alternative for anyone who wants to see what the function does.
…and remove spoofable usage-attribution fallback

Guards claude_code_statusline.py's main() against valid-but-non-dict stdin
payloads, corrects misleading second-terminal-tab troubleshooting advice in
model_routing_guide.md, and removes the unverified X-Model-Routing-User-Id
custom-header fallback in router.py._get_auth_info since it let any caller
attribute usage/cost to another user's identity on this shared multi-tenant
router. Usage attribution now requires a verified OIDC token; the
session-savings endpoint's session_id-as-capability design is confirmed
necessary (Claude Code never exposes its OAuth credential to subprocesses)
and its exception is now tracked in BAI-320.
The parenthetical after "saved" showed each tier's actual cost with no
label, reading as if it broke down the savings total instead of being a
separate cost figure. Prefixes it with "costs:" and shows the serving
provider per tier (Anthropic/AWS), sourced from a new backend field now
persisted in the session rollup alongside the existing per-tier model name.
…rsation

Group-dropping under context pressure only ever protected the last message
when it was literally role=="user" — a conversation resumed right after a
tool call (Read, Bash, AskUserQuestion, etc.) ends in a "tool" message
instead, so nothing stopped every remaining group from being dropped down
to just the system message. Every backend this router talks to (Bedrock
Converse, Bedrock Mantle/Qwen chat templates) rejects a conversation that
doesn't start with a user turn, producing the
"ValidationException: A conversation must start with a user message" error.

Group-dropping now stops at the last group that starts with role=="user"
and can never cut past it, even if still over budget afterward.
BAI-319 add session-savings statusline for model routing
_apply_output_budget_cap floored max_tokens at 1024 unconditionally,
even when the undroppable message tail (protected by BAI-321's last-
user-group rule) left less than 1024 tokens of headroom -- guaranteeing
input+output exceeded backend_max_context_tokens and got rejected by
Bedrock/Mantle with "maximum context length" ValidationException.

Clamp the floor to actual headroom instead of blindly forcing 1024.
The output-cap log line always printed the margin-based formula
parenthetical, even when the new hard_headroom clamp produced a
different safe value, misleading debugging of a recurrence.
BAI-322 clamp output-token floor to hard context headroom
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.

3 participants