Skip to content

Development secrets that survive a restart - #16

Merged
fgatti675 merged 21 commits into
mainfrom
feat/stable-dev-secrets
Aug 22, 2026
Merged

fgatti675 merged 21 commits into
mainfrom
feat/stable-dev-secrets

Conversation

@fgatti675

Copy link
Copy Markdown
Member

Part of #4 — "first run works", extended to "second run doesn't undo it".

loadEnv generates JWT_SECRET and REBASE_SERVICE_KEY when unset outside
production, so you can start without setting anything up. It generated them
freshly on every boot — so restarting the dev server invalidated the previous
run's tokens. You were logged out of your own app for editing a file, and an API
key you had just created stopped working.

The CLI already worked around this for scaffolded projects by writing a stable
JWT_SECRET into .env at rebase init; its comment says exactly why. That left
everyone who didn't scaffold — and anyone running from a container with no
.env — with logout-on-restart.

Generated values are now cached in .rebase-dev-secrets.json, beside
.rebase-dev-port and .rebase-dev-url, gitignored with them, mode 0600.

The two properties that matter more than the convenience

Production is untouched. A boot that had to generate either secret still
fails under NODE_ENV=production, naming the variable. Nothing here can make a
cached value reach production — nothing is even written there.

It fails soft. A read-only filesystem, an unwritable working directory, a
malformed cache: each falls back to the previous behaviour — an ephemeral
secret — and says so once at debug level. A convenience cache is never a reason a
dev server won't start.

The trap, recorded because it nearly shipped

The first version decided whether to cache by reading process.env at call
time. env.test.ts does process.env = {} in its beforeEach, which erases
NODE_ENV and JEST_WORKER_ID alike — so the predicate saw a bare object,
concluded "development", and wrote a secrets file into packages/server on
every jest run
. A library call writing into a test suite's working directory.

Whether a test runner is hosting the process is a fact about the process, not
about what a test has since done to its environment, so it's captured once at
import. There's a test asserting the full suite leaves no file behind, and I
verified it by running the whole suite and checking.

Verification

  • 25 new tests: round-trip, file mode (including tightening a pre-existing 0644
    file), malformed/wrong-shaped/non-string cache contents, directory creation,
    the unwritable-path fallback, and every branch of the caching predicate
  • packages/server: 146 suites, 2153 passing
  • pnpm typecheck and verify:docs clean
  • Confirmed by hand that a full suite run leaves no .rebase-dev-secrets.json

Not verified: an actual rebase dev restart cycle preserving a login. The
mechanism is asserted at the unit level.


Cut from local main, 17 commits ahead of origin/main; those appear in the
diff until main is pushed.

fgatti675 and others added 18 commits August 20, 2026 23:41
`rebase cloud resources` printed a Plan line reading "legacy (no plan)" against
a column that no longer exists, and `rebase cloud billing` built a
`compute_<provider>_<vmSize>` lookup key — a price for a machine on a list this
platform does not buy from, dead since `vmSize` was removed on 2026-08-20 and
printing a bare label ever since.

Both now ask the control plane what the project's dials cost
(`POST /api/functions/pricing/quote`) and print the itemised answer. Best-effort:
an older control plane has no such endpoint, and a resources listing that failed
because a price could not be fetched would be worse than one without it.

Four dials the plans used to decide are flags now — `--replicas`, `--spot`,
`--scale-to-zero`, `--storage` — and `projects create` takes the same set, so a
project can be created at the size it needs rather than resized afterwards. It
also stops sending `vm_size`, which the control plane dropped.

`--spot false` is parsed to the boolean `false`, not the string. The string is
truthy, and would have put a project that asked for on-demand capacity onto
preemptible nodes at a third of the price with the restarts it declined.

Co-Authored-By: Claude Opus 5 <[email protected]>
`import { defineFunction } from "@rebasepro/server"` reaches the whole
framework — boot, the collection loader, the backup routes, the SPA server,
`@hono/node-server`, `ws`, `jsonwebtoken`, Drizzle. On Node that costs start-up
time and nothing else. It also means a function file can only ever resolve
inside a Node process, however portable the function's own code is, and that
import line is in every function file, template and doc page — so it is not a
thing that can be changed later without breaking everyone who wrote one.

The new entry point carries the authoring surface and nothing else. Its
published bundle imports exactly two things, `hono` and `hono/adapter`, and two
gates keep it that way: a test walks the import graph from source and names the
chain that broke the rule, and the build evaluates the emitted file in a `vm`
context holding web globals and no `process`, `Buffer` or `require` at all.
Both are mutation-tested. Importing from the package root still works and
behaves identically.

Also in the authoring surface, because each was a gap the same move exposed:

- Typed context accessors. `getUser(c)` returns `{ uid, roles, …claims }` with
  `roles` always an array, replacing the `c.get("user") as { uid: string;
  roles?: string[] } | undefined` cast that every example opened with — an
  assertion in a security-relevant position, and wrong for at least one auth
  path that reaches it. Plus `requireDriver`, `requireRole`, and guards that
  read the resolved identity rather than parsing a token (equivalent inside a
  function, where the middleware has already run; fail-closed outside one).

- `waitUntil(c, promise)`. A floating promise at SIGTERM is dropped mid-flight,
  so a rolling deploy could always lose a webhook the request had already
  answered 200 for; shutdown now drains tracked work, bounded, and reports what
  it could not wait for.

- Configuration read from the request: `getEnv`/`env`/`requireEnv`/
  `lazyResource`. `new Stripe(process.env.KEY!)` at module scope is a live
  defect today — it throws while the file is being imported, and the loader
  reports that as a *skipped function*, so the route 404s with the reason in a
  boot log. `rebase build` and `rebase doctor` now report those reads.

- `rebase build` records per-function portability in the bundle manifest, so a
  host can tell what is in a bundle without booting it.

`packages/server/functions/package.json` is a resolution redirect, not a
package: TypeScript's `moduleResolution: "node"` — which the scaffolded backend
uses — ignores `exports`, and without it the template's own import fails `tsc`
while running fine. `assert-build-output.mjs` verifies redirect targets for the
same reason it verifies entry points: a broken one is silent.

Docs rewritten in all six locales, with the anchors fixed (the machine
translations had kept the English ones), and the scaffolded template and the
three agent skills moved onto the new import. The API-surface gate now tracks
both entry points.

Co-Authored-By: Claude Opus 5 <[email protected]>
`tsc` writes relative specifiers into `.d.ts` exactly as the source wrote them
— extensionless, because the source is compiled by a bundler. Every package
here is `"type": "module"`, and under `moduleResolution: "nodenext"` an
extensionless relative specifier inside an ESM declaration file is an error.
TypeScript's response is the part that matters: it does not fail at the
consumer's import. It resolves the package, discards every declaration it could
not follow, and types the whole import `any`.

So there was no diagnostic anywhere near the cause. The first thing a consumer
saw was an implicit-any error in *their own file*, pointing at their code, in a
project that had done nothing wrong. Measured on `@rebasepro/server`: `bundler`
resolution sees 170 value exports, `nodenext` sees zero. It has been that way
for the whole life of the packages.

Fixed by appending the extension the declarations always needed — `./init` →
`./init.js`, and `./auth` → `./auth/index.js` where the target is a directory,
resolved against the filesystem rather than guessed, because a dangling
specifier degrades to `any` again. Not a trade: TypeScript maps `./x.js` onto
`./x.d.ts` under node10, bundler and nodenext alike, so nothing that worked
before stops working. 547 specifiers across the five packages that were built
to verify it; the step runs in all 21 published builds.

The rewriter refuses a `dist` whose realpath is outside its package. That is
what a git worktree's symlinked node_modules looks like, and without the guard
a build run there silently rewrites the primary checkout's published output.

`pnpm check:dts` is the gate, in verify.yml after the build. Nothing in this
repository could have caught the original defect, which is the more interesting
half: `pnpm typecheck`, the docs verifier and the template checks all map
`@rebasepro/*` onto source, and the API-surface gate reads a single `.d.ts` in
isolation. Every gate looked at something other than the artifact a stranger
installs. So this one installs each built package into a throwaway directory by
symlink, imports it, and compares the value exports the type checker can see in
each resolution mode — a question that needs no knowledge of any package's API,
and so keeps working as they change. It detects a single reverted specifier
(167 exports where 170 are expected) and names the file and line that caused it.

node10 is expected for package roots always, and for a subpath only where the
package ships a redirect directory — with `@rebasepro/server/functions` named
explicitly, since the backend `rebase init` scaffolds compiles with
`moduleResolution: "node"` and deleting that redirect would otherwise reduce
coverage silently rather than fail.

Co-Authored-By: Claude Opus 5 <[email protected]>
Building the fourteen packages this worktree had never built turned the gate
green across all 21 — and then a mutation test on `@rebasepro/admin` walked
straight past it. Reverting one specifier in its `dist/index.d.ts`, exactly the
defect the gate exists for, was not caught.

The discriminator was value exports: functions, consts, classes. That is the
right signal for a package whose surface is mostly values, and blind for one
whose surface is mostly types. `admin`'s broken re-export was `./types/index`,
which carries no values at all, so nothing it exported could go missing from a
count of values. `@rebasepro/types` — the package most consumers feel first —
was blind for the same reason along its whole surface.

Three changes:

- Read the diagnostics off the package's own declarations directly, rather than
  inferring damage from the export surface afterwards. TS2834/2835 is the exact
  nodenext rule being broken; it needs no inference and no export to be lost.
  This meant turning `skipLibCheck` off, because it suppresses precisely the
  errors under test.
- Compare *all* exports across resolution modes, not only the value ones.
- Stage every workspace package into the throwaway consumer, not just the one
  under test, so its layout matches an installed tree.

Turning declaration checking on surfaced a false positive immediately: a
sibling `@rebasepro/*` import inside a dependency's own `.d.ts` reported
TS2307 under node10. That is the probe's fault, not the package's — symlinking
means TypeScript resolves from the real repository path, so an upward lookup
never reaches the staged node_modules, while a real install has the whole
closure flat and resolves it without trouble. TS2307 now counts only for a
*relative* specifier, which is an emission defect; for a bare one it is a
question the staging cannot honestly answer.

Verified by mutation on three shapes it previously could not distinguish: a
value-heavy package (server), a pure-type package (types), and the type-only
re-export that started this (admin). Plus the node10 redirect deletion. All 21
packages now build and pass; the full run takes ~75s.

Co-Authored-By: Claude Opus 5 <[email protected]>
…osed

Both scripts were verified by running them and reading the output, which checks
that they work on today's input and nothing about the cases they were written
to handle. The gate had already stopped gating once within hours of being
written, so that is not a hypothetical standard.

Writing the fixtures found two more defects in the gate, neither visible by
inspection and both of which made it inert rather than wrong:

- The diagnostic filter was scoped to `/packages/` — the repository's own
  directory shape — so it silently exempted any package outside that path.
  Every fixture is outside it, which is why the first run of the new suite had
  four failures against a gate that passes the real packages. Scoped to the
  package under test now, which also makes the earlier cross-package false
  positive (a sibling's diagnostics reported under `@rebasepro/admin`)
  impossible by construction rather than by filtering.
- The prefix comparison used the literal path. TypeScript reports resolved
  paths, and on macOS `/var/folders/…` is a symlink to `/private/var/…`, so the
  comparison matched nothing for anything under the temp directory. Real
  arguments happened to match; fixtures never could.

The suites encode the shapes each script must tell apart. For the rewrite: a
directory specifier becoming `<dir>/index.js` rather than `<dir>.js` (guessing
dangles the re-export and restores the `any`), a string-literal type and an
ambient `declare module` name left alone (claims that lived in a comment and
nowhere else), idempotency, the symlinked-dist refusal, and a dangling
specifier failing loudly. For the gate: healthy, values-broken, types-broken,
a package with no values at all, subpaths with and without a node10 redirect,
and a `.css` export that is not a module.

Mutation-tested both suites. A naive `+ ".js"` breaks the directory test; a
regex-instead-of-AST collector breaks exactly the two tests guarding syntactic
position — and getting that mutation to be live took two attempts, because the
first one was mis-escaped and passed vacuously.

Wired into `test:gates`, which verify.yml already runs.

Co-Authored-By: Claude Opus 5 <[email protected]>
Portable @rebasepro/server/functions entry point, plus the .d.ts
resolution gates that keep it honest.
CLI prices resources by dial, with no plan left to name.
`frameworkVersion` meant the framework the runtime IMAGE ships in
`cloud status`, and the framework a BUNDLE installed in `cloud
deployments`. The image supplies the server and the bundle supplies the
driver, so the two are routinely different — printed under one name they
read as the control plane disagreeing with itself about a single number,
which is how it was reported. Now `imageFrameworkVersion` and
`builtAgainst`, spelled out where they print so neither can be misread.

Co-Authored-By: Claude Opus 5 <[email protected]>
…nning a version

The security table still named 0.10.x long after 0.10 stopped being the
latest minor, so it documented the opposite of the policy it meant. The
rule now sits above the table and the table only illustrates it.

Co-Authored-By: Claude Opus 5 <[email protected]>
…nto the site

copy_changelog.js only ever moved one file; copy_repo_docs.js mirrors any
repo-root document, copying rather than moving so existing references keep
resolving. check:generated gates the copies so they cannot drift.

Co-Authored-By: Claude Opus 5 <[email protected]>
The dropdown panels were tall enough to cover the hero: 558px for Product,
410px for Developers at 1440x900. Two of that height came from shape, not
content — a two-column grid capped at max-w-3xl, plus a full-width footer
row below it holding the overview/docs links.

Fold that footer into a third headed column (Explore, Resources), let the
grid span the panel's inner width, and tighten the row rhythm. Wider columns
also stop most descriptions wrapping to a second line, which pays again in
height: Product is 380px now, Developers 298px.

Mobile flattens columns into one list, so those links still appear there.

Co-Authored-By: Claude Opus 5 <[email protected]>
Ports the wall from the FireCMS site into this file's own structure:
INTRINSIC sizing, the shared class constants and the `product` field all
stay, and the new entries feed into them rather than around them.

Every new entry is tagged `product: "firecms"`. Unlike the existing
seventeen this is not a guess: each is a FireCMS Cloud customer verified
from signup and project activity, which is the evidence the `product`
comment asks for. The tally moves from 1 known / 17 unknown to 1 rebase /
26 firecms / 16 unknown, so the caption still needs its qualifier.

INTRINSIC values were read back with `new Image()` as the comment
instructs, and that mattered: a viewBox-only SVG reports a 300px natural
width, not its viewBox width, so seven entries would have carried numbers
2-6x too large had they been parsed from markup.

Also: eight marks were too dark once grayscale and opacity-60 composited
over the near-black ground (Team Global Express measured 21 against 153
for white ink); they were dark-coloured marks wrongly flagged
`invert: false`. MedicalMotion moves to the white asset already here.
withu.png was 84% transparent padding and overflowed its cell. Adds a
"companies" type, an optional textClass, matching brightness for text
fallbacks, and two-up logos on mobile.

Co-Authored-By: Claude Opus 5 <[email protected]>
Three-column mega-nav and the 26-logo client wall.

Co-Authored-By: Claude Opus 5 <[email protected]>
The checked-in files predate three generator changes: the users read
policy compares `id = rebase.uid()::uuid` rather than casting the column
to text, `orders` gained its `order` column, and the search block now
emits the immutability guard that refuses to re-apply when a generated
column's expression changed underneath it.

Regenerating twice produces identical output.

Co-Authored-By: Claude Opus 5 <[email protected]>
…write

The skills had drifted from the API they describe: `@rebasepro/ui` was
said to export `AddIcon`/`DeleteIcon`, which do not exist — it re-exports
lucide-react under its own names (`PlusIcon`, `Trash2Icon`); the studio
skill named `sideEntityController` rather than `sidePanelController`; and
the project-structure tree omitted `backend/functions/`. An agent
following any of these writes code that does not compile.

Co-Authored-By: Claude Opus 5 <[email protected]>
`loadEnv` generates `JWT_SECRET` and `REBASE_SERVICE_KEY` when they are unset
outside production, so a developer can start without setting anything up. It
generated them freshly on every boot, so every restart of the dev server
invalidated the previous run's tokens: you were logged out of your own app for
editing a file, and an API key you had just made stopped working.

The CLI already worked around it for scaffolded projects by writing a stable
`JWT_SECRET` into `.env` at `rebase init` — its comment says exactly why. That
left everyone who did not scaffold, and anyone running from a container with no
`.env`, with logout-on-restart.

The generated values are now cached in `.rebase-dev-secrets.json`, beside
`.rebase-dev-port` and `.rebase-dev-url` and gitignored with them, mode 0600.

Production is untouched. A boot that had to generate either secret still fails
with `NODE_ENV=production`, and nothing here can make a cached value reach it.

It fails soft. A read-only filesystem, an unwritable working directory or a
malformed cache all fall back to the previous behaviour — an ephemeral secret —
and say so once at debug level. A convenience cache is never a reason a
development server will not start.

One trap worth recording. The first version decided whether to cache by reading
`process.env` at call time, and `env.test.ts` does `process.env = {}` in its
`beforeEach` — erasing `NODE_ENV` and `JEST_WORKER_ID` alike, so the predicate
saw a bare object, concluded "development", and wrote a secrets file into
`packages/server` on every jest run. Whether a test runner is hosting the process
is a fact about the process, not about what a test has since done to its
environment, so it is captured once at import. A test asserts the full suite
leaves no file behind.
@fgatti675 fgatti675 mentioned this pull request Aug 22, 2026
2 of 5 tasks
…r the build

Every pull request has been failing since the portable functions entry point
landed:

    FAIL baas
      backend/functions/hello.ts(7,8): error TS2307:
      Cannot find module '@rebasepro/server/functions'

`check:templates` and `check:eject` compile a *scaffolded project*, which
resolves `@rebasepro/*` through node_modules and its `exports` map. `./functions`
points at `dist/functions/index.d.ts`, so before `pnpm run build` it resolves to
nothing and the baas preset — whose `hello.ts` now imports it — fails to compile.
Both checks ran before the build step.

Nothing caught it locally because a developer's checkout has a `dist` lying
around from the last build; CI installs and has none. Reproduced by deleting
`packages/server/dist/functions` and running the check, which fails identically.

Moved both after `Build packages`, where `check:api-surface` already sits for
exactly this reason — its comment says "Reads dist/index.d.ts, hence after the
build". The cost is that a broken template is reported a few minutes later; the
alternative is a gate that cannot pass on a clean checkout.

Verified the rest of the lane separately: core-types, types-headless, baas-types,
test-scripts, control-chars, untranslated, hooks, unused, api-surface, dts,
deps, headless, names, derived-names and verify:docs all pass on this commit, so
this is the only thing standing between main and a green run.
`check:generated` runs the website generators and fails on any diff, so a docs
change that does not carry its regenerated artifact fails CI. Mechanical.
@fgatti675
fgatti675 merged commit 22515e7 into main Aug 22, 2026
2 checks passed
@fgatti675
fgatti675 deleted the feat/stable-dev-secrets branch August 22, 2026 10:41
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.

1 participant