Public: anyone can read this; the crew can change it.
server.ts imports page, studio, render and API modules on the first request to their prefix #17313
Merged 32h 48m ago, live in production
The boot's static module count drops from 4061 to 2320, 1741 fewer than before and well past the 700 asked for. The count is the static import closure of src/main.ts, not bun build --metafile. A bundled build inlines dynamic imports, so the metafile does not fall when a module moves to import().
-
Reviews
ApprovedClean on security. Every module is still mounted on the same method and path, so the gates in
answerRoute(admin, run, read-grant, via, contribute) run unchanged. The contract is awaited before any guard that reads it, for/api/routes,/metricsand?page=/?fields=.adminGatestays on every request.contract_lazy.tsthrows if the contract is read before it is loaded, so a missed await fails loudly instead of letting a request through. A test holds the list of contract admin routes outside/api/(/metrics) to the contract's own. Each route list is held to its module's own routes bytest/boot-lazy.test.ts, so a drifted list fails. A failed load is retried. No design surface changes: thesrc/web/edits only moveoriginIconand call sites, so there is no new page, no new door and no README change. Box 2 is ticked on the static closure ofsrc/main.ts(4061 to 2320, with a ceiling test) rather thanbun build --metafile. The builder says why the metafile does not fall, and the boot's imports are what the box is after. -
Checks
shipped production is serving it deploy c4333e8
-
History
- Lazy contract and admin page load by import(), not require(); route tests read lazy mounts dfa4887
- AGENTS.md: the boot imports no page family; where a route module is mounted 4c91479
- Rewrap the lazy lists and the boot test's comments 8eaf2bf
- Page families behind server.ts load on first request to their prefix (#17020) 566bfb5
- Game boxes open 19132/udp for Bedrock players (#17282) a28ad97
- The game agent has one compose command: an array every call and the background job share (#17261) c95f990
- Talk workspace W2: live edit loop — Talk's writes and the Code tab edit the working tree (#17177) e0c876b
- Registry: a gallery page with usage (#17192) c82ef2f
- Count the cold home's work instead of timing it, so production's-size budgets are exact on any machine (#17220) 15d3197
- Registry: rebuild the app template on the registry (#17215) 6fa635d
- Split src/http/server.ts so a route is added in its own module (#17178) 9006e4b
- Merge pull request #17267 from sold/preflight-slow db30116
- Build the duty roster on first ask, so a duty imported first is never read ha… (#17241) dd5bb60
- Talk workspace W2: a hot-reloading dev cell per workspace (#17154) 8442431
- Serving first: background work at SCHED_IDLE, and new checks and crew runs wait while the forge is under pressure (#17235) b68a708
- fork-follow-history: the follows the history test reads are built in three steps, each its own test (#17260) 0bcae71
- A pull reads green and can land while its tests are still queued (#17258) 922eb80
- phone-targets measures the select inside Talk's closed Display menu, so main'… (#17250) 8874dc1
- Preflight runs the SLOW tests that read the whole tree, so a rule test like job-slices reds it as it reds the check 121c9c4
- Edges: DNS records as their own infra kind via Cloudflare, including SRV (#17093) 35ce195
The boot's static module count drops from 4061 to 2320, 1741 fewer than before and well past the 700 asked for. The count is the static import closure of src/main.ts, not bun build --metafile. A bundled build inlines dynamic imports, so the metafile does not fall when a module moves to import(). I did not run the metafile here.
Tests. bun x tsc --noEmit is clean. I ran about 1,000 tests that exercise what changed; all pass, including test/boot-lazy.test.ts, test/lazy-first-use.test.ts, test/mcp-size.test.ts and test/unused-exports.test.ts. The full suite was not run: scripts/fast.ts picked 3118 files, which it expects to take hours. No existing test was edited.
Route families
buildRouterandbuildApiRouterinsrc/http/server.tsnow register all 32 route modules undersrc/http/routes/, the JSON API, its siblings (feed,config,checks_recheck) and the/apiand/api/v1/changelogpages from route lists insrc/http/lazy_lists.ts. Each module is imported on the first request to its prefix.test/boot-lazy.test.tsholds each list to the routes its module adds, in order. It also checks that no family module is in the boot's static closure.- It also holds a ceiling on the boot's module count: 2400, against 2320 now.
forges.tsstays as it was; its module is already lazy.
Leaks I cut so the count could drop
contract/openapi.tsis read withrequireon first use incursor_lists.ts,named_refusal.ts,web/standards.tsandadmin_gate.ts. The gate loads the contract only for/api/routes and/metrics. A new test fails if the contract adds an admin route outside those.originIconmoved toweb/origin_icon.ts, soweb/scope.tsno longer pulls inpages/origins.ts.isPreviewEnvand the preview account lookups moved tospawn/preview_who.ts.preview-seed.tsre-exports them, so its importers are untouched, and the seed itself is imported only in a preview.main.tsimports the home, plans and boards warm-ups andrecordAskLedgerwithimport(). They still run at boot as before.- The everyday-account refusal page is read when first needed.
I also updated AGENTS.md on where modules load and how a new route module is mounted.
Not done. About 58 modules in the page and studio families remain reachable through callers such as actions/* that import web/studio/asks.ts. Cutting them needs asks.ts's data half moved out of web/, which is a separate change. The previewAdmin and previewNewcomer near-duplicate the gate flagged was already in the code I moved.
To try it. On the preview, open /, /settings/tokens, /api/v1/changelog and /api; each answers as on main, and the first request to each prefix pays one import. To count the boot's modules, run bun test test/boot-lazy.test.ts.
🤖 Generated with Claude Code
This push fixes the three failing tests from the check. The full suite has not been run here. I ran the failing tests, boot-lazy, admin-gate, guide, server-timing-sweep, unused-exports, and the openapi* tests, and all passed. tsc is clean. I stopped a wider scripts/fast.ts run because it named 3121 files and would have taken hours.
What changed
require()rule: the lazy loads from the earlier commit usedrequire(), which Bun refuses on a module graph with a top-level await. They are nowimport().- A new
src/http/contract_lazy.tshasloadContract(),contract()and the/metricslist.server.tsawaits it only for/api/and/metricsroutes and before the?page=and?fields=guards.namedRefusalawaits it too. adminGateis now async so it canimport()the everyday page.llmsTxtimportscontract/served.tswhen it draws the page.admin-gate.test.tsawaits the gate and loads the contract first.boot-lazy.test.tstakes the/metricslist from its new home.
- A new
- Design audit: the tests read the route modules from the
./routes/…imports inserver.ts. Those becameimport()calls, so the helper (route-modules.ts) found none. It now reads both forms. The/apipage is registered throughown.add, sodesign-audit.test.tsmatches that too. - Route drift:
test/helpers/registered_routes.tsmatchesown.addas well, which fixes the described-but-not-routedGET /api/v1/changelog.
I did not add tests for contract_lazy.ts. The existing rule, audit and drift tests are what would fail without it.
gate.ts --fix rewrapped comments in two files. I committed them, since the gate skips uncommitted files. It also flagged preview_who.ts as having two near-duplicate functions (previewAdmin and previewNewcomer). I left that for you to judge.
The boot's static module count drops from 4061 to 2320, 1741 fewer than before and well past the 700 asked for. The count is the static import closure of
src/main.ts, notbun build --metafile. A bundled build inlines dynamic imports, so the metafile does not fall when a module moves toimport(). I did not run the metafile here.Tests.
bun x tsc --noEmitis clean. I ran about 1,000 tests that exercise what changed; all pass, includingtest/boot-lazy.test.ts,test/lazy-first-use.test.ts,test/mcp-size.test.tsandtest/unused-exports.test.ts. The full suite was not run:scripts/fast.tspicked 3118 files, which it expects to take hours. No existing test was edited.Route families
buildRouterandbuildApiRouterinsrc/http/server.tsnow register all 32 route modules undersrc/http/routes/, the JSON API, its siblings (feed,config,checks_recheck) and the/apiand/api/v1/changelogpages from route lists insrc/http/lazy_lists.ts. Each module is imported on the first request to its prefix.test/boot-lazy.test.tsholds each list to the routes its module adds, in order. It also checks that no family module is in the boot's static closure.forges.tsstays as it was; its module is already lazy.Leaks I cut so the count could drop
contract/openapi.tsis read withrequireon first use incursor_lists.ts,named_refusal.ts,web/standards.tsandadmin_gate.ts. The gate loads the contract only for/api/routes and/metrics. A new test fails if the contract adds an admin route outside those.originIconmoved toweb/origin_icon.ts, soweb/scope.tsno longer pulls inpages/origins.ts.isPreviewEnvand the preview account lookups moved tospawn/preview_who.ts.preview-seed.tsre-exports them, so its importers are untouched, and the seed itself is imported only in a preview.main.tsimports the home, plans and boards warm-ups andrecordAskLedgerwithimport(). They still run at boot as before.I also updated
AGENTS.mdon where modules load and how a new route module is mounted.Not done. About 58 modules in the page and studio families remain reachable through callers such as
actions/*that importweb/studio/asks.ts. Cutting them needsasks.ts's data half moved out ofweb/, which is a separate change. ThepreviewAdminandpreviewNewcomernear-duplicate the gate flagged was already in the code I moved.To try it. On the preview, open
/,/settings/tokens,/api/v1/changelogand/api; each answers as on main, and the first request to each prefix pays one import. To count the boot's modules, runbun test test/boot-lazy.test.ts.🤖 Generated with Claude Code
Closes #17020