railyard-console was deployed live on 2026-10-14 (railyard.ereboslab.com
returns 200) but sign-in has been silently broken since: SCRIBASE_URL is
set to https://api.scribase.com, the shared control-plane/management API,
not a project's own gateway host, so POST /auth/v1/otp there 404s. Verified
directly against the box's Scribase DB that no project exists for the
console at all yet (zero rows for organization_id='ereboslab').
Add a config-read guard + test so this exact misconfiguration fails loudly
on the next deploy instead of shipping a console that renders but can
never sign anyone in, and correct DEPLOY.md/README.md's stale "never
deployed" / "no action needed" claims to match verified reality, with the
missing owner step spelled out (replace SCRIBASE_URL with the real
project's api_url once provisioned).
Not deployed: redeploying the guard alone, before a real SCRIBASE_URL
exists, would turn today's "page loads, sign-in silently fails" into a
500 on every request, which is worse. Provisioning the real project is
confirmed owner-gated (needs a working SCRIBASE_ACCESS_TOKEN for the
ereboslab org; none found on this machine), matching migration 0001's own
header, not an oversight.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
readConfig() already threw when DODO_API_BASE is the live host and
RAILYARD_DODO_LIVE is unset, but the only covered case was "absent".
Add the case that actually matters before a real deploy: any value
other than the exact string "1" ("true", "yes", "on", "01", padded
whitespace, empty) must still refuse the live host. Pure test addition,
no payment flow or secret touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readConfig required all Dodo values, so the console could not start before
the railyard Dodo brand and products exist (owner item Y-2), although
Railyard is sold inside the Scribase add-on (bridge orgs need no checkout).
Dodo values are now optional: billingReady is true only when the key, the
webhook secret and the three product ids are all set. Without them checkout,
pause and cancel redirect with 'card payments open soon', the webhook answers
503, and everything else runs. Scribase project and session secret stay
required. 4 new tests; console 158/158, tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The console could only sign in with Google or GitHub, so it could not open
before both OAuth apps exist (owner item Y-2). Add email sign-in: Scribase
Auth mails a one-time code (POST /otp), the console redeems it (POST /verify),
reads the user from the auth server, checks it matches the address, and opens
the same session as the OAuth path. Same-origin checks on both posts; inputs
validated before any call. RAILYARD_OAUTH_PROVIDERS picks the OAuth buttons
(default google,github; empty = email only). 7 new tests, console 154/154,
tsc clean.
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>
RYP-E3 in Wave P. ADR RY-0004 records the evidence that path A exists
(Cloudflare self-managed OAuth clients, changelog 2026-06-03, authorization
code flow only) and builds it; path B stays the written fallback; path C
stays rejected.
- railyard link: one URL; at most two consents in the browser (install the
Railyard GitHub App on the repo, then Cloudflare's own consent screen with
PKCE), each skipped when done before; then one pull request from the App on
railyard/ship-on-push adding .github/workflows/railyard.yml. Nothing is
pushed to a default branch. The installation id GitHub sends back is not
trusted; the App's view of the repo decides.
- The workflow holds no key: it asks GitHub for an OIDC token (audience = the
console) and runs `railyard ci`. The console checks issuer, audience,
expiry and signature, the stable repository_id, the Railyard workflow ref
only, push/workflow_dispatch on branches only, and a paused org; it answers
with a short-lived Cloudflare access token (sealed refresh token rotated and
resealed; a cached access token reused while 10 min are left).
- railyard ci masks the token first, deploys exactly like railyard deploy,
never opens a login, and reports with a fresh OIDC token. The console
records the deploy (branch and commit from the token) and writes one
preview comment on the branch's pull request, edited on later pushes.
- Signed App webhooks drop links on uninstall or repo removal.
- GET /api/v1/github/manifest creates the App (owner item Y4); the done page
shows one command that pipes the App key into wrangler secrets.
- Migration 0007_ship.sql (idempotent; scratch Postgres only): installations,
links (one per repo), sealed Cloudflare grants, link sessions; RLS on, no
anon/authenticated grants.
- Off until RAILYARD_SHIP_ON_PUSH_LIVE=1 and every name is set (routes 503;
copy stays "arriving" under denylist rule railyard-slot-ship-on-push).
Env: RAILYARD_SHIP_ON_PUSH_LIVE, GITHUB_APP_ID, GITHUB_APP_SLUG,
GITHUB_APP_PRIVATE_KEY, GITHUB_APP_WEBHOOK_SECRET, CLOUDFLARE_OAUTH_CLIENT_ID,
CLOUDFLARE_OAUTH_CLIENT_SECRET, CLOUDFLARE_OAUTH_SCOPES (optional); reuses
RAILYARD_CREDENTIALS_KEY.
Tests: console 122/122 (ship 12, migration 0007 on a scratch cluster), tsc
clean; CLI 18/18 (link and ci 5, copy lint). The 5-minute push-to-live run on
a real repo and Cloudflare account is owner-run.
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>
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>
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>
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>
Wave E verifier (Y-2/Y-3):
- A card check started a fresh 14-day trial every time: cancel or refund,
pay $1 again (credited back) and get another trial, for $0 net. The
trial now starts only when trial_ends_at is unset; refunds keep it set
and a paid plan marks it used. access() sends a card-on-file org that
used its trial to the plan, and the Billing screen says so.
- startCheckout opened a second plan checkout for an already subscribed
(or cancelling) org, which bills twice; and a second card check for an
org with a card on file. Both are refused (BillingError, ?error=already).
- A refund of an older card-check payment kept its dollar credit, and a
second refund event for the same payment could take it back twice. The
debit now always applies once per payment, tracked in billing_events.
- subscription.* events of a subscription that is not the org's current
one (an old one expiring) no longer end or pause the current plan.
- Deploy records normalise the app name the CLI sends (folder 'My Shop'
-> my-shop) so the second deploy is not a 409; rollback_of must be a
uuid (was a database error).
Tests: 7 new (fail before, pass after); console 37/37, tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Next.js console for Cloudflare Workers (OpenNext config, wrangler.jsonc)
with data in the console's own Scribase project, schema railyard
(migration 0001: orgs, org_members, apps, deploys, entitlements,
billing_events, api_tokens, device_codes; idempotent, RLS on, no anon
grants).
- Sign-in with Google or GitHub through Scribase Auth (PKCE), user read
from the auth server, org and entitlements row created, signed
HttpOnly session.
- Money ladder (pure, immutable): $1 card check credited back to the
customer wallet, 14-day trial with the plan's limits, $19 a month or
$190 a year, pause switch and one-click cancel (ends at the next
billing date; a trial ends now).
- Webhook: Standard Webhooks signature and timestamp verified, replays
ignored by unique message id, signed checkout metadata, other brands
ignored, a refund of the card check reverses the credit and the
trial, a failed wallet call releases the id for the provider's retry.
- Apps, Usage and Billing screens, one primary action each; Add app
shows the deploy command and the Insights tag in two clicks.
- CLI device-flow login and org-scoped hashed tokens for Y-3.
- Test mode only: the live payment host is refused unless the owner
sets RAILYARD_DODO_LIVE=1.
Tests (node --test, 25): journey from sign-in to entitlements and the
snippet, refund, pause and cancel, webhook security, ladder, tokens and
org isolation, PostgREST repo, a component test of Add app with the copy
lint, a next build grep for sentinel secrets in the client bundle, and
the migration applied twice on a scratch Postgres.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>