Skip to Content
gentlemans-stack

Learnings

Tool quirks, false positives and root causes that a future developer would trip on again, newest first.

Tool quirks, false positives and root causes in this repo that a future developer would trip on again and that the code does not show: the "why," not the "what." stack.md holds the settled stack choices; decisions and why one approach beat another go to trail (trail note, saved in .trail/learnings/).

New entries go at the top. Keep each one short: what was learned, and why it matters. Delete an entry once the code or another doc states it or it stops being true.


2026-11-30 — Static docs site on TanStack Start and GitHub Pages

  • Nitro's static preset breaks the Start build (the SSR input is an html file), so apps/docs has no nitro. It uses Start's own prerender with crawlLinks, and the output is apps/docs/dist/client.
  • "type": "module" is required in apps/docs/package.json. Without it the SSR bundle is server.mjs while the prerender's preview server imports server.js, and every prerendered page fails with an unexplained 500. The real error shows only under vite preview.
  • @tanstack/start-static-server-functions ignores the Vite base when it fetches its cache files (checked up to 1.167.44), so client navigation breaks under any non-root base. patches/@tanstack__start-static-server-functions@1.167.33.patch prefixes import.meta.env.BASE_URL. The package is pinned to 1.167.33, the last release whose peer accepts react-start ^1.168. Re-check the patch on every upgrade.
  • Pages needs a 404 the SPA shell can serve. A prerendered page that returns 404 fails the build, so 404.html is the prerendered SPA shell and the root notFoundComponent shows the message. React logs hydration error #418 once on that page, which still renders. Turning on spa also makes the dev server render pages in the browser.
  • Prerender dedupes by path string. The SPA shell takes /, so the real home page is requested as /?home (listed in pages in vite.config.mts); without it a site served at the domain root has no index.html.
  • Fumadocs collections. files replaces the default glob and dir may point outside the app. The record form of loader({ source: { a, b } }) does not set page.data.type, so the two collections are told apart by virtual path. defineDocs needs an explicit DocsCollection<...> type to avoid TS2883 under composite. In a route, loader must come before head, or loaderData types as never.
  • gh-pages leaks dotfiles on the first publish. With no gh-pages branch on the remote it checks out an orphan that keeps the files of main, and its default remove pattern skips dotfiles, so .claude, .trail and .vscode would go public. docs:deploy passes a --remove glob that includes dotfiles. Check it with docs:deploy:dry and git ls-files in node_modules/.cache/gh-pages/*.
  • Nx already infers a serve-static target, so the custom one is serve-pages. A package.json target with only options.command becomes nx:noop, and a second nx dev docs only waits for the first.
  • pnpm adds minimumReleaseAgeExclude entries for packages newer than the release-age policy, here fumadocs-core and fumadocs-ui. Review them before committing.

2026-11-30 — OpenTelemetry and audit: where spans, logs and rows silently go missing or double up

Node side

  • @orpc/otel records nothing unless re-enabled after the SDK starts. It loads as ESM with its own copy of @opentelemetry/api, so the tracer it takes in its constructor stays a no-op. startObservability calls orpc.enable() again after startNodeSdk. Its version must equal @orpc/server exactly (pnpm-workspace.yaml pins it): a caret range gave two @orpc/shared copies and the config never arrived.
  • A second esbuild entry loads the SDK first. additionalEntryPoints writes dist/instrument.js beside main.js; serve passes runtimeArgs: ["--require", "./{projectRoot}/dist/instrument.js"] and the Dockerfile runs node --require ./instrument.js main.js. Importing it first in main.ts also works but depends on import order surviving edits.
  • No mongoose instrumentation: Better Auth uses the raw driver, and mongoose spans only duplicate the driver spans as siblings. instrumentation-http already records http.server.request.duration, so only auth.failures and workspace.invites.accepted are ours.
  • open.router(...) re-applies the open chain to guarded procedures, which ran authenticate, audit and the span twice (two audit rows, two spans). iam-service uses implementers.router, which applies no middleware; the audit middleware is idempotent as a guard.
  • Logs and traces only join in Grafana when service.name matches. evlog names a log after the package; runInstrumentation sets OTEL_SERVICE_NAME and the log plugin passes it on.
  • Grafana LGTM's data must be a named volume on macOS. With a bind mount Loki answered every OTLP log write with 503 while traces and metrics worked. Grafana is on 9300 (3xxx is the services, 4300 another project).
  • Contrib 0.166 has no rate limiter (only memory_limiter), so a per-IP limit on the public OTLP/HTTP port belongs on a reverse proxy (LOCAL_INFRA/README.md). The Collector's transform/redact strips query strings again.

Browser side

  • No sdk-trace-web 3.x (latest 2.12 peers api <1.10): use TracerProvider and StackContextManager from @opentelemetry/sdk-trace 3.1 (libs/observability/src/web.ts). The classic fetch and document-load instrumentations are deprecated; use @opentelemetry/browser-instrumentation/experimental/* (0.x, expect breaking changes).
  • Query strings and tokens end up in url.full of every fetch, document-load and resource span. Rewrite them once in a span processor's onEnding (the only hook with a writable span); attributes cannot be deleted, only overwritten.
  • An unanchored propagateTraceHeaderCorsUrls pattern matches https://api.example.com.evil.test: use anchored regexes. Playwright's request.postDataBuffer() shows what the browser really exported to the Collector.
  • Spans of the last ~2 s of a run are orphans (the page closes or the server is killed before the parent span ends); everything else is complete in Tempo.

Audit

  • oRPC's .meta() merge drops method bivariance, so the audit extractors are typed any (AuditProcedureMeta).
  • The audit middleware must run before the intent guard: a refusal throws before any later middleware runs, so only an earlier one records a denied attempt.
  • evlog/audit is not a subpath (it is in the root evlog export), and evlog/better-auth has no lifecycle hooks, so account events use Better Auth's hooks.after (account-audit.ts).

2026-11-29 — Zod 4 .meta() in the form builder

Pinned by ui-libs/design-system/src/form/zod-meta-facts.spec.ts (Zod 4.5.4):

  • .meta(x) returns a new schema; the original keeps its meta. It copies Zod's description to the clone but not id, and spreading a meta that holds an id back into .meta() does not throw.
  • .meta(x).optional(), .default() and .nullable() leave the outer schema without meta (it stays on the inner one); .meta(x).min(n) keeps it. So ui.* goes outermost and the walker (describe-schema.ts) merges meta from every layer.
  • Our meta key for help text is hint, not description: Zod types description as a string, so a locale function there does not compile (and would break z.toJSONSchema).
  • Specs are excluded from tsc (tsconfig.lib.json), so a // @ts-expect-error in a spec is only proven by a manual tsc over src/form/** with a temporary tsconfig that drops the exclude.
  • A SelectField with 7 options is a searchable combobox, and while its popover is open Radix hides the other comboboxes: a spec cannot open a second popover after picking in the first without it being closed again.

2026-11-29 — Form system: decisions the code does not show

The forms plans were deleted once finished (git history has them); what is not obvious from the code:

  • showErrors modes also show an error after a submit attempt: TanStack sets isTouched on submit but never isBlurred, so a strict blur rule would hide every error on an untouched form.
  • ArrayField drag uses native HTML5 drag and drop on a grip button (no library); it has no touch drag, so the arrow buttons stay the touch and keyboard path.
  • @tanstack/react-table is pinned to v8: v9 has a different useTable API.
  • form.Form and the login form post (method="post"): a submit before hydration must never put a password in the URL.
  • A withFieldGroup component (NewPasswordFields) needs Bound exported from design-system/form, or tsc reports TS2883 (a type that "cannot be named").
  • todo-ui must mount <Toaster /> in __root.tsx; without it every toast.* call is silent.

2026-11-29 — fallow false positives are fixed in .fallowrc.json, not by deleting

fallow dead-code lists scripts run by node, hooks or Nx targets as unused files, and the root package.json dependency mirrors that CLAUDE.md requires as unused dev dependencies. They are covered by entry, ignoreDependencies and, for generated shadcn files (ignoreExports, one file at a time), not by removing anything. A mirror is removable only when no workspace package.json, import or generator under tools/nx-plugin uses it.

2026-11-29 — Playwright e2e quirks

  • IAM's sign-up and sign-in limits are stored in Mongo, so a restart does not reset them. A todo-ui e2e run uses 2 of each and retries stays at 0; back-to-back runs within a minute get HTTP 429.
  • playwright test --list does not run global-setup, so listing works without E2E_PASSWORD.
  • A package.json nx.targets entry with only options.command and nothing that infers it is dropped from the project graph without a warning. Give it "executor": "nx:run-commands", or a top-level command.

2026-11-29 — A closed Radix Select can hang a long jsdom test sequence

SelectField's 4-to-5-option control first used the Radix Select. In apps/todo-ui/src/routes/app.spec.tsx (20 tests) the admin route rendered one, and the later fireEvent.click of the invite test then spun at 100% CPU inside React's event dispatch (no failure, no timeout, because the loop is synchronous). Each test passed alone and in short sequences; raw RadioGroup, Combobox and Field did not trigger it. The control is now shadcn's native-select, which also suits phones. Debugging that worked: start vitest with --inspect=127.0.0.1:9239 --no-file-parallelism, connect with a small WebSocket client and send Debugger.pause (a worker's stdout is blocked while it spins, so the reporter shows the wrong test).

2026-11-29 — shadcn add output needs fixing up

  • The registry's field, textarea and sidebar items import cn from the npm package cn, which is unrelated to shadcn's helper, and the CLI adds "cn" to ui-libs/design-system/package.json. Point those imports at ../../lib/utils, delete the dependency and run pnpm install.
  • Generated files often fail our Biome rules (useSemanticElements, noDoubleEquals, noLeakedRender, noArrayIndexKey), so run pnpm exec biome check on them.
  • To decline the overwrite prompts (sidebar wants button, sheet and separator), pipe yes n | into pnpm dlx shadcn@latest add ...; -y overwrites.
  • sonner.tsx imports useTheme from next-themes, and sidebar appends hard-coded --sidebar-* colours to globals.css: point the first at the design system's own useTheme and alias the second to existing tokens, or design-tokens:generate-check fails.

2026-11-28 — Todos moved into workspaces

  • Todos created before workspaces no longer parse and there is no migration: delete them by hand (db.todos.deleteMany({ workspaceId: { $exists: false } })).
  • The todo cache tag stays todo: a contract's meta is static, so it cannot carry a workspace id. A write therefore over-invalidates other workspaces' lists.

2026-11-28 — Workspace guard typing and in-process sign-up cookies

  • auth.api.signUpEmail({ returnHeaders: true }) sends each of session_token and session_data twice, and only the last token is a real session row. Joining every Set-Cookie into one cookie header works while the cookie cache is on and fails once disableCookieCache is set.
  • createRequireIntent returns { ...context, membership }. A service whose RequestContext has principal? optional must instantiate it with RequestContext & { principal: Principal<...> }, or oRPC rejects .use() after the session middleware.

2026-11-28 — IAM and Better Auth gotchas

Checked against better-auth 1.7.28.

  • The rate limiter keys on a spoofable header. By default it uses the first x-forwarded-for entry, which any client can set. Requests with no or a multi-hop header all share one no-trusted-ip bucket per path, so five bad sign-ins from anyone lock everyone out. A server-to-server get-session call without the client's IP puts every user in one bucket. Behind your own hosting, count hops from the right and check the real hop count before treating per-IP limits as hard.
  • get-session answers from the signed cookie for IAM_SERVICE_SESSION_COOKIE_CACHE_SECONDS (300), so a ban or revoke reached services late. createIamSessionAuthProvider sends disableCookieCache=true; browsers' own calls still use the cache.
  • rateLimit.customStorage needs an atomic consume; separate get/set are rejected, so libs/rate-limit cannot be plugged in as is. Better Auth's limiter covers /api/auth/* only.

2026-11-28 — TanStack Start and Radix testing gotchas

  • Testing routes: router.flatRoutes is undefined at runtime, use router.routesByPath. The design system's @/ alias must be set in vitest.config.mts as well as vite.config.mts.
  • Radix in jsdom: a DropdownMenu opens with fireEvent.keyDown(trigger, { key: "Enter" }); jsdom has no PointerEvent, so a pointer click does not.
  • A query keyed on its arguments (the admin users table) needs placeholderData: keepPreviousData, or the table unmounts on every sort and page change.

2026-10-27 — Device frames: Duo captures and syncing new assets

A Duo simulator has two displays, so capture duo and capture duo-closed both run on it: unfold or fold it first. scripts/sync-from-stack.mjs copies git-tracked files only: git add -N new assets before syncing.

2026-10-19 — Tilted store cards are not byte-stable

Store cards with a tilted device (variant left or right) differ between runs by at most 16 per channel on the device edge: Chromium rasterizes the rotated, layer-promoted device and its blurred shadow differently on some launches. Compare them with a small pixel tolerance, not cmp; centre cards are byte-identical. Awaiting img.decode() and --disable-gpu --force-color-profile=srgb were tried and reverted (the flags changed every card).

2026-10-19 — Shared Biome config pitfalls

  • A biome.shared.jsonc that itself extended the ultracite presets silently dropped them (217 instead of 347 rules); biome rage --linter is the quick check.
  • Biome 2.5 ignores .editorconfig by default, so it only guides editors.
  • Format generated config with the repo's own formatter (pnpm exec biome format --write <file>); a generated .mcp.json with tabs failed pnpm run check in repos that format JSON with spaces.

2026-10-19 — Docs lint skips node ../ commands

scripts/docs-lint.mjs skips node paths starting with ../ because they resolve from a cd earlier in the same block, which a static check cannot follow.

2026-10-19 — Error handling decisions

  • Every internal failure is INTERNAL_SERVICE_ERROR with data: {}: public codes that echoed driver messages leaked index names and duplicated values. There is no CONFIGURATION_ERROR: libs/configuration fails at startup with a plain Error, and a request-time misconfiguration (a procedure with no RBAC intent) is new AppError("INTERNAL_SERVICE_ERROR", {}, { cause: "missing_rbac_intent" }).
  • A malformed JSON body never reached handleError because oRPC decodes the body before clientInterceptors run, hence the request-level interceptor in libs/server-setup. A non-JSON multipart body still gets oRPC's BAD_REQUEST; the stack is JSON-only.

2026-10-19 — Platforms layer and Firebase auth

  • fallow ignores unzoned files. A platforms zone alone would not stop libs/cache, libs/rate-limit or libs/test-support importing a platform unnoticed, so they sit in a standalone-libs zone (.fallowrc.json). The gate is fallow architecture --boundaries; plain fallow check exits 1 on unrelated findings, so it can't serve as one.
  • platforms/*/* matched the script-only folder platforms/gcp/cloud-run, so fallow warned about a missing package.json. pnpm-workspace.yaml excludes it (!platforms/gcp/cloud-run) and .fallowrc.json lists it in ignorePatterns; fallow's workspaces.patterns has no negation. Add the same pair for any script-only folder under platforms/.
  • A new workspace package needs a root tsconfig.json reference, or every pnpm nx run refuses with "workspace is out of sync". Run pnpm nx sync; pnpm nx sync:check is the read-only diagnosis.
  • The nested skill platforms/gcp/.claude/skills/firebase-auth-tests loads once Claude works on files under that directory, so products without GCP never see it.

2026-10-19 — Cloud Run scripts

  • --dry-run prints mutating gcloud calls and the docker build to stderr, because several calls end in >/dev/null; stdin values are never printed.
  • macOS bash 3.2 errors on an empty array expanded under set -u, hence ${SECRET_NAMES[@]+"${SECRET_NAMES[@]}"}.

2026-10-18 — Agent tooling env and context cost

  • Secrets that MCP config expands (${CONTEXT7_API_KEY}) must be exported from ~/.zshenv, not ~/.zshrc: the desktop app and its tool shells start non-interactive zsh, which skips ~/.zshrc, and context7 then connected keylessly with only claude mcp list warning. zsh -c vs zsh -ic shows the difference.
  • Every user-scoped MCP server costs context in every repo (its instructions block and tool-name list arrive at session start); only project scope avoids that. Skills cost a listing line each against a budget (1% of the context window), past which the least-used skills lose their descriptions.

2026-10-13 — Mobile skeleton and email tokens

  • Generated Dart is not formatted by the generator (formatFiles handles ts/json/md only), so mobile-app templates with no placeholders are copies of the formatted files in apps/todo-mobile; diff a rendered app against it to catch drift.
  • Keep app names out of Logger('...') strings: mobile-app-rename rewrites imports, package names and titles, not logger names.
  • Email tokens keep the alpha hex of the dark border/input tokens (#RRGGBBAA); older Outlook may not render it.

2026-10-13 — Patterns carried back from the first product built on this stack

  • Rate-limit rules: procedure meta is a list of rules because one limit per dimension is the only way to say "10 per IP and 3 per email". Abuse-sensitive public endpoints such as "email me a link" fail closed.
  • Client IP: a header set by your own frontend is only trustworthy with a shared secret compared with timingSafeEqual over SHA-256 digests.
  • Emailed token links: store only the SHA-256 of the token. Mail scanners prefetch links, so the GET that opens a link must never be the destructive step: show a preview, and only a button that POSTs acts. Put the token in the request body, not the URL, to keep it out of access logs. Endpoints that take an email answer the same way and with the same timing whether or not the account exists, and send the email after responding.
  • tsconfig lib replaces, it doesn't extend: lib: ["dom"] drops the base es2022 and hides Array.prototype.at, which Biome's useAtIndex then asks for. Use ["dom", "es2022"].
  • Run pnpm fix and nx sync on a clean or backed-up tree: in a product repo, running them coincided with every unstaged edit to tracked files vanishing (cause not found); it was recovered from a dangling stash commit (git fsck --no-reflog --lost-found). Take git diff HEAD > file first when the tree is dirty.
  • Release builds bake in Flutter's .env: an app that lists .env as an asset ships whatever API_BASE_URL it holds, so a LAN address yields a build that succeeds and is useless.

2026-10-02 — Mobile app generator

  • flutter create . into a directory that already has pubspec.yaml and lib/main.dart keeps them and only adds the platform folders, so the mobile-app generator writes its files first and runs flutter create in the post-generation callback (which also deletes the stray <name>.iml).
  • design-tokens:generate discovers Flutter apps by apps/*/pubspec.yaml, so a new app needs no registration.
  • mobile-app-rename rewrites only known contexts (package:x/, apps/x, nx run x:, bundle id strings), never a bare name, because short names like app also appear inside file names.
  • A Card inside Padding as a Scaffold body stretches to full screen height (tight constraints); widget tests missed it and the simulator showed it. Use a ListView body.

2026-09-25 — Profile Biome rules before blaming monorepo file discovery

biome lint --profile-rules showed suspicious/noUnnecessaryConditions consuming 27 s of CPU in a few configuration files (pathological type inference) while every other rule stayed under 41 ms. A narrow override in biome.jsonc disables it only there.

2026-09-15 — Mongo authentication and operation databases must stay aligned

Mongoose's dbName option overrides the URI path for database operations, but credentials still authenticate against the URI's authentication database, so a user can connect and then fail every query. Grant the user on the exact database the service operates on.

2026-09-15 — Vitest project discovery must target first-party configs

A recursive **/vitest.config.* project glob reaches declaration files under node_modules, and including both vite.config.* and vitest.config.* registers a package twice. Scope the root project glob to package directories and dedicated Vitest configs.

2026-09-14 — Connector and Redis quirks

Under NodeNext, relative test imports need .js, and ioredis v6 exposes its constructable client as the named Redis export.

2026-09-09 — A missing generator spec hides coverage and confuses fallow

A generator is reachable only through generators.json's dynamic lookup, so fallow flags one with no spec as dead code; a spec that imports it makes it traceable and covers its output. Writing the domain generator's spec also exposed a template that made new domains depend on packages the generated code never imports.

2026-09-09 — Deploy dependencies and pnpm linking

  • A deployable-service esbuild bundle inlines every workspace lib it composes, but the Docker prune step reads only the service's own package.json. A package used only by a composed lib (jose via libs/auth) can be missing from the service's dependencies, and the gap surfaces only when the pruned image runs (MODULE_NOT_FOUND). scripts/sync-bundle-dependencies.mjs --check scans the compiled bundle for retained require() calls; the generated sync-deploy-deps target runs it (pnpm nx run <service>:sync-deploy-deps).
  • pnpm's strict linking already fails typecheck/build for a lib that imports an undeclared package, so no extra tooling is needed for that case.

On this page

2026-11-30 — Static docs site on TanStack Start and GitHub Pages2026-11-30 — OpenTelemetry and audit: where spans, logs and rows silently go missing or double up2026-11-29 — Zod 4 .meta() in the form builder2026-11-29 — Form system: decisions the code does not show2026-11-29 — fallow false positives are fixed in .fallowrc.json, not by deleting2026-11-29 — Playwright e2e quirks2026-11-29 — A closed Radix Select can hang a long jsdom test sequence2026-11-29 — shadcn add output needs fixing up2026-11-28 — Todos moved into workspaces2026-11-28 — Workspace guard typing and in-process sign-up cookies2026-11-28 — IAM and Better Auth gotchas2026-11-28 — TanStack Start and Radix testing gotchas2026-10-27 — Device frames: Duo captures and syncing new assets2026-10-19 — Tilted store cards are not byte-stable2026-10-19 — Shared Biome config pitfalls2026-10-19 — Docs lint skips node ../ commands2026-10-19 — Error handling decisions2026-10-19 — Platforms layer and Firebase auth2026-10-19 — Cloud Run scripts2026-10-18 — Agent tooling env and context cost2026-10-13 — Mobile skeleton and email tokens2026-10-13 — Patterns carried back from the first product built on this stack2026-10-02 — Mobile app generator2026-09-25 — Profile Biome rules before blaming monorepo file discovery2026-09-15 — Mongo authentication and operation databases must stay aligned2026-09-15 — Vitest project discovery must target first-party configs2026-09-14 — Connector and Redis quirks2026-09-09 — A missing generator spec hides coverage and confuses fallow2026-09-09 — Deploy dependencies and pnpm linking