Dispatch 5.2 has QY1.0 add the Purchases meter to the consumer contract
before QU1.4 merges; it was not added, and QU1.4 shipped against its own
fixture. The Scribase seed gains the metric (sum of tracked_usd, one event
per organization and month, $0 mirror charge) and the contract its meter and
sample event, in the shape QU1.4 sends (transaction id
scribase:scribase.purchases.tracked_revenue:<org>_<YYYYMM>, tracked_usd and
billable_usd). consumers.test.ts 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- packages/openfeature-railyard/src/targeting.mjs: one dependency-free
evaluator (sync SHA-1, rollout hash = parseInt(sha1("<flag>.<id>")[0:15])
/ 0xfffffffffffffff, inside when <= rollout/100; ordered rules, all
conditions of a rule must match, first match wins with its own value).
Property operators follow the reference matcher of posthog-node (MIT):
exact/is_not (lists, true/false by truthiness), icontains, regex, gt/gte/
lt/lte (numeric, else text), is_set/is_not_set. Segments are named sets of
property conditions per environment (Flagsmith segment shape, BSD-3);
cohorts are product analytics cohort ids. Byte copies with .d.mts types in
apps/console/lib/flags and apps/product-analytics/src/flags (drift test).
- Console: rules and segments live in Railyard's store for both backends
(migration 0009: railyard.flag_targeting, railyard.flag_segments, bounded
checks, cascade, RLS, no anon), so the table fallback and the Flagsmith
backend have the same rule features. setFlag validates rules and segment
references; a used segment cannot be removed; branches copy rules and
segments. The read endpoint takes ?id, ?props (JSON, 2 KB) and ?cohorts,
answers each flag for that person and ships {on, value, rules} plus the
segments used, so SDKs evaluate locally; without a person a targeted flag
reads off (old clients stay safe). Flags screen: rules per flag (everyone,
a property, a segment; cohorts only with RAILYARD_REPLAY_LIVE) with a
share, and segments. POST /api/flags/segments.
- Product analytics /flags: evaluates targeted flags with the person's
stored properties (request person_properties override) and cohort
membership (through person overrides).
- OpenFeature providers and the client: evaluation context targetingKey +
attributes (+ cohorts) resolve per person; cached starts keep rules.
- Contract fixture: flags items carry targeting (additive, version 2).
Tests
- openfeature 16/16: SHA-1 vs node crypto, rollout shares within bounds
over 10 000 ids and monotonic growth, operators, rules, validation, read
answer, client and both providers vs the evaluator, cached start, drift.
- console 142/142 incl. both backends with the same 20 rule sets, segments,
isolation, read-endpoint context, 0009 migration on a scratch PG, and
10 000 ids x 20 rule sets: provider local == read endpoint (0 mismatches).
- product analytics test/qy 10/10 incl. 10 000 ids x 20 rule sets: provider
local == /flags from stored people and cohorts (0 mismatches), and the
unmodified posthog-node local evaluation agreeing on all 18 non-cohort
sets for 10 000 ids (0 mismatches, 0 undecided); a3 experiments unchanged.
- contract 6/6; console and PA tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Product analytics (A26, contract 5.3)
- Bridge: new signed route product_analytics {scribase_org_id, app, days?,
with_server_key?} -> host, public key (the site key), first product event,
web view; the server key only when asked, only to the Scribase control plane.
- sites answers analytics_host and analytics_key next to the page-tag values
(nothing of the Insights path removed); insights answers
first_product_event_at; the analytics proof falls back to
first_product_event when no page-tag event came.
- lib/product-analytics.ts: one-app, viewer-scoped org tokens for every call;
PRODUCT_ANALYTICS_PUBLIC_URL (default the SDK default host).
- PA: POST /v1/server/{app_id}/batch with Authorization: Bearer ry_pak_<hex>
(HMAC of the app id under PRODUCT_ANALYTICS_CONSOLE_SECRET, constant-time
check) for server-side forwarders (QU1.4); the public key is refused there.
- Contract tests/contract/fixtures/scribase-bridge/contract.json stays
version 2 with additive QY1.2 keys: product_analytics route and answer
keys, analytics_host section (env names, capture paths, server door).
Web view (A18)
- PA src/web/query.ts: visitors, page views, visits, bounce, daily series,
top pages, entry referrers ($direct), entry UTM, p75 page speed with
ratings, from pa.events under RLS. Shapes follow PostHog web analytics
stats_table (MIT, 7b13402a6350, nothing from ee/), NOTICE updated.
- Console: product-analytics/web screen (range picker, tables, page speed).
/s.js page speed (I7, P-Y12)
- The page tag sends LCP, INP, CLS, FCP and TTFB once per page view
(hidden, pagehide, or before a route change) as a performance event;
data-vitals="off" turns it off. Port of insights-web metrics.ts; metric
definitions per GoogleChrome/web-vitals (Apache-2.0), NOTICE added.
1,620 bytes gzip (budget 3,072).
- With PRODUCT_ANALYTICS_URL the edge collector also forwards every stored
event to product analytics ($pageview, $web_vitals, custom events,
$identify) with cookieless daily ids, no IP, retried on 5xx with the same
uuids, so the web view reads the same store.
Also: lib/ship/ship.test.ts type errors from QY1.1 fixed (doneText helper).
Tests
- insights-edge 34/34 (19 existing + 11 vitals within 10% of
chrome-page-loads.json and 3 KB gzip + 4 forwarding).
- console 135/135; contract 6/6; console tsc clean.
- product-analytics a1 52/52; test/qy 7/7 (web view hand counts, isolation,
edge-shape events, server door, and an end-to-end bridge -> SDK event ->
first_product_event proof: 31 ms against the 60 s target); tsc clean.
Note: performance events still count toward the collector's monthly cap,
as the insights-web ones already did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch contract 5.4, Railyard side:
- apps/rago/seeds/portfolio/grants.json: the portfolio grants org, one count
meter per grant (launch reel, mail) under a $0 monthly plan whose package
charges hold the grant as free units (1 reel, 500 mails, from Scribase
plans.json), so Rago's current usage is the monthly balance.
- tests/contract/fixtures/grants/contract.json: the grant claims on the
partner token (grant, grant_period), the debit transaction id
<aud>:grant:<org>:<YYYY-MM>:<n>, the grants subscription id, sample debits
and the plain refusal with the upgrade path. Menivor PM1.5 and Rally PR3.1
test against it; the Scribase carve-out copies it byte for byte.
Tests: grants contract 3/3 (the allowances match Scribase plans.json on disk).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RYP-E4, dispatch 4.2 PY2.2 (Railyard side):
- lib/watch: checks (public https app addresses only; IPs, private names and
our own hosts refused), 20 per org, a status page slug each. The box 1
agent reads GET /api/v1/watch/agent/checks (ids and URLs only, bearer
WATCH_AGENT_TOKEN) and posts results to /api/v1/watch/agent/results.
Two failures in a row turn a check red; each change emails the owner once
through Rally Send (product railyard, from status@, idempotency key per
change; a failed send is retried on the next result). Older, unknown and
future results change nothing.
- /status/<slug>: live results only (state, share of the last checks, bars),
the check's name and never its address or any host or vendor name.
- The Watch screen: add by address, pause or resume, open the status page.
- Bridge route uptime (contract cases, uptime_check_keys): a check for the
given address, or the app's latest live deploy; the first result is the
slot's proof (check_result).
- Gated on RAILYARD_WATCH_LIVE (denylist rule railyard-slot-watch): off, no
check runs, the pages 404, the nav has no Watch item and the slot answers
arriving. The copy test lints each gated surface with the flag and proves it
checks the flag first.
- Migration 0006 (watch_checks, watch_status; https only, history capped at
90, cascades with the org).
Tests: watch 10/10, bridge 25/25, contract 3/3, migration 7/7 (0006 twice on a
scratch cluster), watch copy 7/7, console 108/108 with the bundle build,
tsc clean, SDK 7/7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RYP-E2 and SP-E6, dispatch 4.2 PY2.1 (Railyard side):
- lib/flags: flag environments per app environment (a Scribase environment
or branch), each with a public client key that reads that one environment.
Two backends, one surface: the unmodified Flagsmith server (one Flagsmith
organisation per Railyard org, a project per app, an environment per env;
FLAGS_API_URL + FLAGS_ADMIN_TOKEN) and, as the fallback the dispatch names
when the box 2 gate keeps Flagsmith down, the console's own tables
(migration 0005). An environment keeps the backend it was made on.
- A branch environment starts with its parent's flags (copy_from), then
changes alone.
- GET /api/v1/flags/client?key=: CORS-open, cached 15 s when keyed by URL;
the first read by an app is the slot's proof (first_flag_read).
- Bridge route flags (contract: id_format, three cases, flags_item_keys);
BRIDGE_SLOTS.flags landed.
- The Flags screen (nav item) flips with one click and adds a flag by key;
POST /api/flags writes only the signed-in org's environments.
- packages/openfeature-railyard: a zero-dependency polling client (30 s,
offline start from storage, back-off) and OpenFeature client and server
providers, with Expo and Next.js examples.
Tests: flags core 11/11 (both backends, a fake of the Flagsmith API, tenant
isolation, branch copies, a 502 that leaves nothing half made), bridge 19/19,
contract 3/3, migration 6/6 (0005 twice on a scratch cluster), console 85/85
with the bundle build, tsc clean, SDK 7/7 (a flip reaches the app within 60 s
in the worst cache timing on a fake clock; copy lint on docs and the screen).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contract scribase-bridge version 2:
- webhook-id is msg_<route>_<24 hex>; the id is inside the Standard Webhooks
signed content, so a signature made for one route is refused on another
(401, fixture wrong_route). ai and ai_usage cannot be confused.
- every orgs request carries addon.as_of (Scribase's epoch ms of the state).
Railyard stores it (migration 0004, addon_as_of) and applies a sync only
when no newer state is stored: one guarded PATCH through PostgREST. An older
sync answers 200 with stale: true and changes nothing.
- RAILYARD_BRIDGE_ACCEPT_LEGACY=1 (default off) accepts the P1 sender for the
minutes between the console and control-api deploys; it never lets an id
that names another route through.
Tests: bridge 15/15 (3 new), contract 3/3 with the new cases, postgrest-repo
and migration 11/11 (0004 applied twice on a scratch cluster, guarded update
proven in SQL), console suite 66/66, bundle 3/3, tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rago's create_event requires external_subscription_id; the contract now sends
<product>-portfolio-<external_customer_id> alongside the dispatch's
external_customer_id, and CONSUMERS.md says so. consumers 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Railyard side of PY1.5 (dispatch 5.3). Acceptance:
1. tests/contract/consumers/contract.json is the contract PM1.5, PR1.5 and
the Scribase carve-out test against: env names (RELAY_URL, RELAY_KEY,
RAGO_URL, RAGO_API_KEY, MINT_URL, MINT_API_KEY, RAILYARD_LIVE), the
RAILYARD_LIVE switch (default 0), every product's meters and one sample
event per meter with the <product>:<meter>:<source id> idempotency key.
2. apps/rago/seeds/portfolio/{scribase,menivor,rally}-portfolio.json define
exactly those meters (valid Rago aggregations, field names where summed)
under $0 mirror plans; consumers.test.ts checks seeds against the contract.
4. tools/reconcile-portfolio/reconcile.mjs compares each product's own counts
with Rago's totals per customer, meter and month; on the fixtures the
difference is 0, and dropped, extra or malformed rows are named (exit 1/2).
5. Nothing switches live in code: docs/CONSUMERS.md gains the Wave P switch
table. scripts/relay/provision-product-keys.mjs prints names and the box
steps only (no value is generated, read or printed).
3 (Mint stack, 128 MiB, /metrics scraped): infra-box stacks/mint; Mint's
/metrics handler exists since RY-MT1.
Not in this commit: Mint outbound event webhooks and the paid-event mirror
(see the lane report).
Tests: consumers 3/3, reconcile 2/2, provision 1/1.
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>
One project's first event, visitors, events, month's stored events against the
add-on's cap, the funnel, and the same cap message the collector follows.
Contract case added. Tests: bridge 11/11, contract 3/3, tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Railyard side of PY1.3 (RYP-D2, RYP-E1, SC-E3). Acceptance:
1. apps/insights: umami-software/umami v3.4.0 (MIT, commit ec0ff503),
vendored --depth 1, LICENSE kept, NOTICE added. Fork additions only:
src/railyard/{ingest,summary,tenancy,api-only}.ts, /v1/ingest/batch (the
edge collector contract v1, bearer INSIGHTS_INGEST_TOKEN, no IP ever,
retried batches de-duplicated by migration 90_railyard_ingest_receipts),
/api/v1/tenants/{org}/summary (bearer INSIGHTS_API_TOKEN), src/proxy.ts
(INSIGHTS_API_ONLY=1 serves only the Railyard API and the heartbeat).
Tenant isolation is tested at the API level (an app id owned by another org
is refused) and at the SQL level (upstream migrations 01-26 plus 90 on a
throwaway cluster: org B never reads org A's rows, even naming its app).
Upstream vitest suite: not run on the Mac (pnpm 12.3.4 pinned upstream,
disk floor); it runs in the image build on box 2 or CI.
2. No upstream product name in anything a customer loads: the page tag, the
console pages and the fork's additions (tests); the upstream dashboard is
never served in API-only mode.
3. The console writes the collector's site entry on "Add app", on
auto-created apps from deploys, and rewrites every entry on add-on, plan or
pause changes (lib/sites.ts, SITES KV binding). The bridge gains
`sites` (the project's app, site key, page tag and collector URLs, entry
written) and the analytics proof is the first event from Insights. The
console's Insights page shows visitors, events, first event and the
visit -> signup -> first action funnel.
5. insights-edge/src/caps.ts: at 100% of the cap events are still counted and
not stored until the next UTC month; the console shows the same message
from a byte-identical copy (lib/caps.ts, tested).
4 (384 MB at 50 events a second for 10 min) is measured on staging before deploy.
Env: INSIGHTS_API_URL, INSIGHTS_API_TOKEN, SITES KV binding (console);
INSIGHTS_INGEST_TOKEN, INSIGHTS_API_TOKEN, INSIGHTS_API_ONLY (Insights).
Tests: console 54/54 (tsc clean), insights fork 7/7 (incl. SQL isolation),
insights-edge caps + collector + sim 14/14, tests/contract 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Railyard side of PY1.2 (SC-E2, SP-F2). Acceptance:
1. packages/cli/src/scribase/env.mjs: in a Scribase project folder,
`railyard deploy` reads the public URL and anon key `scribase init` wrote
(.env, .env.local; NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_/PUBLIC_ variants) into
the build env and onto the Worker (--var), prints their names only, and
leaves secrets out by name (service role key, SECRET/PASSWORD names, a
service-role JWT under any name). `railyard link-scribase` reads a one-time
claim from stdin (no flag takes it), exchanges it once and saves the token
0600; nothing is printed.
2. A git branch with Scribase branch settings (.scribase/branches/<branch>.env,
written by the PS2.0 hook) deploys its <app>-<branch> preview against that
branch (fixture test).
3. Bridge: deploy slot landed; proof is the latest successful deploy; new
route POST /api/v1/bridge/scribase/deploys lists the bound org's deploys for
the Scribase Deploy tab (org isolation test). Contract cases added.
4. Real Cloudflare end-to-end stays owner-run (tests use the fake wrangler).
Tests: packages/cli 13/13, console bridge + deploys 15/15, tests/contract 3/3,
tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PY1.0 acceptance (C8 delta check on main f919636; Wave E Y-0 to Y-5 merged):
1. Denylist .3 (gtm/policy, published by this package) adds portfolio-ott-drm
and portfolio-ott-comparison (DRM, Netflix-style, your own Netflix beyond
Menivor), addon-unlaunched (ADDON_LIVE), rally-capacity-purchase
(RALLY_CAPACITY_PURCHASE_LIVE) and at-cost (allowed only next to a live
price source). Re-vendored byte for byte; every new rule has failing
fixtures (policy/test/fixtures/denylist-3-new-phrases.json); .2 fixtures kept.
2. apps/console/app/api/v1/bridge/scribase/{orgs,claims,proof}: signed
(Standard Webhooks, RAILYARD_SCRIBASE_BRIDGE_SECRET), replay-proof calls from
Scribase control-api. The first call creates the Railyard org bound to the
Scribase org id (deterministic owner id, no second sign-up) and mirrors the
add-on into the entitlement (plan "addon"); a lapsed add-on pauses the org
and keeps its data. Keys go only to the Scribase CLI: a claim is a one-time,
pre-approved device code (120 s) exchanged at /api/v1/device/token; a grep
test keeps every bridge handler free of stdout, stderr and log writes.
3. proof answers {slot, state, live, proof:{kind,id,at}, next}; slots whose
package has not landed answer "arriving".
Contract: tests/contract/fixtures/scribase-bridge/contract.json, run by
tests/contract/scribase-bridge.test.ts; the Scribase carve-out tests the same file.
Migration: apps/console/db/migrations/0002_scribase_bridge.sql (idempotent;
applied twice to a scratch local cluster only by test/migration.test.ts).
Env: RAILYARD_SCRIBASE_BRIDGE_SECRET (secret; unset keeps the bridge off).
Tests: console npm test 48/48, tests/contract 2/2, policy 11/11, cli 9/9, mcp 9/9,
tsc --noEmit clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>