Skip to content

fix(ai-summaries): resolve the shared daily neuron budget like the AI review path (10M)#1455

Open
joaovictor91123 wants to merge 2 commits into
JSONbored:mainfrom
joaovictor91123:fix/ai-summaries-shared-neuron-budget
Open

fix(ai-summaries): resolve the shared daily neuron budget like the AI review path (10M)#1455
joaovictor91123 wants to merge 2 commits into
JSONbored:mainfrom
joaovictor91123:fix/ai-summaries-shared-neuron-budget

Conversation

@joaovictor91123

Copy link
Copy Markdown
Contributor

Summary

Fixes #1454. summarizeAgentBundleWithAi and rewriteSignalBundleWithAi (src/services/ai-summaries.ts) resolved AI_DAILY_NEURON_BUDGET with a 10000 default and 1_000_000 ceiling, while the two sibling Workers-AI features that draw on the same shared daily counter (sumAiEstimatedNeuronsSince) use a 10_000_000 default and ceiling:

// src/services/ai-review.ts:577-578 and src/services/ai-slop.ts:196-197 (the latter shipped as merged #1369)
const rawNeuronBudget = Number(env.AI_DAILY_NEURON_BUDGET);
const budget = clampNumber(env.AI_DAILY_NEURON_BUDGET && Number.isFinite(rawNeuronBudget) ? rawNeuronBudget : 10_000_000, 0, 10_000_000);

Because all three features sum into one shared daily total, summaries were starved into quota_exceeded once shared usage crossed 10k neurons (a tiny fraction of the real 10M budget), and a configured budget was capped at 1M. This applies the same resolution at both summary sites. The fix was applied to ai-slop in #1369 but never to ai-summaries.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; both changed const budget lines have both sides of the new &&/ternary covered (unset→default, finite→raw, non-finite→default) for both the summarize and rewrite paths, with regression tests that fail before the fix.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • Ran the full npm run test:ci gate locally; all checks green.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

Backend service-logic change with no UI/API surface impact, so the UI Evidence section is omitted.

Notes

… review path (10M)

summarizeAgentBundleWithAi and rewriteSignalBundleWithAi resolved AI_DAILY_NEURON_BUDGET with a 10k default and a 1M ceiling, while ai-review.ts and ai-slop.ts (JSONbored#1369) resolve the SAME shared daily counter to a 10M default and 10M ceiling. Because all three Workers-AI features sum into one sumAiEstimatedNeuronsSince total, summaries were starved into quota_exceeded once shared usage crossed 10k neurons — a tiny fraction of the real budget — and a configured budget was capped at 1M. Mirror the sibling resolution (default 10M, finite-check, clamp to 10M) at both sites and add regression tests pinning the high default, the raised ceiling, and the invalid-to-default fallback for both the summarize and rewrite paths.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 26, 2026
@superagent-security

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.37%. Comparing base (b5d575e) to head (b580f55).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1455      +/-   ##
==========================================
- Coverage   95.37%   95.37%   -0.01%     
==========================================
  Files         199      199              
  Lines       21546    21548       +2     
  Branches     7791     7791              
==========================================
+ Hits        20550    20551       +1     
  Misses        416      416              
- Partials      580      581       +1     
Files with missing lines Coverage Δ
src/services/ai-summaries.ts 99.13% <100.00%> (-0.87%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored added the gittensor:bug Gittensor-scored bug fix - worth 0.5x multiplier. label Jun 26, 2026
@gittensory-orb

gittensory-orb Bot commented Jun 27, 2026

Copy link
Copy Markdown

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review — blocked

2 files · 1 AI reviewers · no blockers · readiness 55/100 · CI failing · blocked

🛑 Blocked

Review summary
This is a targeted two-site bug fix that aligns `AI_DAILY_NEURON_BUDGET` resolution in `summarizeAgentBundleWithAi` and `rewriteSignalBundleWithAi` with the already-proven pattern from `ai-review.ts` and `ai-slop.ts`. The old `|| 10000` / `1_000_000` ceiling starved the shared counter at 10k and hard-capped configured budgets at 1M; the new `&& Number.isFinite` / `10_000_000` pattern is logically correct for every input class (unset → 10M, valid number → raw clamped to 10M, truthy-but-non-finite → 10M). The test changes accurately invert the old regression assertion and add coverage for default-HIGH and ceiling-raised scenarios on both the summarize and rewrite paths.

CI checks failing

  • validate
  • lint
Signal Result Evidence
Code review ✅ No blockers 1 reviewers, synthesized
Linked issue ✅ Linked #1454
Related work ⚠️ 2 scoped overlaps Top overlaps are listed below; lower-confidence bulk is hidden.
Review load ❌ 8/20 Readiness component derived from cached public PR metadata and labels; size label size:S.
Validation evidence ❌ 5/25 Cached preflight status is hold.
Open PR queue ❌ 3/10 20 open PR(s), 9 likely reviewable, 11 unlinked.
Contributor context ✅ Confirmed Gittensor contributor joaovictor91123; Gittensor profile; 23 PR(s), 0 issue(s).
Gate result ✅ Passing No configured blocker found.
Nits — 5 non-blocking
  • The 5-line comment block explaining the budget change is copy-pasted verbatim into both functions (ai-summaries.ts ~L38 and ~L284); a private `resolveSharedNeuronBudget(env: Env): number` helper would eliminate the duplication and keep both sites in sync — matching how `clampNumber` and `utcDayStartIso` are already extracted in the same file.
  • Both new `it()` blocks in ai-summaries.test.ts pack two independent scenarios (default-HIGH and ceiling-raised) into a single test body; when one assertion fails the failure message implicates both scenarios, making triage slower — splitting into separate named `it()` calls would self-describe failures.
  • Extract a shared `resolveSharedNeuronBudget(env: Env): number` helper in ai-summaries.ts so the `rawNeuronBudget` / `clampNumber` expression and its explanatory comment live once — callers at ~L38 and ~L284 become a single readable line and future sync with ai-review.ts / ai-slop.ts is less error-prone.
  • Split the multi-scenario `it()` blocks in the test file into individually named cases (e.g., 'uses 10M default when budget is unset', 'honors configured budget above the old 1M ceiling') so a failing assertion immediately identifies which invariant broke.
  • Repository config was not parsed
Review context
Contributor next steps
  • Review top overlaps.
  • Add scope summary.
  • Fix blocker.
  • Expect slower review.
  • Refresh registry data or choose a registered active repo.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Review load = cached public PR metadata such as size labels, changed paths, and preflight status.
  • Open PR queue = repo-wide review pressure; it is not a PR quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
Review details

Generated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative.

This is a targeted two-site bug fix that aligns `AI_DAILY_NEURON_BUDGET` resolution in `summarizeAgentBundleWithAi` and `rewriteSignalBundleWithAi` with the already-proven pattern from `ai-review.ts` and `ai-slop.ts`. The old `|| 10000` / `1_000_000` ceiling starved the shared counter at 10k and hard-capped configured budgets at 1M; the new `&& Number.isFinite` / `10_000_000` pattern is logically correct for every input class (unset → 10M, valid number → raw clamped to 10M, truthy-but-non-finite → 10M). The test changes accurately invert the old regression assertion and add coverage for default-HIGH and ceiling-raised scenarios on both the summarize and rewrite paths.

Nits (4)

  • The 5-line comment block explaining the budget change is copy-pasted verbatim into both functions (ai-summaries.ts ~L38 and ~L284); a private `resolveSharedNeuronBudget(env: Env): number` helper would eliminate the duplication and keep both sites in sync — matching how `clampNumber` and `utcDayStartIso` are already extracted in the same file.
  • Both new `it()` blocks in ai-summaries.test.ts pack two independent scenarios (default-HIGH and ceiling-raised) into a single test body; when one assertion fails the failure message implicates both scenarios, making triage slower — splitting into separate named `it()` calls would self-describe failures.
  • Extract a shared `resolveSharedNeuronBudget(env: Env): number` helper in ai-summaries.ts so the `rawNeuronBudget` / `clampNumber` expression and its explanatory comment live once — callers at ~L38 and ~L284 become a single readable line and future sync with ai-review.ts / ai-slop.ts is less error-prone.
  • Split the multi-scenario `it()` blocks in the test file into individually named cases (e.g., 'uses 10M default when budget is unset', 'honors configured budget above the old 1M ceiling') so a failing assertion immediately identifies which invariant broke.

🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@gittensory-orb gittensory-orb Bot added the gittensor Gittensor contributor context label Jun 27, 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 - worth 0.5x multiplier. gittensor Gittensor contributor context size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AI summaries resolve the shared daily neuron budget with the wrong default (10k) and ceiling (1M)

2 participants