feat: Circle experimental capsules — decimals & stale_quote - #5
Merged
Conversation
late_discover (reorder to think → discover → pay) is valid only when the think step does not consume the quote. Bench Exp D used a controlled think-as-sleep design that satisfied this constraint. Real-world agents typically have think that consumes the quote (e.g., 'is $X worth it?'). For those, options include: (a) split think into pre-quote selection and post-quote price-check (b) request longer quote TTL (c) refresh quote between think and pay Updated stale_quote seed-gene params and Scenario 5 console output to document all repair patterns.
This was referenced May 26, 2026
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.
Circle Experimental Capsules
Follow-up to #3. Adds 2 capsules whose q-values come from Helix's April 2026 Arc Testnet experiments, with end-to-end demo reproduction of both failure modes.
Why this PR
PR #3 (Circle Foundation) shipped 5 Circle capsules. Three were validated against live Circle Sandbox in the same PR. Two more capsules —
decimals-metadata-mismatchandstale_quote— had pre-existing experimental data fromscripts/circle-bench/but weren't integrated into helix-core. This PR closes that gap.decimals-metadata-mismatchoverride_api_decimalsstale_quoteobserve(advisory)What it ships
Type system (
types.ts)ErrorCode+=decimals-metadata-mismatch,stale_quoteFailureCategory+=infrastructure(token metadata bugs, native-vs-ERC-20 confusion)FailureClassification.chainoptional field (e.g.'arc-testnet','base-sepolia')Strategy implementation (
provider.ts)override_api_decimalsuses 3-priority resolution:decimals()ifcontext.publicClient+tokenAddressprovidedcontext.expected_decimalsThis handles Exp A's actual failure mode: Arc Testnet USDC is a native asset with no ERC-20 contract to query. Circle's API claims
decimals=18; the real atomic resolution is6. The repair must use ground-truth knowledge, not on-chain reads.Two-tier perceive detection (
circle/perceive.ts)Tier 1 — Caller-emit (explicit context):
decimals-metadata-mismatch: when caller provides bothexpected_decimalsandapi_reported_decimalsstale_quote: whencontext.stale_quote=trueORresponse.data.code === 'STALE_QUOTE'OR message matchTier 2 — Heuristic:
requested_amount / available_balance > 10^9, suspect a decimals bug rather than insufficient funds (18-vs-6 ratio is 10^12, so 10^9 catches it comfortably)Seed capsules (
seed-genes.ts)2 new entries with q-values from telemetry, not guesses. Both apply
apiLayer: 'wallets-api'for correct Gene Map lookup matching.Demo expansion (
examples/circle-e2e.ts)decimals=18for Arc USDC, sends0.001 × 10^12raw amount, Circle returns insufficient funds. Perceive heuristic catches the suspicious ratio, ground-truth table provides correct decimals=6, parameterModifier scales the amount, retry succeeds on real Arc Testnet.STALE_QUOTEerror matching x402 facilitator response shape. Perceive routes tostale_quotecapsule.observestrategy records the failure for caller's preflight; does not auto-fix. Console surfaces 3 repair options with their applicability conditions.Important caveat:
stale_quoterepair optionsThe bench Exp D demonstrated
think → discover → estimate → pay → verifyreorder yields 96% E2E. This reorder is only valid when thethinkstep does not consume the quote (Exp D's controlled think-as-sleep design satisfied this).Real-world agents typically have
thinkthat consumes the quote (e.g., "is $X worth my budget?"). For those, the repair options are:thinkis quote-independentthink— pre-quote selection + post-quote price-checkThis nuance is encoded in:
seed-genes.tsparams (machine-readable)864587dmessage (historical record)observestrategy is deliberate — Helix records the failure pattern and surfaces options; the caller's architecture decides which repair fits.Validation
Two full demo runs (LEARN then IMMUNE rerun), all 5 scenarios pass cleanly.
Capsule deltas across two demo runs
decimals-metadata-mismatchstale_quotewallets-api-rate-limitcircle-param-invalidcircle-insufficient-fundsgateway-rate-limitgateway-nonce-usedcctp-attestation-pendingAll exercised capsules show q-value rising. Untouched capsules unchanged.
tsc --noEmitcleanNotable findings during development
Arc Testnet USDC is a native asset, not ERC-20. Circle's SDK returns
{ isNative: true, decimals: 18 }with notokenAddress. Original Exp A repair worked by using ground-truth knowledge, not on-chain reads. Strategy now reflects this.stale_quoteis advisory. The actual workflow reorder is the agent's responsibility, not the engine's. Helix records the failure pattern viaobservestrategy; agents preflight Gene Map audit logs to decide on a repair option (see caveat section above).stale_quotepreserves underscore casing. Inconsistent with other ErrorCodes' hyphen convention, but matches the string already stored in bench audit logs and Cloudflare registry. Changing to hyphens would silently break cross-agent inheritance.Roadmap (out of scope here)
stale_quote— implement as a wrap-layer feature alongsideobservecapsule. Currently advisory only.Verification by reviewers
https://helix-telemetry.haimobai-adrian.workers.dev/v1/statsscripts/circle-bench/(Exp A through Exp D)