r/AI_Agents • • Oct 17 '26

Discussion Is migrating my existing Python agent architecture to Pi-Durable a good idea?

I’m building a B2B SaaS with a Python-based architecture. The system uses separate LLM calls within Python components, with business logic, workflow orchestration, and application state managed by the existing application. I’m currently using SQLite.

As the system grows, I’m thinking about potential challenges around concurrent users, long-running workflows, retries, failure recovery, and agents handing tasks back and forth.

I’ve been advised to consider migrating the orchestration layer to Pi-Durable, but I’m not sure whether this is the right move for my current architecture.

Does migrating to Pi-Durable make sense in this situation, or would I be better off keeping my current architecture and improving it as needed? What trade-offs should I consider before making this decision?

3 Upvotes

16 comments sorted by

View all comments

1

u/Significant_Tune9219 Oct 18 '26

Moving the loop into a durable runtime does not move the charge. In this setup the workflow log would live in one place and the business write would still live in the Python process and SQLite, and those are different lifecycles. A retry of the loop after a crash can run that Python step again even though the write already committed, and the durable history will say the step succeeded twice. I would leave the orchestration where it is until the side effect and the record of that side effect commit together. The kill-the-worker test only passes if the second run does not create a second write.

1

u/alatmaca Oct 18 '26

Thanks, that makes sense. My plan is to migrate from SQLite to PostgreSQL, make critical business writes idempotent, and then introduce Pi-Durable for long-running workflows with human waits and retries.

Would you recommend this approach? Specifically, how would you handle atomicity between business writes and durable workflow state, and what would you consider the minimum safeguards before adopting Pi-Durable?

1

u/axonpush Oct 18 '26

The plan is sound. On atomicity: you can't get one transaction across Postgres and the workflow runtime's own state, so don't chase distributed atomicity. Make each side safe on its own and decide which one is the record. What works: the business write and its effect record go in the same Postgres transaction. A step that sends, charges, or updates does: check whether its effect row already exists (keyed by an idempotency key the workflow assigns before the step runs); if not, do the write and insert the effect row in one commit; then report done. A retry after a crash reads the effect row and skips or reconciles instead of writing twice. Treat the workflow's own history as a claim, not proof: "step succeeded" in the durable log can disagree with the business database, and when it does, the business database wins.

Minimum safeguards before adopting: a unique constraint backing every idempotency key (so the database, not the code, is the last line); a kill-mid-step test for each step type, not just one happy-path retry; a defined answer for "crashed between the business commit and the step ack" (your reconciliation case); and pending human approvals stored as business rows, not only as workflow timers, so a waiting approval is queryable and survives anything.

If those four are in place, introducing the runtime for the long-running workflows first is a reasonable order.

1

u/alatmaca Oct 18 '26

thank you so much. i’ll organize my implement plan around your recommendation

1

u/axonpush Oct 18 '26

One correction to my own comment above, because the distinction matters for your plan: "do the write and insert the effect row in one commit" only holds for writes inside your own Postgres. An external effect (a send, a charge, a ticket created through an API) can't share that transaction: if the receiver succeeds and your worker crashes before recording it, the local unique constraint never saw the effect, and a retry sends it twice. The shape for external effects is: persist the intent with its operation key in the same commit as the business write, then a separate delivery step does the call using that key as the receiver's idempotency key where the receiver supports one. Where it doesn't, a crash between the receiver succeeding and the record landing is genuinely ambiguous: it stays marked unknown and gets reconciled against the receiver, never blindly retried.

1

u/Significant_Tune9219 Oct 18 '26

I would make the business write idempotent before I move the loop. A durable log and a Postgres commit are two commits, so a crash between them reruns the step and the second run has to find the first row instead of inserting another. Store the workflow's step id on the business row before you commit, and have the retry look that id up. The minimum check is killing the worker after the commit and before the workflow marks the step done: the second run must not create a second row. Human waits can wait until that test passes.