Found while verifying the previous commit's fix doesn't miss siblings:
three of Menivor's own backend features route through this same gateway
with the identical vulnerable shape (single `user` message, no `system`
message, static instructions dominating a short variable section) at
temperatures the 0.7 default left unprotected --
app/domains/appaudit/rewrite.py (0.6), app/domains/applisting/hookscript.py
and app/domains/adclone/relay_writer.py (0.7, exactly at the old boundary).
Lowered the default to 0.5: every confirmed real caller that sets a
non-zero temperature today does so at 0.6+ specifically for sampling
variety, so 0.5 now covers all of them. No caller found anywhere in the
portfolio relies on caching in the 0.5-0.7 band, so this is pure
additional coverage, not a tradeoff -- confirmed low-temperature/no-temperature
consumers (CalDesk at 0.2, Kamiko's persona chat and Bidstage's structured
extraction, both of which omit temperature) are unaffected either way.
Extended the regression test to assert both newly-covered real
temperatures (0.6, 0.7) also bypass the cache, not just the headline 0.9
case. 22/22 tests still pass.
Live bug (Menivor /tools free generators, all of hooks/script/hashtags/
titles/captions/ideas/reel): every visitor got an earlier, unrelated
visitor's cached answer for their own topic. Root cause is a second,
distinct instance of the same class of bug the Oct 29 system-prompt fix
(dfe50215) addressed for Kamiko: Menivor sends one `user` message that
mixes a long static instruction block with the short, varying topic, at
`temperature: 0.9` for creative variety. There is no `system` message to
exclude, so the whole blob is embedded and the static instructions
dominate the vector -- two unrelated topics for the same tool cosine-match
at 0.96-0.98, past the default 0.95 threshold.
Reproduced live against relay.ereboslab.com with Menivor's real production
key: a houseplant-subscription hooks request returned `x-relay-cache: hit`
(similarity 0.9919) on its very first call, and a completely unrelated
dog-leash request then hit the *same* cached houseplant answer verbatim
(similarity 0.9539).
Fix: a request with an explicit `temperature` above a new
`max_temperature` tunable (default 0.7, env override
RELAY_SEMANTIC_CACHE_MAX_TEMPERATURE) is never looked up or stored --
the caller already signaled it wants non-repeatable output. Requests with
no `temperature` at all, or a low one, are unaffected: every low-temperature
consumer found across the portfolio (CalDesk/Bidstage at 0.6-0.7, Kamiko's
persona chat) keeps caching exactly as before.
crates/relay-semantic-cache: 22/22 unit tests pass, incl. a new
regression test reproducing the Menivor shape (single user message, no
system prompt, two unrelated topics at temperature 0.9) and asserting
both miss the cache and reach the inner layer. cargo check/test clean;
cargo clippy has 2 pre-existing failures in untouched files (setup.rs,
embed.rs), confirmed present on main before this change, not introduced
by it.
Relay serves many Railyard products from one shared gateway, each with its
own API key, but the upstream TensorZero inference-listing, dataset,
evaluation and /internal/* routes carry zero per-key scoping (unlike
/relay/traces, /relay/billing/* and the provider-key/catalog-price editors,
which already check require_operator or scope to the caller's own key).
Reproduced live: used Rally's real production key to run one inference with
a unique marker prompt, then fetched that same inference's full prompt,
output and tags (including its owning api_key_public_id) using Menivor's
completely different key via POST /v1/inferences/get_inferences - any
tenant could read any other tenant's full inference history, datasets, and
raw object-storage bytes.
Fix: route_layer a require_operator_middleware over build_observability_routes
(list/get_inferences), build_datasets_routes, build_optimization_routes,
build_gepa_routes, build_evaluations_routes, and all of
build_internal_non_otel_enabled_routes except /internal/autopilot/status
(which must stay fully unauthenticated as a liveness probe). A missing
principal still passes through unchanged, so a single-tenant deployment
with [gateway.auth] off (the TensorZero default, and every e2e test that
doesn't configure auth) is unaffected.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The cache embedded the whole conversation (system + user turns) for
similarity matching. A tenant with a large static system prompt (e.g. a
~500-token persona) dwarfs a short user turn in that embedding, so
completely different questions under the same persona cosine-matched at
0.996+ and collapsed onto the same cached answer (real-world case:
Kamiko's chat answering every visitor with one frozen line).
Fold system/developer messages into the exact-match `scope` hash instead
of the embedded `prompt`: different personas still never share an entry
(scope differs), but the embedding now only reflects the turns that
actually vary per request. Tenants with short/no system prompts are
unaffected (same prompt as before, since there's nothing to exclude).
Added regression tests at both the request-shaping level (request.rs) and
the live middleware level (middleware.rs) reproducing Kamiko's own repro:
3 different questions, same persona, must each miss and get a distinct
answer, and legitimate same-tenant caching must still hit.
New relay-semantic-cache crate: chat requests split into a scope (hash of
model, sampling, tools, format) and an embedded prompt; a stored answer is
reused when tenant and scope match, cosine similarity clears the
threshold and it has not expired. Embeddings come from a local hashed
n-gram embedder or any OpenAI-compatible embeddings route (Relay's own
included); stores are in-memory or pgvector. The gateway mounts it inside
guardrails and outside spend caps and billing when RELAY_SEMANTIC_CACHE is
memory or pgvector, keyed by organization/workspace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Relay had no content controls (recount I19): any prompt went to the provider.
relay-guardrails (new crate, tested without TensorZero):
- detectors for e-mail, phone (international or North American formatted),
payment cards (Luhn), IBANs (mod-97), US SSNs and API secrets (sk-, AKIA,
gh*_, xox*, PEM private keys); checksums keep order numbers and amounts;
- pii: redact (in place, [REDACTED_KIND], x-relay-guardrails: kind=n on the
answer) or block (400 guardrail_blocked, never echoing the data);
- operator deny rules (regex + message) and max_prompt_chars;
- the policy comes from RELAY_GUARDRAILS_JSON or RELAY_GUARDRAILS_PATH and is
validated at startup (bad JSON, unknown fields or a bad regex stop the
gateway); without one nothing changes.
The gateway adds the layer inside auth and outside spend caps, metering and
billing, so a refused prompt never opens a hold or reaches a provider and a
redacted one is what billing and the provider see (cargo check -p gateway).
Tests: 10 (policy + the axum layer: upstream sees only the redacted body,
blocked requests never reach inner layers, other routes/bad JSON/clean
prompts untouched, oversized bodies refused). Relay owned crates with a
scratch database: 240 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Railyard side of PY1.4 (ADR RY-0003). Acceptance:
1. Bridge `ai` gives a Scribase project environment one key (ry_ai_..., shown
once, to the Scribase control plane only, stored here as SHA-256; `rotate`
revokes the old one) and a one-time link to /connect/ai (15 minutes), the
only place a provider key is typed. It is sealed with AES-256-GCM under
RAILYARD_CREDENTIALS_KEY, bound to org and provider, and only a
four-character hint is ever read back.
2. BYOK only: POST /api/v1/ai/chat/completions (OpenAI-compatible) refuses
with 403 byok_required when the org has not connected the provider the
model names, and never calls Relay then. When it does call, the customer's
key fills that provider's slot and every other slot carries a refusal
marker, so Relay (caller credential wins) can never use our keys, not even
on failover; a test pins the slot list to Relay's PROVIDER_KEY_SLOTS.
Credentials in a request body are refused.
3. Daily and monthly token caps per key (429 with the period); usage (atomic
rpc) and one trace per call (model, provider, status, tokens, latency),
read per project key by the bridge `ai_usage` route for the Scribase tab;
Relay traces carry tensorzero::tags for the same filter.
4. Copy says "your provider bills you directly"; no credits are included
anywhere (copy lint over the connect page and every gateway message).
apps/relay/config/tenants/README.md records the tenant rules.
Migration: apps/console/db/migrations/0003_ai_gateway.sql (idempotent;
applied twice to a scratch local cluster by test/migration.test.ts).
Env: RELAY_URL (var), RELAY_TENANT_KEY, RAILYARD_CREDENTIALS_KEY (secrets).
Tests: console 63/63 (gateway 6, bridge 12, migration 3, repo 5), tsc clean,
tests/contract 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
H10: llama-3.1-8b-instant runs GPT-OSS 20B on Groq ($0.075/$0.30 per 1M)
but sold at $0.05/$0.08. It is now priced at cost x 1.25 (93750/375000
micro-USD per 1M). A contract test ties every Groq compatibility alias to
its first leg's built-in cost and fails if any sells below it.
H11 (workflow side): ci.yml lists its pull_request activity types; the
infra-box job guard is deny-by-default for any event the workflows do not
declare.
Denylist 2026-09-29.2 is vendored at policy/copy-denylist.json with a
zero-dependency JavaScript matcher (CLAIMS-RULES section 4) that the
console, CLI and MCP packages share. Tests: version pin, byte-for-byte
match with gtm/policy, the per-rule self-test for every product, and a
failing fixture for each phrase added in .2. A root .gitleaks.toml
allowlists the fake AWS key hit example, as infra-box already does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implements OSS9. New relay-traces crate reads chat/json inferences by the
GIN-indexed tensorzero::api_key_public_id tag, joined with model_inferences
for model, provider, tokens, latency, cost and finish reason.
- GET /relay/traces: caller's own traces, newest first, keyset paging,
window bounded (1-2160 h). Operator keys may use scope=all and key=.
- GET /relay/traces/{inference_id}: model calls plus stored bodies; a trace
owned by another key returns 404, same as a missing one.
- relay-traces-retention: 14 d bodies, 90 d metadata (OD-RY2 defaults, env
overridable), batched deletes against one cutoff, dry-run mode. Shipped in
the relay image; systemd service/timer in crates/relay-traces/deploy (not
installed).
- Relay UI: /observability/keys list (live refresh on the first page) and
detail page; sidebar "Key Traces".
- No new tables or migrations.
Tests: 8 unit tests; live test on a scratch copy of the inference tables
proves key isolation, operator scope, paging and window-exact retention;
UI vitest 7/7, tsc and eslint clean; cargo check -p gateway clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude-haiku (claude-haiku-4-5) and claude-sonnet-5 route Anthropic first
and the OpenRouter copy second; claude-sonnet stays on 4.5 unchanged. Both
are priced in config/catalog.json at list price, so the metered startup
check passes and a request served by the OpenRouter leg bills the same
catalog price. A contract test ties tensorzero.toml, catalog.json and the
built-in list prices together.
relay-catalog gains a read-only cross-check against LiteLLM's MIT price
JSON (relay-price-crosscheck CLI): it flags differences above 5% and never
changes a price. First run flags the two llama alias routes, whose retail
price differs from the gpt-oss model that now serves them. The provider
canary route list now covers the two new routes (34 calls a day).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records OD-RY1's default: keep the TensorZero fork as the Relay engine,
maintain the four adapters in use, Bifrost as the Wave E provider layer,
LiteLLM price JSON read-only, and the three tripwires.
The canary calls every named chat route plain, streaming and with a
forced tool call, plus each fallback leg once, and passes a call only when
the route's first configured provider served it (raw usage provider_type).
A revoked Anthropic key is red even while OpenRouter keeps answering.
Output is canary format v1 under product railyard. routes.json is generated
from tensorzero.toml for boxes without tomllib; tests fail when stale.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- relay_key_budgets gains an optional daily_limit_micros (UTC day). The
spend-cap middleware answers 429 relay_spend_cap_exceeded with
error.period "day" or "month"; the monthly cap wins when both are hit.
- A groq::<model> (or any managed-provider) shorthand whose provider is the
first route of a same-id catalog model now runs on that catalog model when
a later route is enabled, so an exhausted Groq key fails over to the
OpenRouter floor instead of failing the caller. First attempt unchanged.
- Budgets UI: optional daily cap field and today's spend.
- Tests: unit tests for decide/validation/failover/429 body, plus a
live-Postgres test of the month and day windows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Groq retired llama-3.3-70b-versatile and llama-3.1-8b-instant. The chat and
passport_text defaults now run openai/gpt-oss-120b (Groq, OpenRouter failover),
with openai/gpt-oss-20b as the small model. The retired names stay as catalog
aliases that route to the gpt-oss replacements so existing consumers keep
working; the default retail catalog lists the new ids and Groq list prices.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELAY_RAGO_ROUTES_JSON maps a gateway API-key id to its own Rago org
bearer (inline or via api_key_env) and subscription, so Rally/AutoGTM and
OpenJev usage lands in separate Rago tenants. Single-org mode
(RELAY_COST_FEED_BEARER + map/prefix) is kept for unrouted keys; with
routes and no default bearer, unrouted keys fail delivery instead of being
billed to the wrong org. Bearers are redacted from Debug output.
autogtm.json and opentypesafe.json now define relay_llm_usage (sum_agg
over charged_micros): $0 mirror for AutoGTM, pass-through at cost for
OpenJev. Tests include an HTTP test where two keys land in two orgs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- apps/{vend,turnstile,abacus}/Dockerfile.dockerignore: per-Dockerfile ignore
files so repo-root builds upload only the workspaces they compile
- apps/relay/ui/Dockerfile.dockerignore: the gateway .dockerignore excludes ui/
and pnpm-lock.yaml, which the Relay UI image needs
- apps/vend/Dockerfile: copy apps/mint (vend-mint-client path-depends on
mint-core/mint-protocol); the builder stage failed without it
- apps/DEPLOY-SHARED-PLANE.md: rewritten to match infra-box
stacks/railyard/docker-compose.yml (docker compose profiles, host ports
3100-4000, one Postgres with Relay observability in Postgres, no ClickHouse,
abacus + relay-ui, env matrix, basic_auth/SSH access for the console)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Relay no longer aborts at startup when OPENAI_API_KEY (or any provider key)
is unset. Every provider credential in config/tensorzero.toml is now a
`dynamic::relay_*_api_key` slot (filled per request from the stored key or
the env var), and `[provider_types.*.defaults]` point shorthand models at the
same slots, so nothing reads `env::` at load time.
- Groq slot (GROQ_API_KEY) on the Providers page; `enabled` on each slot.
- Gateway refuses requests whose every route needs a disabled provider with
HTTP 503 `provider_not_configured` naming the env var (before provider I/O).
- A shorthand whose provider is disabled resolves to the catalog model of the
same id (Menivor sends `openai::llama-3.3-70b-versatile` for Groq models).
- Startup log lists enabled/disabled providers.
- Cost-first default: `functions.chat` and unpinned `passport_text` run on
Groq llama-3.3-70b-versatile (OpenRouter failover); OpenAI/Anthropic are
fallback variants. Catalog prices for the Groq models.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Relay turned Autopilot off (every /autopilot route renders the "not
available" page), so the five upstream specs in e2e_tests/autopilot/ are
skipped explicitly with that reason. New autopilot-unavailable.spec.ts
(runs in the default suite) asserts /autopilot, /autopilot/sessions,
/autopilot/sessions/new and a session URL answer 501 with the unavailable
heading, and that the home sidebar has no Autopilot links.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README rewritten with engine features, not-available list and Apache-2.0
attribution (forked from TensorZero 2026.6.0). UI status indicator, logger
prefix and warnings renamed to Relay (RELAY_UI_LOG_LEVEL with legacy alias).
Help links resolve via docs-url.ts to pinned engine docs (VITE_RELAY_DOCS_URL
override); fixed SFT link. /autopilot always shows the unavailable page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Relay UI: user-facing TensorZero strings -> Relay; bug-report links point to
the Relay operator; API Keys card description; tests updated to match
- Vend admin/console, Turnstile admin: load failures render as red role=alert
error state instead of muted empty state
- Rithub web: capitalized brand in title/header/footer/sign-in
- README: complete, current Apps table with console locations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README leads with the quickstart and examples; CHANGELOG covers
everything since the TensorZero 2026.6.0 fork point; manual checklist
for extracting apps/relay into its own public repo.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One-key stateless quickstart (OPENAI_API_KEY, optional OpenRouter
failover) plus examples for the OpenAI SDK/curl, fallback routing,
per-key budgets with Postgres metering, and the resale price catalog.
Configs validated with gateway --validate-and-exit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apache-2.0 section 4(d) requires redistributed images to carry the
license and the TensorZero attribution NOTICE.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BUILTIN_PRICES expanded to 111 models priced from OpenRouter's live list;
relay-catalog/openrouter.rs refreshes repriceable rows with integer money
math and rejects bad feeds; gateway re-applies operator overrides after
each refresh (RELAY_CATALOG_REFRESH_URL=openrouter).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Update README positioning, add NOTICE attribution for upstream
TensorZero, and a MIGRATING-FROM-TENSORZERO guide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- per-provider RetryConfig on ModelConfig (default 1 retry; 0=legacy immediate failover); all 4 dispatch loops
(infer_hedged/stream + both sequential) wrap the network call in retry_collecting_errors (exp backoff+jitter, is_retryable)
- parse_retry_after() (delay-seconds + HTTP-date) threaded through openai/anthropic/gemini(+13 sites) error handlers;
honored as the retry sleep via Error.retry_after (serde-skip field, no construction-site churn)
- health recording decoupled from hedge.enabled (HEALTH_RECORDING_ENABLED) so EWMA/circuit-breaker updates on sequential path
- [gateway.relay.slo] TOML -> SloConfig (was hardcoded with_defaults); installed before router build
- cargo check green (gateway, tensorzero-core, relay-hedge, tensorzero-error). NOTE: vendored #[cfg(test)] literals
need mechanical retries/None/slo bumps before cargo test compiles (lib/bin gate is green; deferred per no-tests rule)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>