Commit f9221ad7 authored by Shouib's avatar Shouib

docs: specify fault simulator extension (request loss, crash before execution)

parent 1105ec4a
# Specification Quality Checklist: Fault Simulator Extension
**Purpose**: Validate specification completeness and quality before proceeding to planning
**Created**: 2026-11-03
**Feature**: [spec.md](/mnt/c/Users/Shouib/IdeaProjects/banking-sdd/specs/003-fault-simulator/spec.md)
## Content Quality
- [x] No implementation details (languages, frameworks, APIs)
- [x] Focused on user value and business needs
- [x] Written for non-technical stakeholders
- [x] All mandatory sections completed
## Requirement Completeness
- [x] No [NEEDS CLARIFICATION] markers remain
- [x] Requirements are testable and unambiguous
- [x] Success criteria are measurable
- [x] Success criteria are technology-agnostic (no implementation details)
- [x] All acceptance scenarios are defined
- [x] Edge cases are identified
- [x] Scope is clearly bounded
- [x] Dependencies and assumptions identified
## Feature Readiness
- [x] All functional requirements have clear acceptance criteria
- [x] User scenarios cover primary flows
- [x] Feature meets measurable outcomes defined in Success Criteria
- [x] No implementation details leak into specification
## Notes
- All items pass. The spec is ready for planning.
# Feature Specification: Fault Simulator Extension
**Feature Branch**: `003-fault-simulator`
**Created**: 2026-11-03
**Status**: Draft
**Input**: User description: "Extend the banking system with a fault simulator for the two
missing cases from FR-019:
(1) Request delivery failure: the request is lost before the server starts any
processing. No balance or ledger change occurs. The client retries with the
same sequence key and the withdrawal executes exactly once.
(2) Server crash before execution: the server stops after receiving the request
but before any commit. No partial state remains (no deduction, no sequence
key update, no ledger row). After restart and retry, the request executes as
if it were new.
Requirements: faults must be configurable per request (not a global static flag),
with a configurable injection count (inject once, then behave normally).
Include acceptance criteria per case, including: final balance = initial balance
minus the sum of unique successful withdrawals. Do not mention implementation details."
## Clarifications
### Session 2026-11-03
- Q: How should the "injection count" be tracked across server restarts for the "Server Crash Before Execution" case? → A: The client tracks the attempt and sends the fault configuration in a per-request header.
## User Scenarios & Testing *(mandatory)*
### User Story 1 - Request Delivery Failure Simulation (Priority: P1)
A tester simulates a network failure where a withdrawal request is lost before it reaches the server's processing logic. The tester verifies that no funds are moved and that a subsequent retry with the same transaction identity results in a single successful withdrawal.
**Why this priority**: Validates the system's resilience to "lost requests," ensuring that retries don't result in duplicate transactions and that the system remains consistent when the server never sees the request.
**Independent Test**: Can be fully tested by triggering a "request-loss" fault for a specific transaction and verifying that the account balance remains unchanged until the retry is performed.
**Acceptance Scenarios**:
1. **Given** an account with $100, **When** a withdrawal for $20 is submitted with a "request-loss" fault configured, **Then** the server does not process the request, no balance is deducted, and no ledger entry is created.
2. **Given** the previous state, **When** the user retries the same withdrawal ($20, same sequence key), **Then** the transaction executes successfully, the balance becomes $80, and exactly one ledger entry is created.
3. **Given** a series of withdrawals where some are lost, **When** all are eventually retried and completed, **Then** the final balance equals the initial balance minus the sum of unique successful withdrawals.
---
### User Story 2 - Server Crash Before Execution Simulation (Priority: P1)
A tester simulates a server crash that occurs after the server has received the request but before it has committed any changes to the database. The tester verifies that no partial state (balance change or ledger entry) persists after the crash, and that a retry after server restart allows the transaction to proceed as a new request.
**Why this priority**: Validates the "all-or-nothing" atomic property of transactions in the face of catastrophic process failure. It ensures that if a crash happens before the commit, the system doesn't end up in a corrupted "half-processed" state.
**Independent Test**: Can be fully tested by triggering a "crash-before-commit" fault for a specific transaction, restarting the server, and verifying the state.
**Acceptance Scenarios**:
1. **Given** an account with $100, **When** a withdrawal for $20 is submitted with a "crash-before-commit" fault configured, **Then** the server terminates, and no balance deduction or ledger entry is persisted.
2. **Given** the server has restarted, **When** the user retries the same withdrawal ($20, same sequence key), **Then** the transaction executes successfully, the balance becomes $80, and exactly one ledger entry is created.
3. **Given** a series of withdrawals with interleaved crashes, **When** all are eventually retried and completed, **Then** the final balance equals the initial balance minus the sum of unique successful withdrawals.
### Edge Cases
- **Fault Overlap**: What happens if a request is configured for both a request-loss and a server-crash? The system should prioritize the first fault in the request lifecycle (request-loss).
- **Injection Count Exhaustion**: What happens when the `injectionCount` reaches zero? The system must transition immediately to normal behavior for all subsequent requests.
- **Invalid Fault Configuration**: How does the system handle a request that specifies a fault type not recognized by the simulator? The system should ignore the unknown fault and process the request normally.
## Requirements *(mandatory)*
### Functional Requirements
- **FR-001**: The system MUST allow faults to be configured on a per-request basis rather than using a global state.
- **FR-002**: The system MUST support a configurable `injectionCount` for each fault, specifying how many times the fault should be triggered before the system returns to normal behavior for that specific transaction identity.
- **FR-003**: The system MUST simulate a "Request Delivery Failure" where the request is discarded before any processing begins, ensuring no state changes occur.
- **FR-004**: The system MUST simulate a "Server Crash Before Execution" where the process terminates after receiving the request but before any database commit occurs, ensuring no partial state is persisted.
- **FR-005**: The system MUST ensure that after a "Request Delivery Failure" or "Server Crash Before Execution," a retry with the same sequence key results in exactly one successful execution of the withdrawal.
- **FR-006**: The system MUST maintain the invariant: `Final Balance = Initial Balance - Sum(Unique Successful Withdrawals)`.
### Key Entities
- **FaultConfiguration**: A per-request specification defining the type of fault to inject (e.g., REQUEST_LOSS, SERVER_CRASH), the target transaction identity, and the number of times the fault should be triggered (`injectionCount`).
## Success Criteria *(mandatory)*
### Measurable Outcomes
- **SC-001**: 100% of simulated "Request Delivery Failures" result in zero state changes (balance and ledger) before the first successful retry.
- **SC-002**: 100% of simulated "Server Crashes Before Execution" leave no trace of the transaction in the database (no partial balance updates, no ledger entries) upon server restart.
- **SC-003**: For any sequence of mixed faults and retries, the final account balance is mathematically identical to the expected balance based on unique successful transactions.
- **SC-004**: The fault simulator allows per-request configuration without impacting the behavior of other concurrent transactions.
## Assumptions
- **Fault Triggering**: It is assumed that the fault is triggered by a specific field in the request payload or a specialized header used for testing.
- **Server Lifecycle**: For the "Server Crash" simulation, it is assumed that the "crash" is simulated by a process termination that is handled by an external orchestrator (e.g., a test runner) that restarts the server.
- **Consistency**: It is assumed that the existing idempotency logic (sequence keys) is the primary mechanism that allows retries to work after these faults.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment