Skip to content

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

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
joaovictor91123:fix/ai-summaries-shared-neuron-budget
Jun 28, 2026
Merged

fix(ai-summaries): resolve the shared daily neuron budget like the AI review path (10M)#1455
JSONbored merged 3 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 label Jun 26, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

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.52%. Comparing base (59492e6) to head (1140c0b).
⚠️ Report is 27 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1455      +/-   ##
==========================================
- Coverage   95.53%   95.52%   -0.01%     
==========================================
  Files         204      204              
  Lines       22090    22092       +2     
  Branches     7975     7975              
==========================================
+ Hits        21103    21104       +1     
  Misses        412      412              
- Partials      575      576       +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 — scores a 0.05x multiplier. label Jun 26, 2026
@loopover-orb

loopover-orb Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review — held for maintainer review

2 files · 1 AI reviewers · no blockers · readiness 55/100 · CI green · clean

⏸️ Held for maintainer review — Touches a guarded path — held for manual review

Review summary
This PR correctly ports the `AI_DAILY_NEURON_BUDGET` resolution pattern from `ai-review.ts`/`ai-slop.ts` to both functions in `ai-summaries.ts`, fixing a real starvation bug where shared counter usage above 10k triggered `quota_exceeded` — a tiny fraction of the real 10M shared budget. The new two-liner is a faithful, character-for-character copy of the sibling pattern and handles all edge cases correctly: unset, empty, and non-finite inputs default to 10M; a finite configured value is used and clamped to 10M. Regression tests pre-populate the shared `sumAiEstimatedNeuronsSince` counter to drive the real code path rather than manufacturing an unreachable state, which is the right approach here.

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 34 open PR(s), 17 likely reviewable, 17 unlinked.
Contributor context ✅ Confirmed Gittensor contributor joaovictor91123; Gittensor profile; 23 PR(s), 0 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Nits — 6 non-blocking
  • The budget resolution two-liner (`rawNeuronBudget` + `budget`) is now duplicated four times across three files (`ai-summaries.ts` ×2, `ai-review.ts`, `ai-slop.ts`); a shared `resolveSharedNeuronBudget(env: Env): number` helper (e.g. `src/lib/ai-budget.ts`) would prevent any one copy from drifting again — this divergence is exactly what caused the present bug.
  • The two identical multi-line block comments at `ai-summaries.ts:37-40` and `ai-summaries.ts:283-286` restate what the PR description already covers well; a single-line cross-reference per site (`// mirrors ai-review.ts / ai-slop.ts — see fix(ai-slop): resolve the shared neuron budget like the AI review path (10M) #1369`) would be less noise without losing traceability.
  • The 'resolves the SHARED neuron budget' `it` in `ai-summaries.test.ts` bundles two independent scenarios (default-HIGH with 2M pre-used; ceiling-raised with 1.5M pre-used) into one body — splitting them gives cleaner failure messages and independent setup if either assertion changes.
  • The rewrite-path invalid-budget assertion (`expect(...status).toBe('ok')`) in the new rewrite regression test relies on `publicEnv` having `AI_PUBLIC_COMMENTS_ENABLED` set to a truthy value — if it doesn't, the function short-circuits to `{ status: 'disabled' }` before reaching the budget check, making the assertion vacuously true for the wrong reason; confirm `publicEnv` wires that flag.
  • Extract the shared budget resolution to a single `resolveSharedNeuronBudget(env: Env): number` helper and import it in all three callers — the four-copy spread is the exact shape of the original divergence that produced this bug, and a helper makes the next audit trivial.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.
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 PR correctly ports the `AI_DAILY_NEURON_BUDGET` resolution pattern from `ai-review.ts`/`ai-slop.ts` to both functions in `ai-summaries.ts`, fixing a real starvation bug where shared counter usage above 10k triggered `quota_exceeded` — a tiny fraction of the real 10M shared budget. The new two-liner is a faithful, character-for-character copy of the sibling pattern and handles all edge cases correctly: unset, empty, and non-finite inputs default to 10M; a finite configured value is used and clamped to 10M. Regression tests pre-populate the shared `sumAiEstimatedNeuronsSince` counter to drive the real code path rather than manufacturing an unreachable state, which is the right approach here.

Nits (5)

  • The budget resolution two-liner (`rawNeuronBudget` + `budget`) is now duplicated four times across three files (`ai-summaries.ts` ×2, `ai-review.ts`, `ai-slop.ts`); a shared `resolveSharedNeuronBudget(env: Env): number` helper (e.g. `src/lib/ai-budget.ts`) would prevent any one copy from drifting again — this divergence is exactly what caused the present bug.
  • The two identical multi-line block comments at `ai-summaries.ts:37-40` and `ai-summaries.ts:283-286` restate what the PR description already covers well; a single-line cross-reference per site (`// mirrors ai-review.ts / ai-slop.ts — see fix(ai-slop): resolve the shared neuron budget like the AI review path (10M) #1369`) would be less noise without losing traceability.
  • The 'resolves the SHARED neuron budget' `it` in `ai-summaries.test.ts` bundles two independent scenarios (default-HIGH with 2M pre-used; ceiling-raised with 1.5M pre-used) into one body — splitting them gives cleaner failure messages and independent setup if either assertion changes.
  • The rewrite-path invalid-budget assertion (`expect(...status).toBe('ok')`) in the new rewrite regression test relies on `publicEnv` having `AI_PUBLIC_COMMENTS_ENABLED` set to a truthy value — if it doesn't, the function short-circuits to `{ status: 'disabled' }` before reaching the budget check, making the assertion vacuously true for the wrong reason; confirm `publicEnv` wires that flag.
  • Extract the shared budget resolution to a single `resolveSharedNeuronBudget(env: Env): number` helper and import it in all three callers — the four-copy spread is the exact shape of the original divergence that produced this bug, and a helper makes the next audit trivial.

🟩 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

@dosubot dosubot Bot added the lgtm label Jun 28, 2026
@JSONbored
JSONbored merged commit 7ddaaf0 into JSONbored:main Jun 28, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in gittensory - v1 roadmap Jun 28, 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

No open projects
Status: Done

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)

3 participants