Skip to content

feat: add fail-closed pre-fund policy hook - #39

Open
AgentTanuki wants to merge 10 commits into
Virtual-Protocol:mainfrom
AgentTanuki:codex/pre-fund-policy-hook
Open

feat: add fail-closed pre-fund policy hook#39
AgentTanuki wants to merge 10 commits into
Virtual-Protocol:mainfrom
AgentTanuki:codex/pre-fund-policy-hook

Conversation

@AgentTanuki

@AgentTanuki AgentTanuki commented Aug 7, 2026

Copy link
Copy Markdown

Why

session.fund() currently prepares a transaction without an optional counterparty/policy decision point. Wallet agents need a last-mile gate on the exact provider, chain, amount, and hydrated job.

What

  • adds optional fundPolicy to AcpAgent.create
  • evaluates it before every funding branch prepares a transaction
  • requires explicit { allow: true }
  • returns typed FundPolicyDeniedError with machine-readable evidence
  • preserves current behavior when no policy is configured
  • documents the hook and exports the types

Validation

  • TypeScript build passes
  • Node tests cover explicit allow, denial, missing decision, verifier error, and no-policy compatibility (4/4)

AI disclosure: implemented with significant Codex assistance and independently reviewed against the transaction ordering and compiled/tested locally.


Note

Medium Risk
Touches the on-chain funding gate for all session.fund() paths; mistakes could block legitimate funds or use stale job data, though behavior is unchanged when no policy is set and snapshot pinning mitigates async races.

Overview
Adds an optional fundPolicy on AcpAgent.create so wallet agents can approve or block funding using the exact provider, chain, amount, and hydrated AcpJob before any fund transaction is prepared.

session.fund() now calls enforceFundPolicy first (fail-closed: only { allow: true } proceeds; denial, missing decision, or thrown errors abort with FundPolicyDeniedError). Funding branches use a fixed job snapshot taken at the start of fund() so a slow policy or concurrent fetchJob() cannot change the job the policy saw. Omitting fundPolicy leaves prior behavior unchanged.

New src/core/fundPolicy.ts types and helper are exported from the package; README documents the hook. npm test runs compile plus Node tests for allow/deny, missing decision, errors, and snapshot stability.

Reviewed by Cursor Bugbot for commit cbaf094. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/jobSession.ts
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