Skip to content

Comments

Add formal FSM for transaction lifecycle with decision points#25

Merged
pelle merged 3 commits intomainfrom
claude/analyze-tap-node-D5Es2
Feb 20, 2026
Merged

Add formal FSM for transaction lifecycle with decision points#25
pelle merged 3 commits intomainfrom
claude/analyze-tap-node-D5Es2

Conversation

@pelle
Copy link
Contributor

@pelle pelle commented Feb 20, 2026

Summary

This PR introduces a formal Finite State Machine (FSM) for managing TAP transaction lifecycles, replacing ad-hoc state handling with explicit states, transitions, and decision points. The FSM models the complete transaction journey from initiation through authorization to settlement, with clear separation between automatic transitions and decisions requiring external input.

Key Changes

  • New FSM module (tap-node/src/state_machine/fsm.rs):

    • TransactionState enum: 8 states covering the full transaction lifecycle (Received, PolicyRequired, PartiallyAuthorized, ReadyToSettle, Settled, Rejected, Cancelled, Reverted)
    • AgentState enum: Per-agent authorization tracking (Pending, Authorized, Rejected, Removed)
    • FsmEvent enum: 10 event types representing incoming TAP messages (TransactionReceived, AuthorizeReceived, RejectReceived, etc.)
    • Decision enum: 3 decision types for external systems (AuthorizationRequired, PolicySatisfactionRequired, SettlementRequired)
    • TransactionFsm engine: Pure-logic state machine with apply() method for processing events
    • DecisionHandler trait: Pluggable handler for decision points with built-in implementations (AutoApproveHandler, LogOnlyHandler)
    • DecisionMode enum: Configuration for how decisions are handled (AutoApprove, EventBus, Custom)
  • Updated StandardTransactionProcessor:

    • Integrated FSM context management with in-memory DashMap storage
    • Converts incoming TAP messages to FsmEvents
    • Routes events through the FSM and delegates decisions to configured handler
    • Maintains backward compatibility with auto-approval mode (default behavior)
    • Supports event-bus mode for external decision handling
  • New event type (NodeEvent::DecisionRequired):

    • Published when FSM reaches decision points in EventBus mode
    • Includes transaction ID, current state, decision details, and pending agents
    • Enables external systems to subscribe and respond
  • Configuration updates (NodeConfig):

    • Added decision_mode field to control FSM decision handling strategy

Implementation Details

  • The FSM is pure logic with no I/O — all state changes are in-memory and must be persisted by the caller
  • Per-agent tracking: Transactions track individual agent authorization status while maintaining a single top-level transaction state
  • Decision points: Three states require external decisions (Received, PolicyRequired, ReadyToSettle); the FSM returns a Decision describing what must be resolved
  • Policy handling: Supports policy exchange flow where counterparties can request presentations before authorizing
  • Agent management: Supports dynamic agent addition/removal (TAIP-5) with automatic state adjustments
  • Terminal states: Rejected, Cancelled, and Reverted states accept no further events
  • Backward compatible: Default AutoApprove mode preserves existing behavior of auto-authorizing registered agents and auto-settling

Testing & Integration

  • Updated integration tests to use new FSM infrastructure
  • Stress test updated with default decision_mode configuration
  • Event logger updated to handle DecisionRequired events

https://claude.ai/code/session_01YBT8UQJ3Z4bcVoaZ8V8u82

claude and others added 3 commits February 19, 2026 07:31
Introduce a pure-logic finite state machine (TransactionFsm) that models
the complete TAP transaction lifecycle with 8 states, 10 event types, and
3 explicit decision points where external systems must intervene.

States: Received → PolicyRequired → PartiallyAuthorized → ReadyToSettle
        → Settled (terminal: Rejected, Cancelled, Reverted)

Decision points:
- AuthorizationRequired: new transaction needs authorize/reject/policy
- PolicySatisfactionRequired: counterparty policies need data
- SettlementRequired: all agents authorized, originator must settle

Includes 17 unit tests covering happy path, multi-agent, policy exchange,
agent management, rejection, cancellation, revert, and edge cases.

https://claude.ai/code/session_01YBT8UQJ3Z4bcVoaZ8V8u82
…gurable DecisionMode

Integrate the transaction FSM into the actual message processing pipeline
with three configurable modes via NodeConfig::decision_mode:

- AutoApprove: preserves existing behavior (auto-authorize registered
  agents, auto-settle when all authorize). Default.
- EventBus: publishes NodeEvent::DecisionRequired for external systems.
  No automatic action — compliance engines, UIs, or business rules
  must subscribe and respond.
- Custom(handler): caller provides a DecisionHandler implementation
  for full control over authorization and settlement decisions.

Changes:
- Add DecisionHandler trait, AutoApproveHandler, LogOnlyHandler to fsm.rs
- Add DecisionMode enum (AutoApprove | EventBus | Custom)
- Add NodeEvent::DecisionRequired variant with EventBus publish helper
- Refactor StandardTransactionProcessor to run FSM on every message,
  track per-transaction TransactionContext in DashMap, and delegate
  decisions to the configured handler
- Add decision_mode field to NodeConfig
- Update EventLogger to handle DecisionRequired events
- Update all tests and benchmarks for new constructor signature

https://claude.ai/code/session_01YBT8UQJ3Z4bcVoaZ8V8u82
@pelle pelle merged commit a1b35ae into main Feb 20, 2026
3 checks passed
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.

2 participants