feat(agent): add remaining-spend helper and harden amount conversion - #228
Open
Olasunkanmi975 wants to merge 3 commits into
Open
feat(agent): add remaining-spend helper and harden amount conversion#228Olasunkanmi975 wants to merge 3 commits into
Olasunkanmi975 wants to merge 3 commits into
Conversation
…d comparator Previously a single malformed/non-numeric round entry in .keeper-store.json caused listRounds() ordering (which did BigInt() on the id) to throw, which the load path surfaced as a full corrupted-file backup that dropped every entry. - Drop individual malformed round entries on load instead of nuking the whole store (still warn, still back up on truly corrupted JSON). - Extract a shared compareRoundIds() numeric comparator so listRounds and callers (parseRoundIdSpec) order rounds consistently regardless of id type. Closes Sub-Rosa-Issue#194
Author
|
@karagozemin please kindly review and merge |
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.
Summary
Implements issue #193 for the autonomous agent service.
Remaining-spend helper
remainingAppraisalSpend(mandate, spentSoFarStroops?)which returns theremaining x402 appraisal budget in stroops and throws a
MandateCapErrorwhencumulative spend already exceeds the mandate cap. Exported from the package
entrypoint.
Hardened amount conversion
usdcToStroopsnow rejects non-finite (NaN/Infinity), negative andout-of-safe-range inputs with a clear
MandateErrorinstead of silentlyproducing junk via
BigInt(Math.round(...)).stroopsToUsdcnow requires abigint, rejects negative values, and splitsthe whole/fraction parts to avoid
Number(bigint)precision loss for largeescrow/bid amounts.
Test plan
services/agent/src/mandate.test.tswith cases for the hardenedconversions (NaN/Infinity/negative rejection, round-trip) and for
remainingAppraisalSpend(full budget, partial spend, over-cap and badinput).
pnpm test(13 passing) andpnpm typecheckfor@sub-rosa/agentare green.mandate-cap-negative.test.tsstill passes.closes #193