Skip to content

fix(byok): a reader's own key never touches the deployment's bookkeeping (1.18.0) - #77

Merged
catomean merged 1 commit into
mainfrom
fix/byok-links-claim-no-capacity
Sep 26, 2026
Merged

catomean merged 1 commit into
mainfrom
fix/byok-links-claim-no-capacity

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

Problem. byokChain links share their provider id with the deployment's own link to the same vendor (groq is groq), and every shared ledger in ai-kit keys on that id. So a reader's own key could:

  • cool the site's free link for everyone. createLinkCooldown.record on a reader's personal daily 429 cools groq/<model> until UTC midnight;
  • flip the site's AI health to degraded/down because one reader's key was bad or empty;
  • read as capacity. dailyTokens: Infinity makes any hand-rolled sum unlimited, and a *_DAILY_TOKENS override would be counted by dayCapacityTokens;
  • show up in the site's quota store as the site running dry.

Fix

  • Provider.byok, set by byokChain. The id is unchanged, because apps show and log it.
  • dayCapacityTokens skips byok providers.
  • createLinkCooldown.record ignores byok links.
  • tryChain / walkChain / completeStream record no health for them:
    • a success on an own-key link isn't recorded;
    • a failure is skipped when every link in the chain is own-key.
  • QuotaReading.byok: true on readings from own-key links.
  • dailyTokens: 0 instead of Infinity.
  • New exports: isOwnKeyLink, healthFor.

Exposure today: none. I checked loki, substrata, heidi, orangecat, evig and petvity; none feeds an own-key chain into capacity, and Loki skips telemetry on its own-model path. This closes the trap for the next app. After it ships, Heidi can drop its local dailyTokens: 0 pin (heidi#138).

Checked

  • pnpm run verify green (350 pass).
  • New test/byok-isolation.test.js (6 tests). Each guard was mutation-checked by removing it and rebuilding: capacity, cooldown, health, reading flag, and Infinity each turn a test red.

Minor bump to 1.18.0. It publishes when the v1.18.0 tag is pushed after merge.

🤖 Generated with Claude Code

…ing (1.18.0)

byokChain links share their provider id with the deployment's link to the same
vendor (groq is groq), and every shared ledger in this package keys on it. So:

- Provider.byok marks an own-key link (set by byokChain).
- dayCapacityTokens never counts it, even with a *_DAILY_TOKENS override.
- createLinkCooldown never cools a link because of it — one reader's
  exhausted personal quota used to cool groq/<model> for everybody.
- tryChain / walkChain / completeStream record no health for it: one reader's
  bad key says nothing about whether the site's AI works.
- Quota readings about it carry byok: true, so an app's store can skip them.
- dailyTokens is 0, not Infinity: a caller summing it by hand adds nothing.
- New exports: isOwnKeyLink(link), healthFor(chain, health).

No live app was exposed (checked loki, substrata, heidi, orangecat, evig,
petvity: none fed an own-key chain into capacity); this closes the trap for
the next one. Each guard mutation-checked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@catomean
catomean merged commit 102ab38 into main Sep 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant