Repository navigation
fix(inbox): keep the cap booking on a paid but unusable reply, and enforce the default cap at run time (#455) - #457
Closed
secret-mars wants to merge 1 commit into
Conversation
…force the default cap at run time (aibtcdev#455) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes items 1 and 5 of #455. Items 2, 3, 4 and 6 are left for separate PRs, because each one changes ledger or dry-run behaviour and deserves its own review.
1. A paid inference with an unusable body is no longer refunded to the daily cap.
In
marketplaceReplyGenerator, the three failures after payment (a non-JSON body, nochoices[0].message.content, an empty reply aftercleanReply) threw a plainError.paymentWasSent()only recognisesPaidRequestError, sorunAutoReplycalledreleaseDailySatsfor sats that had actually been spent. They now throwPaidRequestErrorwhenresult.paid, and stay a plainErroron the unpaid path.Scope note: this makes the cap count the spend. It does not stop the message from being retried and paid for again on the next run. That is item 3 of #455 (no per-message give-up state), and it is unchanged here.
5. The run-time cap no longer silently disappears when the config has no
dailyCapSats.readAppConfigis an unvalidated JSON cast, and the default was applied only inauto-reply-config. With the key missing,spent + sats > undefinedis alwaysfalse, so no cap applied. The newresolveDailyCapSats()keeps a stored non-negative safe integer (including0) and otherwise falls back toDEFAULT_DAILY_CAP_SATS.runAutoReplyapplies it, so any caller is covered, andinbox.tsuses it for both the run and the printeddailyCapSats.Tests (
bun test src/lib/services/inbox-auto-reply.service.test.ts: 22 pass;tsc --noEmitclean):marketplaceReplyGeneratoragainst the existing sponsored-payment fixture serves a paid 200 with each of the three unusable bodies, and expectsPaidRequestErroreach time.serveEndpointgained an optional URL so it can serveINFERENCE_GATEWAY.resolveDailyCapSatskeeps250and0, and falls back forundefined,null,"500",-1,1.5andNaN.The same shape exists in the aibtc-mcp-server port:
src/services/inbox-auto-reply.service.ts:293-297throws a plainErrorafter a paid response. It is not changed here, since the ledgers are shared but the code is separate.No upstream doc covers this; it is the repo's own spend logic. The checks use
Number.isSafeInteger(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).🤖 Generated with Claude Code