Repository navigation
feat: x402 e2e test, structured LLM outputs, prompt-injection guard and shared LLM budgets (#64 #65 #70 #71) - #175
Merged
Levi-Ojukwu merged 3 commits intoOct 18, 2026
Conversation
The conflict resolution in 3ce175e dropped one side of several files: the LLM router wiring (completeLLM was imported but not exported), Prisma models for IPFS content / transparency reports / treasury ops, config keys, cron handlers (syntax errors) and trace-publication/audit schema. Re-do the merge of 7a8d096 and ced038e, keep both sides, and fix the few type errors that remained so the tree compiles again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ned traces (OracleDesk#64) - tests/x402-e2e.test.ts: real createTraceApi from the submodule, traces from generateReasoningTrace + pinAndPublishDocument, in-memory IPFS, stub facilitator, hermetic fetch guard (402, paid 200, tampered 502, unknown 404, settle failure). - tests/canonical-parity.test.ts: canonicalJson vs contracts canonicalize. - pinJson rejects non-plain objects (IPFS_NON_PLAIN_DOCUMENT). - npm scripts test:x402:prepare / test:e2e:x402, CI install + cache + step. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n budgets (OracleDesk#65, OracleDesk#70, OracleDesk#71) OracleDesk#65 Structured outputs - src/lib/llm-schema.ts: zod schemas as the single source; derived Anthropic tool input_schema and Gemini responseSchema (toGeminiSchema), postValidate. - callLLMStructured(): forced tool use / responseSchema, one repair round per provider, LLM_STRUCTURED_OUTPUT_FAILED; no fence stripping anywhere. - setAnthropicClient / setGeminiModelFactory seams, recorded response fixtures. OracleDesk#70 Prompt injection - llm-guard.service.ts: sanitiser, quarantine, nonce-delimited untrusted blocks, deterministic checkProposal (PROPOSAL_REJECTED_BY_GUARD). - Ingestion sanitises before caching; GDELT URLs move to url. - 28 attack + 18 benign corpus cases replayed through generateMarketQuestion. OracleDesk#71 Budgets and shared guards - llm-budget.ts + atomic Lua (token bucket, circuit breaker with half-open probe, daily token/cost budgets, admin reserve) in Redis; fail-open/closed. - Providers take a lease per attempt; usage read from Anthropic usage and Gemini usageMetadata; budget exhaustion logged once per day. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@TheCodingChef-eth Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #64, closes #65, closes #70, closes #71
Base repair (first commit)
developdoes not compile: 3ce175e (PR #172) was committed with a bad conflictresolution (schema syntax error, missing Prisma models and config keys,
completeLLMimported but not exported, syntax errors in the cron files). Thefirst commit redoes the merge of 7a8d096 and ced038e keeping both sides, plus
the few type fixes needed to compile. Please review it on its own.
closes Run the contracts x402 trace API in an end-to-end test against backend-published traces #64 x402 end-to-end
tests/x402-e2e.test.tsruns the submodule's realcreateTraceApiagainsttraces from
generateReasoningTrace+pinAndPublishDocument: 402 challenge,paid 200 (content equals the canonical payload), tampered 502, unknown 404,
and no content when settlement fails.
In-memory IPFS, in-process stub facilitator, and a fetch guard that fails the
test on any non-loopback request.
tests/canonical-parity.test.tscomparescanonicalJsonwith the contractscanonicalizeover an edge-case corpus;pinJsonnow rejects non-plainobjects (
IPFS_NON_PLAIN_DOCUMENT) becauseDatediverges (ISO vs{}).npm run test:x402:prepareandnpm run test:e2e:x402; CI installs andcaches the x402 deps. Skips locally with guidance, fails when
CI=true.closes Use provider-native structured outputs generated from the zod proposal schemas #65 Structured outputs
src/lib/llm-schema.tsis the single schema registry (zod, Anthropic toolschema, Gemini
responseSchema,postValidate).callLLMStructured(): Anthropic forced tool use, GeminiresponseSchema, onerepair round per provider,
LLM_STRUCTURED_OUTPUT_FAILED. Fence stripping isgone from
llm.ts,gemini.tsandmarket.service.ts.generateMarketQuestion/generateHedgeConditionsmigrated; seamssetAnthropicClient/setGeminiModelFactory; fixtures intests/fixtures/llm/.closes Defend market generation against prompt injection in ingested signals #70 Prompt injection
llm-guard.service.ts: sanitiser (NFKC, control/zero-width/bidi, caps, URLsmoved to
url), quarantine, nonce-delimited untrusted blocks,checkProposal(grounding, probability, expiry, oracle allowlist, content policy).
All fetchers sanitise before caching; GDELT URL is stored in
url.Rejections/quarantines go to
agent_logswith reason codes and hashes only.Corpus: 28 attack + 18 benign cases in
tests/fixtures/injection/.closes Enforce LLM token budgets and a shared circuit breaker across instances #71 Budgets and shared breaker
llm-budget.ts+ atomic Lua: per-provider token bucket, circuit breaker withhalf-open probe, daily token/cost budgets with an admin reserve, reservations
released on error/missing usage, crashed leases reclaimed.
Usage read from Anthropic
usageand GeminiusageMetadata; cron stops atbudget minus reserve, admin runs to the full budget;
LLM_BUDGET_EXCEEDEDlogged once per day.
LLM_REDIS_FAIL_MODE=closed|open.Same scenario table runs against the JS reference store and real Redis.
Notes
.env.exampleanddocs/architecture.md.npm testhas 15 failures that also fail on the repaired base (request-idtests, copy-trade/reconcile, some resilience tests, DB-dependent tests).