ui-server config: two comments promise nothing below createApp reads process.env, but a dozen call sites do

Aperta Adatta ai principianti
#4,833 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript

Direzione di ricerca

Leggi packages/ui-server/src/app.ts attorno al commento su CreateAppOptions.config e alle chiamate a githubToolsTokenSource(), poi confronta l’intestazione di packages/ui-server/src/config/env.ts con DYNAMIC_ENV_READS. Aggiorna i commenti per descrivere le letture rimanenti dell’ambiente di processo e condividi una sola closure della sorgente del token GitHub tools tra i relativi consumatori. Controlla le suite GitHub tools e della route dei dettagli GitHub indicate nella PR, insieme ai controlli elencati per l’ambiente e i report API.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent-ready area: ui-server priority: p3 type: refactor

Context

CreateAppOptions.config promises that createApp resolves the environment once, "here at the edge — nothing deeper in the package touches the ambient environment", so that two differently configured apps can run in one process and tests can vary configuration without mutating process.env (packages/ui-server/src/app.ts:234-240). The header of config/env.ts repeats it: every consumer "never touches process.env itself" (packages/ui-server/src/config/env.ts:13-16).

That is not what the code does. These helpers default to process.env and are called without an environment argument below the edge:

  • subprocessEnv() (config/env.ts:1486-1492), which filters process.env for a child process at call time: app.ts:510 (twice) and :870, attachments/extract.ts:89, brain/application.ts:200, brain/client.ts:204, :212, :326, routes/brain.ts:317, schedules/service.ts:139, storage/removal-facts.ts:12, storage/removal.ts:235.
  • Credential and key sources: referenceCredentialValues() (app.ts:556), apifyTokenSource() (app.ts:820), githubToolsTokenSource() (app.ts:843 and again at :1231), resolveWebSearchEnv() (app.ts:868, routes/web-search.ts:146).
  • Three lazy createModelPricing(resolveStandalonePricingConfig()) fallbacks (activity/store.ts:458, ws/session-catalog.ts:217, ws/session-catalog-writes.ts:141).
  • maintenanceDataRoot() (config/env.ts:1594-1596), read in the maintenance child's entry (brain/maintenance-entry.ts:41).

The effect: createApp({ config: resolveServerConfig(customEnv) }) applies only part of customEnv. Two apps in one process, or two tests, cannot differ in child environment, GitHub or Apify credentials, reference credentials or web-search keys without changing process.env. A reader who trusts either comment will write such a test and get the ambient values.

Part of this is documented as intended. DYNAMIC_ENV_READS lists subprocessEnv as a call-time read (config/env.ts:1572-1591), docs/supported-inputs.md:637 documents subprocessEnv(audience, extra, extraNames) as a supported input, and child environments are a privilege boundary (docs/decisions/hardening.md, ruling 4). The closed epic #1343 fixed the exec wrapper and listed subprocessEnv() as out of scope, and #2784 repeats that exclusion. So the two comments are the part that is wrong.

Decision (2026-11-27, delegated orchestrator choice; reviewer marked it the clear preferred option): correct the two comments to what the code does, and build the GitHub tools token source once per app. Nobody has a use case today for two apps in one process with different credentials or child environments. Rejected: resolving every read once at boot, which turns a documented call-time read at a privilege boundary into a boot-time snapshot and adds fields to the documented ServerConfig; and threading only the credential, web-search and pricing sources through ServerConfig, which adds contract surface and threads through createApp ahead of #2784 with no caller asking for it.

Related: #2784 (splits createApp and edits the same file; whichever lands second rebases). #4822 edits other comments in config/env.ts; whichever lands second rebases.

Scope

  • The doc comment on CreateAppOptions.config (app.ts:234-240) says what passing config covers and what it does not: createApp resolves ServerConfig once, and these are still read from the process environment whatever config holds: child-process environments (subprocessEnv, at each spawn), the reference, Apify and GitHub-tools credentials, the web-search provider keys, and the standalone pricing fallback. It says that two apps in one process share those.
  • The header comment of config/env.ts (:13-16) says the same in one or two sentences and points at DYNAMIC_ENV_READS for the call-time reads.
  • createApp calls githubToolsTokenSource() once and passes the one closure to both createGithubToolsHost and createGithubDetails (app.ts:843, :1231).

Out of scope

  • Threading any environment-derived value through ServerConfig, and any new ServerConfig field.
  • subprocessEnv, BRAIN_UI_SUBPROCESS_ENV_EXTRA, the audience allowlists, and the DYNAMIC_ENV_READS entries: unchanged.
  • ENV_VARS, docs/supported-inputs.md and the generated environment documentation: no variable is added, removed or redocumented.
  • Restructuring createApp (#2784).
  • The exec wrapper (ServerConfig.exec), already resolved at the edge (app.ts:381-388).
  • maintenanceDataRoot(): it runs in the maintenance child process, which has no ServerConfig.
  • The other comments in config/env.ts that no longer sit on their declarations (#4822).

Acceptance criteria

  • git grep -n "nothing deeper in the package touches the ambient environment" -- packages/ui-server/src returns nothing, and the header of config/env.ts no longer says that consumers never touch process.env.
  • The CreateAppOptions.config comment names each group of remaining ambient reads listed in Scope, and each name it uses is an exported function that exists (subprocessEnv, referenceCredentialValues, apifyTokenSource, githubToolsTokenSource, resolveWebSearchEnv, resolveStandalonePricingConfig). The PR lists, for each group, one call site that proves the comment true.
  • git grep -n "githubToolsTokenSource(" -- packages/ui-server/src/app.ts shows one call.
  • The existing GitHub tools and GitHub detail route suites pass with no edit to their assertions (the PR names them).
  • subprocessEnv, DYNAMIC_ENV_READS and ENV_VARS are byte-identical, and the env-access gate and the env-parity gate pass.
  • api-report/ui-server.txt is byte-identical.

Verification

bun run test packages/ui-server/tests/env.test.ts
bun run test packages/ui-server
NODE_OPTIONS=--max-old-space-size=6144 bun run typecheck
bun run lint
bun run api-report
bun run check:pr --base origin/main

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit.
  • This changes a published package's behaviour, so it needs a changeset.

Two comments change and one token closure is shared by its two consumers; both closures read the same variable at boot today, so no request, credential or child environment differs.

Found by a repository audit on 2026-11-26 (main 87b96b10c); independently reviewed before filing.

Lingua principale
TypeScript
Stelle
5
Fork
0
Merge medio
8h 3m
PR unite (30g)
606

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di schlessera/brain-kit

Tutte le issue di schlessera/brain-kit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.