feat(gateway): persist inbound turns and outbound delivery across gateway restarts
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- python, sqlite
- Domain
- backend, database, distributed-systems
Research direction
Start by tracing the Weixin adapter through Intake.publish and the Spine scheduler, including shutdown behavior, then review the suggested restart, duplicate-delivery, lease, and outbox tests. Done means accepted turns and outbound replies survive restart, duplicate deliveries execute once, expired claims are handled safely, and pending delivery can resume without exposing private content or credentials.
Written by the indexing model from the issue text.
Description
Summary
Raven's channel intake and Spine scheduler currently provide in-process concurrency and per-conversation serialization, but they do not establish a durable acceptance boundary for inbound turns or a durable outbox for completed replies.
If the gateway restarts after a channel has received a message but before the turn finishes, the accepted turn cannot be recovered from persistent state. If outbound delivery fails after execution succeeds, there is no channel-neutral durable outbox that guarantees redelivery after recovery.
This proposal is about failure containment and recoverability. It does not assume that a specific channel, model provider, or network is at fault.
Version inspected
- Raven
0.1.7 mainatc3f3678a24d4cbda6204c5142c681235f5df15c4
Current behavior
The current Weixin adapter illustrates the gap:
- It keeps recently seen message IDs in the process-local
_seencollection. - It calls and awaits
intake.publish(...)after parsing the inbound message. Intake.publish(...)submits theTurnRequestto the in-process Spine scheduler.- Scheduler lanes and queued futures live in the gateway process and are intentionally drained or cancelled during shutdown.
This is a sound in-process scheduling model, but it does not persist the fact that Raven accepted a user request. A process restart therefore loses unstarted or unfinished in-memory work. The same gap exists on the outbound side: delivery success/failure is not represented by a durable, retryable outbox shared across channels.
Minimal reproduction
The issue is channel-neutral and can be reproduced with a synthetic slow runner:
- Start the gateway with a channel adapter and a runner that blocks long enough to observe restart behavior.
- Send one user turn and confirm that the adapter has parsed and submitted it.
- Restart the gateway before the turn produces an outbound reply.
- Observe that there is no persistent accepted-task record from which the turn can be resumed or definitively reported as failed.
- Separately, make a completed turn's outbound send fail, restart the gateway, and observe that there is no durable outbox item guaranteeing later redelivery.
Provider timeouts such as #150 reduce the duration of one failure mode, and structured termination such as #149 improves diagnosis, but neither creates a durable channel-to-run-to-delivery contract.
Expected behavior
Once Raven acknowledges a turn as accepted:
- the inbound request should survive gateway restart;
- a stable idempotency key should prevent duplicate execution after channel redelivery;
- processing should be claimable with a lease and safely recoverable after worker death;
- task completion and outbound delivery should be recorded as separate states;
- a failed outbound send should remain pending and retry after channel recovery;
- users should be able to query an accepted task's state even if the original run failed.
Proposed direction
Introduce channel-neutral persistence interfaces rather than implementing reliability independently in every adapter:
-
Durable inbox
- Persist
TurnRequest, conversation ID, origin, channel message ID, and timestamps transactionally. - Enforce a unique idempotency key per channel message.
- Persist
-
Recoverable dispatch
- Claim accepted turns with expiring leases.
- On restart, inspect expired claims before retrying so non-idempotent tool effects are not repeated blindly.
-
Durable outbox
- Persist final replies and delivery attempts separately from run completion.
- Retry transient channel failures and resume pending delivery after restart.
-
Acknowledgement and status hooks
- Allow a channel to acknowledge only after durable acceptance.
- Expose accepted, running, awaiting confirmation, completed, failed, cancelled, and delivery-pending states.
SQLite WAL could be a practical default local backend, but the core contract should remain storage-neutral. Whether the worker stays in the gateway process or moves to a separate service can remain an implementation choice as long as accepted work and delivery state survive process failure.
Suggested tests
- duplicate channel delivery produces one accepted turn;
- restart after acceptance but before execution resumes or reports the same turn;
- restart during execution safely handles an expired lease;
- successful execution plus failed send leaves a pending outbox item;
- channel recovery drains the outbox exactly once;
- scheduler shutdown cannot silently discard a previously acknowledged turn;
- no private message content or channel credentials appear in diagnostic status output.
I am happy to help refine the design and contribute a tested implementation once maintainers confirm the preferred persistence and process boundaries.
- Dominant language
- Python
- Stars
- 4.1k
- Forks
- 94
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 216
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EverMind-AI/Raven
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
EverMind-AI/Raven#1413 ·
Maintainers usually reply within 1 day
-
feat: allow users to build ui-web and ui-tui with `bun`May be free again @0warning0error claimed this 8 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
EverMind-AI/Raven#1283 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
EverMind-AI/Raven#121 ·
Maintainers usually reply within 1 day
-
fix: Feishu channel status wrongly reports missing credentials and "not connected" while WebSocket is livePossibly taken @pcbeingused333 claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 18/100
EverMind-AI/Raven#1399 · 1 comment ·
Maintainers usually reply within 1 day
-
WebUI tab froze silently while gateway stayed healthy (heartbeat stopped 1h49m); reproducible /auth refresh dead-end fixed in #1392Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 22/100
EverMind-AI/Raven#1393 · 2 comments ·
Maintainers usually reply within 1 day
All issues in EverMind-AI/Raven
Similar issues
-
bug docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
comp/tools P2 tool/skills type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#159541 ·
Maintainers usually reply within 1 day