Skip to content

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

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

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

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), applied to an explicitly-supplied override only — an absent override still inherits DEFAULT_TENANT_CONFIG's 1. resolveTenantConfig also drops non-string allowedActionClasses entries, 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, 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:54
@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 01:15:58 UTC

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

🛑 Suggested Action - Fix Blockers

Review summary
This PR fixes a real aliasing bug in getTenantConfig (hit path returned the stored object directly, allowing mutation of frozen-but-shallow nested collections) and adds normalization for maxConcurrentLoops plus filtering of non-string allowedActionClasses entries. The logic is correct and well-traced: cloneTenantConfig deep-copies on the hit path, setTenantConfig deep-freezes each level, and finiteNonNegativeInt matches the cited tenant-quota.ts precedent. Tests directly verify the mutation-isolation and freeze behavior with concrete before/after assertions, and the PR closes the linked issue #9614.

Nits — 5 non-blocking
  • codecov/patch shows only 51.16% of the diff is covered despite the PR claiming 100% branch/statement coverage on changed code — worth double-checking which lines codecov considers uncovered (e.g. the JSDoc-only reformatting or comment-only lines may be inflating the denominator, but verify).
  • tenant-config.ts:79-84 the `allowedActionClasses` filter silently drops non-string entries without any signal to the caller (e.g. a warning or count) — acceptable per the description but worth confirming that's the desired UX for malformed input.
  • The inline `engine(tenant-config): getTenantConfig hands out the store's live config object #9614:` comments are fairly verbose and duplicate what's already stated in JSDoc above them (e.g. tenant-config.ts:45-47 and the function docstring say nearly the same thing) — could be trimmed for conciseness.
  • Investigate the codecov/patch gap (51.16% vs claimed 100%) before merge, since the PR conventions in this repo (per the review guide) demand ~97% patch coverage on src/**.
  • Consider whether cloneTenantConfig (tenant-config.ts:104-113) and the object literal in resolveTenantConfig could share a small helper, since both duplicate the same preferences-shape copy — minor DRY opportunity, not blocking.

CI checks failing

  • codecov/patch — 51.16% of diff hit (target 99.00%)

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 · LLM: moderate
Linked issue satisfaction

Partially addressed
The core fixes are solid — getTenantConfig now deep-copies on both paths, setTenantConfig deep-freezes preferences/allowedActionClasses, and maxConcurrentLoops normalization plus allowedActionClasses filtering match the required finiteNonNegativeInt discipline — but two explicitly listed test deliverables are missing: a dedicated test for two successive getTenantConfig calls on a tenant with no st

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: Python, Cuda, JavaScript, Kotlin, Perl, Ruby, TypeScript, Vue
  • 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.

🟩 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.

JSONbored#9614)

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

- getTenantConfig now deep-copies on BOTH paths (the hit path previously returned the
  stored object; Object.freeze is shallow), and setTenantConfig deep-freezes the written
  entry (config, preferences, and the action-class array).
- resolveTenantConfig normalizes an explicitly-supplied maxConcurrentLoops override with
  the exact finiteNonNegativeInt body from tenant-quota.ts:45-47 (JSONbored#5828) -- absent override
  still inherits DEFAULT_TENANT_CONFIG's 1 -- and drops non-string allowedActionClasses
  entries, 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>
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.16279% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.00%. Comparing base (bd139a5) to head (9fac82e).

Files with missing lines Patch % Lines
packages/loopover-engine/src/tenant-config.ts 51.16% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9622      +/-   ##
==========================================
- Coverage   90.02%   90.00%   -0.02%     
==========================================
  Files         888      888              
  Lines      111983   112021      +38     
  Branches    26570    26571       +1     
==========================================
+ Hits       100810   100823      +13     
- Misses       9843     9864      +21     
- Partials     1330     1334       +4     
Flag Coverage Δ
backend 95.56% <100.00%> (-0.01%) ⬇️
engine 66.51% <23.25%> (-0.05%) ⬇️

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

Files with missing lines Coverage Δ
packages/loopover-engine/src/tenant-config.ts 71.90% <51.16%> (-12.44%) ⬇️

... and 1 file with indirect coverage changes

@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 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (CI is failing (codecov/patch)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

@loopover-orb loopover-orb Bot closed this 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.

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