Skip to content

fix(contracts): enforce and document agent_vault exit paths (#865) - #909

Open
jeffrey-graham wants to merge 1 commit into
ExcelDsigN-tech:mainfrom
jeffrey-graham:fix/agent-vault-exit-paths
Open

jeffrey-graham wants to merge 1 commit into
ExcelDsigN-tech:mainfrom
jeffrey-graham:fix/agent-vault-exit-paths

Conversation

@jeffrey-graham

Copy link
Copy Markdown

Overview

Defines, documents, and enforces the agent_vault exit paths per AgentStatus (follow-up to #835):

  1. Suspended and Expired agents keep safe unwind/exit paths (burn_float, withdraw_collateral, and non-positive settle_net deltas delta <= 0) so customer cash-outs, end-of-day net-downs, and collateral recovery (withdraw_collateral + agent_registry::withdraw_bond once float == 0) are never trapped.
  2. Peer-to-peer float transfers (transfer_float / transfer_to_agent) require both from and to to be Active (VaultError::AgentNotFound otherwise).
  3. Pending and unregistered agents are rejected across all issuance and exit paths (VaultError::AgentNotFound) when a registry is configured.

Closes #865

Technical Implementation

  • contracts/agent_vault/src/lib.rs:
    • Added assert_agent_can_exit(env, agent) requiring AgentStatus::Active | AgentStatus::Suspended | AgentStatus::Expired when a registry is wired via set_registry.
    • Enforced assert_agent_active on from in transfer_float (alongside to).
    • Enforced assert_agent_can_exit on burn_float, withdraw_collateral, and non-positive settle_net entries (delta <= 0).
  • CONTRACTS.md:
    • Added ### Registry Status Gate & Exit Paths (Issues #788, #835, #865) documenting the rationale and per-status entry/exit matrix.
  • contracts/agent_vault/src/test.rs:
    • Extended MockRegistry with per-agent status overrides (set_agent_status) so two-agent calls can isolate sender vs. recipient statuses.
    • Added test_transfer_float_rejects_non_active_sender, test_burn_float_exit_paths_by_status, test_withdraw_collateral_exit_paths_by_status, and test_settle_net_negative_delta_exit_paths_by_status.

Test Coverage

  • cargo fmt --all -- --check: passed
  • cargo clippy -p agent_vault --all-targets -- -D warnings: 0 warnings
  • cargo test -p agent_vault -- --test-threads=1: 55 passed
  • WASM size (wasm32-unknown-unknown --release): agent_vault.wasm 41,937 bytes (< 256 KiB budget).

Checklists

Issue Definition of Done

  • Decision recorded on this issue
  • CONTRACTS.md documents the allowed exit paths per status
  • Contract enforces it, with a test per status and path
  • Clippy clean with -D warnings, every wasm under 256 KiB
  • All required CI checks pass

@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9a39806-bd92-46e8-bfb8-100c762ed21f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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.

Decide and document which agent_vault exit paths a non-Active agent keeps

1 participant