- Home
- Skills
- Agents & Orchestration
- Durable Agent Sessions
Durable Agent Sessions
Design and audit AI agent sessions to survive crashes, retries, and restarts without state loss or side-effect duplication.
$9
Works with the AI Agents you already use
Durable Agent Sessions
Example session with this skill installed
Audit our session handling in server/agent_loop.py. We store messages in Postgres but users report double-tool execution when the websocket reconnects. Check for idempotency and recovery tails.
- Read your context and instructions
- Compiled the durable agent sessions
I have audited the session logic in server/agent_loop.py against the durable session contract. The current implementation lacks a terminal interpretation for interrupted tool calls, leading to duplicate side-effects on reconnect.
Durable Session Audit: server/agent_loop.py
| Work Unit | Storage Authority | Commit Point | Model Context |
|---|---|---|---|
| Session | sessions table | On init | Yes (Metadata) |
| Turn | messages table | Post-LLM response | Yes (History) |
| Tool Call | tool_results | Post-execution | Yes (Evidence) |
Recovery Decision Table
| Tail State | Interpretation | Action |
|---|---|---|
call_id without result | Uncertain Commit | Check idempotency key in provider API before retry. |
Message without run_id | Dangling Turn | Reject history; session is structurally inconsistent. |
| Pending tool at restart | Interrupted Effect | Query downstream service for call_id status. |
Failure Test Matrix
- Crash before tool commit: Verify that the system does not assume success on restart.
- Network timeout during tool call: Ensure the same
call_idis passed to the tool on retry. - Websocket reconnect during write: Test for duplicate row insertion in
messagestable.
Risk Findings
High Risk (Double-Effect): agent_loop.py:142 calls process_payment() without a stable idempotency key. A restart during this await block causes a second charge.
2.
Medium Risk (Evidence Destruction): The recovery entry point clears the pending_actions buffer on start, losing the only record of unobserved tool calls.
Next steps
- Implement a
client_tokenorcall_idas an idempotency key for all tool execution calls. - Change the session schema to include a
statusfield (pending/committed) for tool results. - Add an integration test simulating a
SIGKILLduring the tool execution phase.
Connects securely to your tools. The creator never sees your data.
About this skill
Building AI agents that crash or lose state mid-task destroys user trust and wastes tokens. This skill provides a rigorous framework for designing and auditing agent sessions to ensure they survive restarts, cancellations, and network failures without repeating side-effects. It moves beyond simple logging to enforce hard durability contracts.
What it does
- Fact Cataloging maps every piece of session data to its commit point, model context inclusion, and owner.
- Lifecycle Closure traces every unit of work through success, failure, and process interruption to ensure terminal states.
- Idempotency Auditing verifies that side-effecting tools and API calls use stable identities to prevent double-execution during retries.
- Recovery Logic defines specific decisions for incomplete session tails, prioritizing structural integrity over heuristic guessing.
- Failure Matrixing generates test cases for crashes occurring before, during, and after data commit points.
How it works
- Define Work Units by identifying the system's specific session, turn, and tool call boundaries.
- Trace Interruptions by analyzing how the system handles timeouts and process restarts at every await boundary.
- Audit Storage Contracts to check for atomicity, writer ownership, and safe repair of corrupted histories.
- Generate Verdicts including a fact catalogue, recovery decision tables, and a prioritized risk report.
Frameworks & tools
This workflow is framework-agnostic and applies to any agent system using persistent storage, including LangGraph, AutoGen, PydanticAI, or custom orchestration layers using SQL, NoSQL, or vector-based state stores.
Why this beats prompting it yourself
Generic prompts often mistake "saving chat history" for "session durability." This skill enforces low-level reliability patterns like writer ownership and atomic publication that LLMs typically overlook without a structured audit framework.
Use cases
- Audit an existing agent's recovery logic to prevent duplicate API billing.
- Design a session schema for long-running agents that must survive server reboots.
- Map idempotency keys for agents performing financial or infrastructure side-effects.
- Create a failure test suite to verify agent behavior during network partitions.
Known limitations
Does not provide implementation code unless explicitly requested. Requires access to session schemas or code for a full audit; otherwise, it produces a design-level review.
Requires session schemas or source code for full audits. Provides design reviews if implementation details are missing. Focuses on durability, not agent reasoning quality.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 17 days ago
Permissions
Reads the agent runtime's source code, schemas, persistence paths, architecture documentation, and tests to produce an evidence-backed durability review. It does not write files or execute commands unless the buyer separately requests implementation.