Skip to content

fix(scripts): detect env reads forwarded through same-file wrapper functions (#8651) - #8709

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-env-reference-wrapper-8651
Jul 26, 2026
Merged

fix(scripts): detect env reads forwarded through same-file wrapper functions (#8651)#8709
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-env-reference-wrapper-8651

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Problem

Closes #8651.

scripts/gen-selfhost-env-reference.ts recognized an env-name read only via a literal, envString(env, "X"), or a registered helper called with a literal at the call site. It had no case for a same-file wrapper function that forwards its own string parameter (not a literal) into a recognized sink. Six operator-tunable knobs read only through such wrappers were missing from the reference:

  • queue-common.ts's envDurationMs(name)parsePositiveIntEnv(name, …): QUEUE_STARTUP_JITTER_MS, QUEUE_RECOVERY_JITTER_MS, QUEUE_PROCESSING_TIMEOUT_MS, QUEUE_DEAD_LETTER_REVIVE_INTERVAL_MS, SCHEDULED_ENQUEUE_JITTER_MS
  • maintenance-admission.ts's parsePositiveFloatEnv(name)process.env[name]: MAINTENANCE_ADMISSION_MAX_HOST_LOAD

Fix

A per-file discovery pass finds any function forwarding a string parameter, unmodified, into an already-recognized env sink — a direct env[param]/process.env[param] read, an envString/parse*Env helper, a literal-arg helper, or another discovered wrapper (resolved to a fixpoint, so wrapper-of-wrapper chains are caught) — and treats it like a literal-arg helper at its call sites. Fully general: no wrapper name is special-cased.

Additional genuine reads surfaced (same mechanism)

Because the fix generalizes, it also correctly surfaces vars read through the sibling wrappers the generator likewise never saw — all verified genuine env[...] reads:

  • repoJsonMap(env, "…") (notify-pagerduty/notify-discord): PAGERDUTY_REPO_ROUTING_KEYS, PAGERDUTY_REPO_COOLDOWN_MINUTES, SLACK_REPO_WEBHOOKS
  • processEnvString(env, "…") (posthog): LOOPOVER_CENTRAL_POSTHOG_KEY
  • configured(env, "…") (ai-config) reads ANTHROPIC_API_KEY/OPENAI_API_KEY, so their firstReference now correctly attributes to the earlier-sorting src/selfhost/ai-config.ts (they are not dropped).

Plus a 6th envDurationMs call surfaces QUEUE_RATE_LIMIT_JITTER_MS. This is the intended "close the category, not just the 6 instances" outcome.

Tests

A fixture module in test/unit/selfhost-env-reference-script.test.ts exercises every wrapper form (via parsePositiveIntEnv / process.env / envString / a literal-arg helper / a chained wrapper; and function-declaration, arrow, and function-expression syntaxes) plus non-wrapper and non-literal-call negatives — covering every new branch. npm run selfhost:env-reference -- --check passes; git diff --check clean.

…nctions

gen-selfhost-env-reference.ts recognized env-name reads only via a literal, envString(env, "X"), or a
registered name-helper called with a literal at the call site. It had no case for a same-file wrapper
function that forwards its own string PARAMETER into a recognized sink, so operator-tunable knobs read
only through such wrappers never reached the self-host reference table:

- src/selfhost/queue-common.ts's envDurationMs(name) -> parsePositiveIntEnv(name, ...): QUEUE_STARTUP_JITTER_MS,
  QUEUE_RECOVERY_JITTER_MS, QUEUE_PROCESSING_TIMEOUT_MS, QUEUE_DEAD_LETTER_REVIVE_INTERVAL_MS,
  SCHEDULED_ENQUEUE_JITTER_MS (and QUEUE_RATE_LIMIT_JITTER_MS)
- src/selfhost/maintenance-admission.ts's parsePositiveFloatEnv(name) -> process.env[name]:
  MAINTENANCE_ADMISSION_MAX_HOST_LOAD

Add a per-file discovery pass that finds any function forwarding a string parameter, unmodified, into an
already-recognized env sink (direct env[param] read, envString/parse*Env helper, literal-arg helper, or
another discovered wrapper -- resolved to a fixpoint for wrapper-of-wrapper chains), and treats it like a
literal-arg helper at its call sites. Fully general -- no wrapper name is special-cased.

Because it generalizes, it also correctly surfaces vars read through the sibling wrappers repoJsonMap()
(PAGERDUTY_REPO_ROUTING_KEYS, PAGERDUTY_REPO_COOLDOWN_MINUTES, SLACK_REPO_WEBHOOKS), processEnvString()
(LOOPOVER_CENTRAL_POSTHOG_KEY), and configured() -- the last of which is why ANTHROPIC_API_KEY/OPENAI_API_KEY
now attribute to their earlier-sorting real read site src/selfhost/ai-config.ts. All are genuine reads.

Test: a fixture module exercises every wrapper form (parsePositiveIntEnv/process.env/envString/literal-arg/
chained wrapper, function-declaration/arrow/function-expression) plus non-wrapper and non-literal-call
negatives.
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.78%. Comparing base (512f720) to head (ef03e6d).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8709   +/-   ##
=======================================
  Coverage   93.78%   93.78%           
=======================================
  Files         797      797           
  Lines       79466    79466           
  Branches    24071    24071           
=======================================
  Hits        74531    74531           
  Misses       3563     3563           
  Partials     1372     1372           
Flag Coverage Δ
backend 95.06% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 00:27:11 UTC

3 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR generalizes the env-reference generator to detect same-file wrapper functions that forward a string parameter into an already-recognized env-name sink, resolved to a fixpoint so wrapper-of-wrapper chains are caught. The core algorithm (collectParamForwardingWrappers/bodyForwardsParamAsEnvName/callForwardsParamAsName) is a sound generalization of the existing literal-arg helper pattern, and the regenerated apps/loopover-ui/src/lib/selfhost-env-reference.ts output matches the new vars the description claims (QUEUE_*_MS knobs, MAINTENANCE_ADMISSION_MAX_HOST_LOAD, PAGERDUTY_REPO_*, SLACK_REPO_WEBHOOKS, LOOPOVER_CENTRAL_POSTHOG_KEY) plus the ai-config.ts firstReference correction for ANTHROPIC_API_KEY/OPENAI_API_KEY. The new test in test/unit/selfhost-env-reference-script.test.ts exercises the wrapper detection against a realistic synthetic fixture covering function declarations, arrow functions, function expressions, wrapper-of-wrapper chaining, and multiple sink types, which is a genuine test of the new code path, not a fabricated one.

Nits — 5 non-blocking
  • scripts/gen-selfhost-env-reference.ts:184 (collectParamForwardingWrappers) nests to depth 5 (walk -> isFunctionDeclaration/isVariableDeclaration branching inside a while/for loop) — consider extracting the fixpoint body into a helper for readability.
  • apps/loopover-ui/src/lib/selfhost-env-reference.ts is a generated file that has grown to ~783 lines; this is expected given the generator's nature but worth noting as it will keep growing with every new self-host knob.
  • The PR description doesn't explicitly link back to an issue number in the diff itself beyond 'fix(scripts): selfhost-env-reference generator misses same-file wrapper helpers like envDurationMs #8651' in comments — worth double-checking the PR is tied to an actual open, maintainer-acknowledged issue rather than self-motivated scope.
  • Consider adding a short top-level doc comment cross-referencing miner env-reference generator misses coding-agent driver env vars #6994/selfhost-env-reference generator misses POSTHOG_SERVER_NAME/POSTHOG_MIN_SEVERITY/POSTHOG_REPO_MIN_SEVERITY #8627's existing ENV_NAME_LITERAL_ARG_HELPERS mechanism from the new collectParamForwardingWrappers comment, since both solve overlapping 'name arrives via a parameter, not a literal' problems and a future reader benefits from seeing them connected explicitly.
  • The fixpoint loop in collectParamForwardingWrappers re-walks all candidates each outer iteration (O(n^2) worst case) — fine at this codebase's scale but worth a one-line comment noting the bound is small (few dozen functions per file) if that's the intended justification.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8651
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 329 registered-repo PR(s), 137 merged, 37 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 329 PR(s), 37 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds a generalized same-file wrapper-detection pass (collectParamForwardingWrappers/bodyForwardsParamAsEnvName/callForwardsParamAsName) to the generator, regenerates selfhost-env-reference.ts with all six required vars (QUEUE_STARTUP_JITTER_MS, QUEUE_RECOVERY_JITTER_MS, QUEUE_PROCESSING_TIMEOUT_MS, QUEUE_DEAD_LETTER_REVIVE_INTERVAL_MS, SCHEDULED_ENQUEUE_JITTER_MS, MAINTENANCE_ADMISSION_MA

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 329 PR(s), 37 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 16d0409 into JSONbored:main Jul 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(scripts): selfhost-env-reference generator misses same-file wrapper helpers like envDurationMs

1 participant