Skip to content

feat(console): one build serves every product and environment, fetched not built - #120

Merged
ruehowl merged 1 commit into
mainfrom
claude/tender-bell-gunxyb
Oct 25, 2026
Merged

ruehowl merged 1 commit into
mainfrom
claude/tender-bell-gunxyb

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Table 1.3, the last item of the bootstrap speed-up — and the one that needed real work in the console rather than a script.

Why it couldn't be done before

The console baked its environment into the bundle: environmentBuildVar: NEXT_PUBLIC_DEPLOY_ENV was compiled in, and DEPLOY_ENV functionally locked the API target, so a stage build deployed to prod would have pointed at the stage API. One build could not serve both environments — and an artifact that can't be redeployed anywhere isn't an artifact.

CA1 — identity at runtime

src/lib/app-config.ts keeps its constants as the compiled-in fallback, so PRODUCT_NAME = "Lumen" and STORAGE_PREFIX = "lumen.next" remain the literal seams rebrand.mjs matches — the rebrand needed no new rule. On top sits a resolved AppConfig: each field overridable per request by the Worker's vars, which OpenNext copies into process.env.

The root layout resolves it on the server (generateMetadata + async RootLayout) and hands it to the client via <Providers config>. wrangler.jsonc now carries the five CONSOLE_* vars, which the rebrand rewrites — so a product's console says the product's name even though the bundle was built from the baseline's sources. That's load-bearing: a prebuilt artifact carries the baseline's defaults, and vars are the only place a product's identity reaches it.

CA2 — environment at runtime

Read from the -<env> the workers.dev host carries, or CONSOLE_DEPLOY_ENV where a custom domain names none. environmentBuildVar is gone. api.ts's TARGETS / DEPLOY_ENV / IS_LOCKED were module constants evaluated once at import; they're now apiTargets() / deployEnv() / isLocked().

CA4 — the artifact

06-console's console-artifact hook pins the baseline's published artifact (URL, sha256, the product's own source hash). The component's buildCommand verifies the digest and unpacks it instead of a cold Next.js build.

Everything degrades to a normal build: no artifact, a changed console, an unreachable URL. Only a digest mismatch is fatal — that means something served bytes other than those published. The rebrand leaves the pin alone (it names the baseline's release — provenance; a rename would point the product at a release that doesn't exist). .github/workflows/tag.yml publishes one as part of cutting a baseline-vN tag, and is ignored from products, which carry only ci.yml.

Budget

06-console drops 13 → 5 (the Cloudflare-only baseline measured the build step at 0.6s and the whole console job at 1m13s–1m22s). Bootstrap budget is now 45 minutes, from 84 where this work started.

docs/phases/TIMINGS.md states the one condition plainly: the fetch needs a published artifact for exactly those sources. Without one the pin is absent, the phase is its old ~13, and nothing fails.

Verification

  • Console typecheck clean.
  • 25 suites / 258 console tests pass, including the new app-config.test.ts. (On main one suite can't compile in this sandbox for an unrelated @saas/sdk build-order reason; with the sdk built, both are green.)
  • testing/console-artifact.test.sh holds pack determinism, the pin, the fetch, a changed console, a tampered asset, the no-artifact path, and that the rebrand doesn't touch the pin — it caught a real bug: without the exclude rule the rebrand rewrote the pin's baseline URL.
  • Full contract suite 12/12, plus orun new --status under v2.88.0.
  • A placed product carries ci.yml only — no tag.yml, no baseline.yml.

Note on tagging

This adds tag.yml, which the repo didn't have. Baseline tags have been cut by hand; this session cannot push tag refs (the git transport returns 403 for them and the REST refs API is blocked by the proxy), so baseline-v30 is still uncut. With tag.yml merged, a tag can be cut by workflow_dispatch instead — a path that works from here.


Generated by Claude Code

…d not built

Table 1.3, the last item of the bootstrap speed-up, and the one that needed
real work in the console rather than a script: the prebuilt console artifact.

It could not be done before because the console baked its environment into the
bundle. `environmentBuildVar: NEXT_PUBLIC_DEPLOY_ENV` was compiled in, and
`DEPLOY_ENV` functionally LOCKED the console's API target — so a stage build
deployed to prod would have pointed at the stage API. One build could not
serve both environments, and an artifact that cannot be redeployed anywhere is
not an artifact.

CA1 — identity at runtime. `src/lib/app-config.ts` keeps its constants as the
compiled-in fallback (so `PRODUCT_NAME = "Lumen"` and
`STORAGE_PREFIX = "lumen.next"` remain the literal seams rebrand.mjs matches,
and the rebrand needed no new rule) and gains a resolved `AppConfig`: each
field overridable per request by the Worker's `vars`, which OpenNext copies
into `process.env`. The root layout resolves it on the server and hands it to
the client through `<Providers config>`; `wrangler.jsonc` carries the five
`CONSOLE_*` vars, which the rebrand rewrites, so a product's console says the
product's name even though the bundle was built from the baseline's sources.

CA2 — environment at runtime. The deploy environment is read from the `-<env>`
its workers.dev host carries, or `CONSOLE_DEPLOY_ENV` where a custom domain
names none. `environmentBuildVar` is gone. api.ts's `TARGETS` / `DEPLOY_ENV` /
`IS_LOCKED` were module constants evaluated once at import; they are now
`apiTargets()` / `deployEnv()` / `isLocked()`, reading the config in force.

CA4 — the artifact. 06-console's `console-artifact` hook pins the baseline's
published artifact (URL, sha256, and the product's own source hash); the
component's buildCommand verifies the digest and unpacks it instead of running
a cold Next.js build. Everything degrades to a normal build: no artifact, a
changed console, an unreachable URL. Only a digest mismatch is fatal. The
rebrand leaves the pin alone — it names the BASELINE's release, which is
provenance. `.github/workflows/tag.yml` publishes one as part of cutting a
`baseline-vN` tag, and is ignored from products.

06-console drops from 13 to 5 (the Cloudflare-only baseline measured the build
step at 0.6s and the whole console job at 1m13s–1m22s), so the bootstrap
budget is 45 minutes, from 84 where this work started. docs/phases/TIMINGS.md
states the one condition: the fetch needs a published artifact for exactly
those sources, and without one the phase is its old ~13 and nothing fails.

Verified: console typecheck clean; 25 suites / 258 console tests pass (the new
app-config suite among them); testing/console-artifact.test.sh holds pack
determinism, the pin, the fetch, a changed console, a tampered asset, the
no-artifact path and the rebrand's hands-off; full contract suite 12/12 with
`orun new --status` under v2.88.0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BfmHkwWeA1oPJGBNF3QSQH
if (typeof window === "undefined" || !slug) return;
try {
window.localStorage.setItem(LAST_ORG_KEY, slug);
window.localStorage.setItem(lastOrgKey(), slug);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced this. It is pre-existing and attributed here only because this PR touched adjacent lines, and I do not believe it is a true positive — but I am leaving it open for a human call rather than closing it myself.

The dataflow is unchanged by this PR. Before (f5bf493) and after (8a7059a), resolvePostAuthDestination does:

const home = pickAccountBillingOrg(organizations)!;
writeLastOrgSlug(home.slug);          // → window.localStorage.setItem(<key>, slug)

The only thing this PR changed in this file is how the storage key is computed — const LAST_ORG_KEY = \${STORAGE_PREFIX}.last-org`becameconst lastOrgKey = () => `${appConfig().storagePrefix}.last-org``, because the storage prefix is runtime config now (saas-console-artifact CA1). The stored value and its source are identical.

Why I read it as a false positive. pickAccountBillingOrg returns the oldest org from the caller's own org list, and what reaches localStorage is .slug — a URL path segment the user is about to see in their address bar (/orgs/<slug>/projects). It is an identifier, not a credential; the token, which is sensitive, is handled separately in session.tsx. The module's own header has said this since it was written: "It's a low-sensitivity hint (just a slug)." CodeQL appears to taint the whole org object and flag the sink.

What I have not done: changed any code to silence it. If you want it addressed rather than dismissed, the options are to stop persisting the slug client-side (it would need the per-user preferences API the module's header describes as the upgrade path), or to dismiss the alert as a false positive in code scanning. That call is yours.

Flagging one process failure of mine alongside it: I merged this PR without seeing this check. I verified the three Actions workflow runs were green and did not list the repository's check runs, which is where CodeQL reports. On #118 and #119 I did list check runs; here I did not, and that is how a failing high-severity check got past me.


Generated by Claude Code

@ruehowl
ruehowl marked this pull request as ready for review October 25, 2026 15:05
@ruehowl
ruehowl merged commit 8a7059a into main Oct 25, 2026
9 of 10 checks passed
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