Add formal FSM for transaction lifecycle with decision points#25
Merged
Conversation
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
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.
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):TransactionStateenum: 8 states covering the full transaction lifecycle (Received, PolicyRequired, PartiallyAuthorized, ReadyToSettle, Settled, Rejected, Cancelled, Reverted)AgentStateenum: Per-agent authorization tracking (Pending, Authorized, Rejected, Removed)FsmEventenum: 10 event types representing incoming TAP messages (TransactionReceived, AuthorizeReceived, RejectReceived, etc.)Decisionenum: 3 decision types for external systems (AuthorizationRequired, PolicySatisfactionRequired, SettlementRequired)TransactionFsmengine: Pure-logic state machine withapply()method for processing eventsDecisionHandlertrait: Pluggable handler for decision points with built-in implementations (AutoApproveHandler, LogOnlyHandler)DecisionModeenum: Configuration for how decisions are handled (AutoApprove, EventBus, Custom)Updated StandardTransactionProcessor:
New event type (
NodeEvent::DecisionRequired):Configuration updates (
NodeConfig):decision_modefield to control FSM decision handling strategyImplementation Details
Decisiondescribing what must be resolvedTesting & Integration
https://claude.ai/code/session_01YBT8UQJ3Z4bcVoaZ8V8u82