Skip to content

fix(engine): isolate getTenantConfig reads and normalize tenant config - #9621

Closed
kai392 wants to merge 1 commit into
JSONbored:mainfrom
kai392:fix/9614-tenant-config-isolation
Closed

fix(engine): isolate getTenantConfig reads and normalize tenant config#9621
kai392 wants to merge 1 commit into
JSONbored:mainfrom
kai392:fix/9614-tenant-config-isolation

Conversation

@kai392

@kai392 kai392 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #9614

What

packages/loopover-engine/src/tenant-config.ts promised full per-tenant isolation but had two gaps:

1. The read path leaked the stored object. getTenantConfig returned store[tenantId] ?? resolveTenantConfig() — only the miss path was a fresh copy. On a hit it handed back the stored object, and setTenantConfig's Object.freeze is shallow (nested preferences/allowedActionClasses weren't frozen), so a caller could mutate a read config and silently rewrite that tenant's stored autonomyLevel/allowedActionClasses.

Fix: getTenantConfig now returns a deep copy on both paths, and setTenantConfig deep-freezes the written entry (config, its preferences, and the action-class array).

2. maxConcurrentLoops was unnormalized. ?? let -5, 0.5, NaN, Infinity pass through verbatim. It now uses the exact finiteNonNegativeInt body from tenant-quota.ts:45-47 (the #5828 discipline shared by loop-consumption.ts/worktree-pool.ts), applied to an explicitly-supplied override only — an absent override still inherits DEFAULT_TENANT_CONFIG's 1. resolveTenantConfig also now drops non-string allowedActionClasses entries rather than copying them through, mirroring the existing autonomyLevel guard.

DEFAULT_TENANT_CONFIG, TENANT_AUTONOMY_LEVELS, EMPTY_TENANT_CONFIG_STORE, and every exported type are unchanged; getTenantConfig's JSDoc is corrected.

Tests

5 new cases in test/unit/tenant-config.test.ts: maxConcurrentLoops normalization (-5/0.5/NaN/Infinity→0, 3→3, absent→1), non-string action-class dropping, deep-copy-on-hit isolation, and deep-freeze of the stored entry. 100% branch + statement coverage on the changed code; verified non-vacuous (4/5 fail with the fix reverted). tsc --noEmit clean.

@kai392
kai392 requested a review from JSONbored as a code owner July 29, 2026 00:47
@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-29 00:50:59 UTC

2 files · 1 AI reviewer · no blockers · CI failing · unstable

🛑 Suggested Action - Fix Blockers

Review summary
The PR fixes two issues in tenant config handling: 1) `getTenantConfig` now returns deep copies on both hit/miss paths to prevent config mutation, and 2) `maxConcurrentLoops` is normalized to finite non-negative integers. The deep-copy logic uses a dedicated `cloneTenantConfig` function, and `setTenantConfig` deep-freezes all levels of the config object. The tests validate these changes with 100% coverage.

Nits — 2 non-blocking
  • The `finiteNonNegativeInt` helper could benefit from a JSDoc comment explaining its purpose and behavior for clarity.
  • Consider adding a test case for `allowedActionClasses` with mixed types (e.g., strings and numbers) to ensure non-string entries are consistently filtered.

CI checks failing

  • validate
  • changes

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 #9614
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 ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 100 registered-repo PR(s), 49 merged, 7 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 100 PR(s), 7 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The PR implements deep copies for both paths in getTenantConfig via cloneTenantConfig, deep-freezes all nested structures in setTenantConfig, and normalizes maxConcurrentLoops with the required finiteNonNegativeInt logic. All required tests and JSDoc updates are included.

Review context
  • Author: kai392
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is registered but has no active allocation in the current snapshot.
  • Public profile languages: not available
  • Official Gittensor activity: 100 PR(s), 7 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Await review-lane availability.
  • Then work through the remaining 2 steps in the Signals table above.
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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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.

Decision record
  • action: hold · clause: success
  • config: b047b4811327bffb67b602f4aa4bb1b8cf82681e889f77a16f448399ec6add41 · pack: oss-anti-slop · ci: failed
  • note: diverted by the randomized close-audit holdout (calibration: randomized ε-holdout on would-close PRs with propensity logging #8831) — the deterministic pipeline would otherwise have closed this PR
  • record: 175b3caec5e4ee1babc33d259283b901c8f31af6f58f2fe89eae3d25cc983456 (schema v5, head 24dad48)

🟩 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

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 29, 2026
@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 29, 2026
JSONbored#9614)

tenant-config.ts promised full per-tenant isolation but leaked the stored object and
skipped normalizing maxConcurrentLoops:

- getTenantConfig returned the very object held in the store on a hit (only the miss path
  was a fresh copy), and setTenantConfig's Object.freeze is shallow, so a caller could
  mutate preferences/allowedActionClasses and silently rewrite a tenant's stored config.
  Now getTenantConfig deep-copies on BOTH paths, and setTenantConfig deep-freezes the
  written entry (config, preferences, and the action-class array).
- resolveTenantConfig now normalizes an explicitly-supplied maxConcurrentLoops override
  with the exact finiteNonNegativeInt body used in tenant-quota.ts / loop-consumption.ts /
  worktree-pool.ts (JSONbored#5828) -- -5/0.5/NaN/Infinity no longer pass through; an absent override
  still inherits DEFAULT_TENANT_CONFIG's 1. It also drops non-string allowedActionClasses
  entries rather than copying them through, mirroring the existing autonomyLevel guard.
- Corrected getTenantConfig's JSDoc; DEFAULT_TENANT_CONFIG, TENANT_AUTONOMY_LEVELS,
  EMPTY_TENANT_CONFIG_STORE, and every exported type are unchanged.

Tests: 5 new cases (100% branch on the changed code, verified non-vacuous).

Closes JSONbored#9614
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kai392 kai392 closed this Jul 29, 2026
@loopover-orb loopover-orb Bot reopened this Jul 29, 2026
@loopover-orb loopover-orb Bot closed this Jul 29, 2026
@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LoopOver had already started reviewing this pull request — closing it to dodge the one-shot review process is not allowed. Please open a new pull request with the issues addressed.

@loopover-orb loopover-orb Bot added the review-evasion Gittensor contributor context label Jul 29, 2026
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. manual-review Gittensor contributor context review-evasion Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

engine(tenant-config): getTenantConfig hands out the store's live config object

2 participants