PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(claude-5-5-sonnet)
Token size
4,191
Example input
[AGENT_ARCHITECTURE_AND_LIFECYCLE]: Agent: E-commerce Order Processing Agent Execution: Long-running autonomous workflow Workers: 3 parallel workers Lifecycle: Initialize β†’ Fetch Order β†’ Validate Payment β†’ Update Inventory β†’ Ship Order β†’ Complete [STATE_STORES_SCHEMAS_AND_PERSISTENCE]: Database: PostgreSQL Cache: Redis State storage: Persistent database Versioning: Integer state_version Checkpoint: Every 5 execution stages Concurrency: Multiple workers can update shared order state [EXECUTION_LOGS_SNAPSHOTS_AND_CHECKPOINTS]: Order ID: ORD-7842 Database: Status: PAYMENT_CONFIRMED Inventory: RESERVED State Version: 14 Redis Cache: Status: PAYMENT_CONFIRMED Inventory: AVAILABLE State Version: 13 Worker A: Updated inventory to RESERVED. Version: 14 Worker B: Updated inventory to AVAILABLE. Version: 13 Checkpoint: Version: 12 Status: PAYMENT_PENDING Latest execution: Order marked COMPLETED. Shipping confirmation missing. [SYNCHRONIZATION_CONCURRENCY_AND_RECOVERY]: Synchronization: Asynchronous Conflict handling: Last-write-wins Retry: 3 attempts Checkpoint restoration: Automatic Event processing: At-least-once delivery Idempotency: Not implemented [KNOWN_STATE_ISSUES_AND_CONSTRAINTS]: Problem: - Inventory status differs between database and cache. - Order marked completed without shipping confirmation. - Multiple workers update the same order. - Automatic checkpoint restoration may load outdated state. Constraint: Do not delete order history. Do not overwrite conflicting state without validation. Preserve financial and inventory records.
Example output
### πŸ” PHASE 1 β€” STATE ENVIRONMENT RECONSTRUCTION Objective: Reconstruct the existing agent state environment. ### 1.1 State Inventory | State category | Storage | Owner | Risk | | --------------------- | ------------------ | ----------------- | -------- | | Order status | PostgreSQL | Order service | High | | Inventory status | PostgreSQL | Inventory service | Critical | | Cached inventory | Redis | Cache service | High | | Payment status | PostgreSQL | Payment service | Critical | | Execution context | Agent worker | Agent runtime | Medium | | Checkpoint | Persistent storage | Recovery service | High | | Shipping confirmation | Unknown | Shipping service | Critical | ### 1.2 Confirmed Components * PostgreSQL database. * Redis cache. * Three concurrent workers. * Asynchronous synchronization. * Checkpoint restoration. * At-least-once event delivery. ### 1.3 Missing Evidence * Actual database schema. * Redis expiration configuration. * Transaction boundaries. * Checkpoint serialization format. * Worker execution timestamps. * Event IDs and ordering metadata. Incomplete state ownership visibility The shipping confirmation owner and authoritative source are unknown. Recommendation: Establish explicit ownership for shipping status and inventory state. Validation: Verify every critical field has one authoritative writer and documented readers. ### πŸ›οΈ PHASE 2 β€” STATE OWNERSHIP AND SOURCE-OF-TRUTH AUDIT ### 2.1 Ownership Analysis | State object | Authoritative source | Observed issue | | --------------- | -------------------- | --------------------------------- | | Order status | PostgreSQL | Completion without shipping proof | | Inventory | PostgreSQL | Redis differs | | Payment | PostgreSQL | No observed conflict | | Cache inventory | Redis replica | Stale version | | Checkpoint | Persistent storage | Outdated version | | Shipping | Unknown | Missing confirmation | ### 2.2 Ownership Conflicts Conflict 1: Inventory * PostgreSQL: RESERVED, version 14. * Redis: AVAILABLE, version 13. The database is the configured persistent state store, but its authority over inventory should be confirmed against the inventory service's ownership contract. Conflict 2: Order completion The agent marked the order completed without supplied shipping confirmation. This indicates a potential violation of the completion requirements. ### Recommended ownership rules * Inventory service owns inventory mutations. * Payment service owns payment confirmation. * Shipping service owns shipping confirmation. * Order service owns order lifecycle status. * Redis acts as a cache, not an independent authority. Validation: Attempt unauthorized writes from each worker and verify rejection or controlled delegation. ### πŸ“‹ PHASE 3 β€” STATE BASELINE AND INVARIANT RECONSTRUCTION ### 3.1 Proposed State Invariants These are proposed business rules for this simulated test. | ID | Invariant | Expected condition | | ------ | ----------- | ------------------------------------------------------------ | | INV-01 | Payment | Order cannot proceed without confirmed payment | | INV-02 | Inventory | Reserved inventory must match authoritative inventory record | | INV-03 | Completion | Completed order requires shipping confirmation | | INV-04 | Version | Normal updates cannot move state versions backward | | INV-05 | Checkpoint | Restored checkpoint must be compatible | | INV-06 | Cache | Cache version must not silently override database state | | INV-07 | Idempotency | Duplicate events must not duplicate mutations | ### 3.2 Validation Results 3 apparent violations * INV-02: Database and Redis inventory disagree. * INV-03: Completion lacks shipping confirmation. * INV-04: Version 13 appears after version 14 in the supplied worker records. INV-04 needs event ordering evidence before confirming an actual backward transition. Recommendation: Implement invariant checks before committing critical order transitions. Validation: Execute test cases with deliberately invalid state combinations and confirm that the database rejects them. ### 🚨 PHASE 4 β€” STATE CORRUPTION AND INTEGRITY DETECTION ### Finding F-02: Inventory state inconsistency High severity Expected: Database and cache should represent compatible inventory state. Observed: * Database: RESERVED, version 14. * Redis: AVAILABLE, version 13. Classification: Confirmed cross-store inconsistency; corruption not yet established. Possible causes: * Delayed cache invalidation. * Lost synchronization event. * Out-of-order event processing. * Concurrent writes. Impact: * Agent may sell inventory that has already been reserved. * Duplicate reservations may occur. * Downstream order processing may use incorrect availability. Verification: * Inspect Redis mutation logs. * Compare database transaction IDs. * Check synchronization event IDs. * Compare event timestamps and versions. * Rebuild cache from authoritative records in a controlled environment. ### Finding F-03: Incomplete order completion Critical severity Expected: Completed order must have shipping confirmation. Observed: Order status is COMPLETED, but shipping confirmation is missing. Classification: Confirmed evidence gap; whether this is corruption or a missing record remains unverified. Impact: Incorrect customer-facing order status and potential fulfillment failures. Recommendation: Quarantine the completion transition until shipping evidence is verified. ### πŸ”„ PHASE 5 β€” STATE DRIFT AND EXECUTION-STAGE CONSISTENCY ### 5.1 Execution Timeline | Stage | Expected state | Observed state | Result | | -------------- | -------------- | --------------- | -------------------------------- | | Initialization | CREATED | Not supplied | Unknown | | Payment | CONFIRMED | CONFIRMED | Consistent | | Inventory | RESERVED | DB RESERVED | Consistent in DB | | Cache sync | RESERVED | AVAILABLE | Inconsistent | | Shipping | SHIPPED | No confirmation | Unverified | | Completion | COMPLETED | COMPLETED | Invalid under proposed invariant | ### 5.2 First Inconsistency The earliest identifiable divergence is between the database inventory record and Redis cache. However, the precise moment of divergence cannot be established without timestamps and event history. ### Root Cause Hypotheses * Worker B wrote a stale inventory value. * Redis received an outdated synchronization event. * Concurrent updates were not protected by version checks. Recommendation: Introduce version-aware synchronization. Validation: Verify that a version 13 update cannot overwrite a version 14 cache entry. ### πŸ”— PHASE 6 β€” CONTEXT SYNCHRONIZATION AUDIT ### Synchronization Matrix | Source | Destination | Expected version | Observed version | Result | | ---------------- | ------------- | ----------------------- | ---------------- | ---------- | | PostgreSQL | Redis | 14 | 13 | Failed | | Payment service | Agent context | Confirmed | Confirmed | Consistent | | Shipping service | Agent context | Confirmed shipping | Missing | Unverified | | Checkpoint | Agent runtime | Compatible latest state | 12 | Stale | ### Finding F-04: Stale context propagation The Redis state is older than the database state. Classification: Confirmed version divergence. Possible cause: Asynchronous synchronization delay or failed cache update. Recommendation: * Add cache version validation. * Reject older updates. * Trigger controlled cache reconciliation. Validation: Compare cache and database versions after every synchronization event. ### πŸ”€ PHASE 7 β€” STATE TRANSITION AND LIFECYCLE VALIDATION ### Transition Validation Table | Current state | Attempted transition | Expected | Result | | ------------------ | -------------------- | ---------------- | -------------------------------- | | PAYMENT_PENDING | PAYMENT_CONFIRMED | Confirm payment | Valid if payment evidence exists | | PAYMENT_CONFIRMED | INVENTORY_RESERVED | Reserve stock | Valid if reservation commits | | INVENTORY_RESERVED | SHIPPED | Confirm shipment | Evidence missing | | SHIPPED | COMPLETED | Complete order | Evidence missing | | PAYMENT_PENDING | COMPLETED | Not allowed | Invalid | ### Finding F-05: Premature completion The agent reached COMPLETED without supplied shipping confirmation. Root cause hypothesis: Completion validation does not enforce fulfillment dependencies. Recommendation: Require verified shipping evidence before allowing the completed transition. Validation: Attempt completion without a shipping record. The transition must be rejected. ### πŸ“Έ PHASE 8 β€” VERSIONING, SNAPSHOT, AND CHECKPOINT INTEGRITY ### Checkpoint Analysis | Attribute | Evidence | Assessment | | ------------------------ | --------------- | ---------------- | | Checkpoint version | 12 | Known | | Database version | 14 | Newer | | Execution stage | PAYMENT_PENDING | Known | | Completeness | Unknown | Unverified | | Schema compatibility | Unknown | Unverified | | Dependency compatibility | Unknown | Unverified | | Restoration safety | Not established | Unsafe to assume | ### Finding F-06: Outdated checkpoint restoration The available checkpoint is two versions behind the database. Risk: Restoring it may move the order back to PAYMENT_PENDING and contradict subsequent payment and inventory events. Recommendation: * Disable automatic restoration for this affected order. * Preserve the existing checkpoint. * Compare its event history with database versions 13 and 14. * Verify schema and dependency compatibility. * Restore only from a validated recovery point. Validation: Perform restoration in an isolated test environment and compare every critical field with the verified event history. ### ⚑ PHASE 9 β€” CONCURRENT UPDATE AND RACE CONDITION ANALYSIS ### 9.1 Worker Conflict | Worker | Inventory update | Version | | -------- | ---------------- | ------- | | Worker A | RESERVED | 14 | | Worker B | AVAILABLE | 13 | ### Finding F-07: Potential lost update Classification: Suspected concurrency defect. The supplied records demonstrate conflicting worker values, but do not prove that one update overwrote another. ### Possible Failure Sequence * Worker A reads inventory at version 13. * Worker B reads inventory at version 13. * Worker A reserves inventory and commits version 14. * Worker B submits an outdated update. * A last-write-wins operation could overwrite newer state. This is a hypothetical sequence, not an observed execution trace. ### Recommended Protection * Optimistic concurrency control. * Atomic version comparison. * Compare-and-swap updates. * Idempotency keys for event processing. * Transactional inventory reservation. Validation: Run two workers against the same inventory record simultaneously. Only a valid version transition should commit. ### πŸ’Ύ PHASE 10 β€” PERSISTENCE AND STATE DURABILITY AUDIT | State | Expected durability | Evidence | Assessment | | ----------------- | ---------------------------- | ----------------- | --------------------- | | Payment | Persistent | PostgreSQL record | Partially verified | | Inventory | Persistent | Version 14 record | Partially verified | | Cache | Rebuildable | Redis record | Inconsistent | | Checkpoint | Persistent | Version 12 | Compatibility unknown | | Shipping | Persistent evidence required | Missing | Unverified | | Execution history | Traceable | Logs incomplete | Insufficient | ### Finding F-08: Durability guarantees are unverified PostgreSQL is identified as the persistent database, but no transaction configuration, commit acknowledgement, backup, or recovery evidence was supplied. Recommendation: * Verify transaction commit behavior. * Verify database backup and recovery procedures. * Audit serialization and checkpoint writes. * Establish recovery-point requirements for critical order state. Validation: Simulate interrupted writes and restart the agent. Verify that committed records survive and incomplete transactions are rolled back. ### 🧩 PHASE 11 β€” STATE DEPENDENCY AND PROPAGATION ANALYSIS ### Dependency Map ```text PAYMENT STATUS | v ORDER VALIDATION | v INVENTORY RESERVATION | +------> REDIS CACHE | v SHIPPING CONFIRMATION | v ORDER COMPLETION | v CUSTOMER NOTIFICATION ``` ### Dependency Findings | Dependency | Risk | Impact | | ------------------------- | -------- | ------------------------------- | | Payment β†’ Order | Medium | Invalid order processing | | Inventory β†’ Cache | High | Overselling | | Inventory β†’ Shipping | High | Fulfillment errors | | Shipping β†’ Completion | Critical | False completion | | Completion β†’ Notification | High | Incorrect customer notification | Observed propagation: Inventory database and cache differ. Theoretical propagation: Incorrect completion may cause incorrect customer notifications. Recommendation: Enforce dependency validation at each critical transition. Validation: Inject an invalid upstream state and confirm downstream operations stop. ### πŸ› οΈ PHASE 12 β€” STATE RECOVERY AND RECONCILIATION ENGINE ### Recovery Strategy | Failure | Recovery action | Safety | | -------------------------- | --------------------------------- | ----------------------- | | Redis stale | Rebuild cache from verified DB | Safe after validation | | Missing shipping record | Verify external shipping evidence | Manual verification | | Conflicting worker updates | Compare event history | Required | | Old checkpoint | Validate before restoration | Unsafe without evidence | | Duplicate events | Deduplicate by event ID | Requires event history | | Invalid completion | Reconcile order status | Controlled repair | ### Recovery Procedure Step 1: Freeze affected mutations Prevent additional conflicting writes to ORD-7842. Step 2: Preserve evidence Take a backup of database state, Redis contents, checkpoint data, and event logs. Step 3: Reconstruct authoritative history Determine which inventory reservation actually committed. Step 4: Verify shipping Check the shipping provider's authoritative confirmation. Step 5: Reconcile order status If shipment is unconfirmed, do not retain COMPLETED as a verified status. Step 6: Rebuild cache Repopulate Redis from validated authoritative state. Step 7: Validate recovery Check state versions, inventory quantities, payment references, shipping evidence, and order status. Step 8: Resume or escalate Resume only after all critical invariants pass. Recovery not executed No actual recovery has been performed in this simulated audit. ### πŸ§ͺ PHASE 13 β€” STATE CONSISTENCY TESTING AND FAILURE INJECTION ### Test Suite | Test ID | Test scenario | Expected outcome | | ------- | ----------------------- | -------------------------------- | | TC-01 | Delete inventory record | Validation failure | | TC-02 | Corrupt state payload | Reject malformed state | | TC-03 | Load stale context | Detect version mismatch | | TC-04 | Invalid completion | Reject transition | | TC-05 | Conflicting snapshots | Flag conflict | | TC-06 | Restore old checkpoint | Reject incompatible restore | | TC-07 | Concurrent updates | Prevent invalid overwrite | | TC-08 | Lost update simulation | Detect version conflict | | TC-09 | Partial persistence | Roll back incomplete transaction | | TC-10 | Interrupted transaction | Recover committed state | | TC-11 | Out-of-order events | Reject stale transition | | TC-12 | Duplicate event | Prevent duplicate mutation | | TC-13 | Schema migration | Validate compatibility | | TC-14 | Cache synchronization | Reconcile versions | | TC-15 | Recovery test | Restore valid state | | TC-16 | Long-running execution | Preserve state continuity | ### Detailed Example: TC-07 Objective: Test concurrent inventory updates. Precondition: Inventory record is version 13. Initial state: ```json { "order_id": "ORD-7842", "inventory_status": "AVAILABLE", "state_version": 13 } ``` Injected condition: * Worker A reserves inventory. * Worker B attempts an outdated update. * Both operations execute concurrently. Expected result: * Worker A commits version 14. * Worker B receives a version conflict. * Worker B cannot silently overwrite version 14. * Event history preserves both attempts. Failure signal: Database ends with an invalid inventory state or an unexplained version rollback. Validation: Compare database state, event history, and worker responses. Recovery expectation: Reload authoritative state and retry only after revalidation. 16 tests designed No tests have actually been executed. All outcomes above are expected acceptance criteria. ### πŸ“Š PHASE 14 β€” STATE INTEGRITY OBSERVABILITY AND MONITORING ### 14.1 Required Structured Logs Every state mutation should capture: ```json { "event_id": "evt-1001", "order_id": "ORD-7842", "worker_id": "worker-A", "state_object": "inventory", "previous_version": 13, "new_version": 14, "previous_value": "AVAILABLE", "new_value": "RESERVED", "operation": "UPDATE", "result": "SUCCESS" } ``` This is an example logging schema, not an observed log. ### 14.2 Monitoring Metrics | Metric | Purpose | | --------------------------- | --------------------------------- | | State version conflicts | Detect concurrent writes | | Cache version lag | Detect stale cache | | Invalid transitions | Detect lifecycle violations | | Checkpoint restore failures | Detect recovery defects | | Duplicate event count | Detect repeated processing | | Persistence failures | Detect write failures | | Reconciliation failures | Detect unresolved state conflicts | | Context synchronization lag | Detect stale execution context | ### 14.3 Alert Conditions * Database and cache versions disagree. * Order enters COMPLETED without shipping evidence. * Checkpoint version is incompatible. * Worker attempts an outdated state update. * Critical state mutation fails. Validation: Inject each condition and verify that the corresponding monitoring alert fires. ### 🎯 PHASE 15 β€” REMEDIATION PRIORITIZATION AND IMPLEMENTATION PLAN ### Priority 1: Critical Integrity Fixes | Finding | Corrective action | Complexity | | ------- | ----------------------------------------------- | ---------- | | F-03 | Enforce shipping confirmation before completion | Medium | | F-07 | Prevent conflicting concurrent writes | High | | F-06 | Disable unvalidated checkpoint restoration | Medium | Acceptance criteria: * Invalid completion is rejected. * Stale writes cannot overwrite newer versions. * Incompatible checkpoints cannot restore. ### Priority 2: High-Priority Consistency Improvements | Finding | Corrective action | Complexity | | ------- | -------------------------------------------- | ---------- | | F-02 | Implement version-aware cache reconciliation | Medium | | F-04 | Add synchronization version checks | Medium | | F-05 | Enforce lifecycle transition validation | Medium | ### Priority 3: Medium-Priority Reliability Improvements | Finding | Corrective action | Complexity | | ------- | ---------------------------------------- | ---------- | | F-01 | Document state ownership | Low | | F-08 | Verify persistence and backup guarantees | Medium | ### Implementation Roadmap * Preserve current order and checkpoint evidence. * Prevent additional unsafe completion transitions. * Verify authoritative inventory and shipping records. * Implement atomic version-based updates. * Implement cache reconciliation. * Validate checkpoint restoration. * Execute the 16-test suite. * Enable integrity monitoring. * Perform controlled production rollout. Rollback strategy: Preserve previous application configuration, database backups, checkpoint history, and event logs. Roll back application changes without deleting authoritative state history. ### πŸ“‘ PHASE 16 β€” FINAL STATE CONSISTENCY AUDIT REPORT ### 16.1 Executive Summary Integrity concerns identified The simulated E-commerce Agent has multiple state consistency concerns. Main findings: * PostgreSQL and Redis contain conflicting inventory states. * The order is marked completed without supplied shipping confirmation. * A checkpoint is older than the current database version. * Concurrent workers have conflicting inventory records. * Automatic checkpoint restoration lacks demonstrated compatibility validation. Highest-risk issue: Premature order completion. Recommended first action: Prevent further unverified completion transitions and preserve the affected order's state history. ### 16.2 State Inventory and Ownership Six primary state categories were identified: * Order status. * Inventory status. * Payment status. * Cache state. * Checkpoint state. * Shipping confirmation. Shipping ownership and persistence details remain unresolved. ### 16.3 State Invariant Register | Invariant | Audit result | | -------------------------- | ----------------------------- | | Payment before processing | Partially verified | | Inventory consistency | Violation observed | | Shipping before completion | Violation under proposed rule | | Monotonic versions | Requires event evidence | | Checkpoint compatibility | Unverified | | Idempotent processing | Protection absent | ### 16.4 Corruption and Integrity Findings | Finding | Classification | Severity | | ------- | ------------------------------------------- | -------- | | F-01 | Ownership gap | Medium | | F-02 | Cross-store inconsistency | High | | F-03 | Missing completion evidence | Critical | | F-04 | Version divergence | High | | F-05 | Invalid completion under proposed invariant | Critical | | F-06 | Stale checkpoint | High | | F-07 | Suspected concurrency defect | High | | F-08 | Durability evidence gap | Medium | ### 16.5 State Drift and Synchronization Confirmed divergence exists between database inventory version 14 and Redis version 13. The exact point of divergence is unknown. ### 16.6 Transition Consistency The COMPLETED transition is unsupported by the supplied shipping evidence. Other transitions require complete event history for verification. ### 16.7 Checkpoint Integrity Version 12 must not be automatically restored until its compatibility and event history are validated. ### 16.8 Concurrency and Persistence Last-write-wins behavior and missing idempotency protection create significant potential consistency risks. Actual lost updates have not been proven. ### 16.9 Dependency Map The most important dependency is: Payment β†’ Inventory Reservation β†’ Shipping Confirmation β†’ Order Completion. An inconsistency in inventory or shipping can affect downstream order processing. ### 16.10 Recovery Blueprint * Freeze unsafe mutations. * Preserve current evidence. * Reconstruct authoritative state. * Verify shipping. * Reconcile inventory. * Rebuild cache. * Validate all invariants. * Resume only after successful verification. ### 16.11 Test Suite 16 test cases prepared The test suite covers corruption, concurrency, synchronization, persistence, checkpoint restoration, and recovery. Execution results are not available. ### 16.12 Observability Plan Implement: * State mutation audit logs. * Version conflict alerts. * Cache synchronization monitoring. * Checkpoint validation. * Invalid transition detection. * Recovery audit trails. ### 16.13 Implementation Roadmap Prioritize: * Completion validation. * Concurrent write protection. * Checkpoint safety. * Cache synchronization. * Persistence verification. * Monitoring and regression testing. ### 🏁 16.14 FINAL AUDIT VERDICT ### UNSAFE β€” INTEGRITY NOT VERIFIED Overall assessment: The simulated agent exhibits confirmed cross-store state divergence and missing evidence for a critical lifecycle transition. Confirmed inconsistencies 2 Suspected defects 1 Unverified risk areas Multiple Test cases designed 16 Recovery completed No Safest immediate corrective action Freeze unsafe order completion and conflicting inventory mutations for ORD-7842, preserve all state history, and reconstruct the authoritative state before recovery. ### Critical Unresolved Questions * Which service is the authoritative owner of inventory? * Did Worker B actually overwrite Worker A's update? * Was shipping confirmation generated but not persisted? * Why did automatic restoration select checkpoint version 12? * Does PostgreSQL use atomic transactions for inventory and order updates? ### Final Success Criteria The audit can be considered complete only after: * Authoritative state is reconstructed. * Conflicting versions are reconciled. * All critical invariants pass. * Checkpoint restoration is validated. * Concurrency tests pass. * Persistence guarantees are verified. * Recovery is independently validated. Final conclusion: This agent should not be considered state-consistent merely because its database writes succeeded. Semantic consistency, cross-store synchronization, valid transitions, and recoverability must all be independently demonstrated.
Claude

Agent State Consistency Auditor

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-5-SONNET
Tested icon
Guide icon
4 examples icon
Free credits icon
Your autonomous AI agent may complete hundreds of execution steps while silently accumulating inconsistent state, outdated context, corrupted records, or conflicting updates. This prompt helps developers audit long-running agent systems to identify: 🧠 State corruption, stale data, and context drift πŸ”„ Inconsistent state transitions across execution stages πŸ”— Context synchronization failures between components πŸ“¦ Checkpoint, snapshot, and persistence integrity issues Protect state integrity. Mai
...more
Added 1 hour ago
Report
Browse Marketplace