Skip to content
Directory
GitHub Star
Evidence, tags & source code

Transactional Outbox for Agent Reports: Prompt Notifications Without Losing Work ​

After my personal research Agent saves a daily report, I want a prompt message. If I save the report and then directly call email or a bot, the process might exit between the two steps. If I send first, the message might contain a report link that does not yet exist.

Unlike a general background-job queue, this problem is about reliably linking an already committed business transition with a future external effect, not building another research executor.

Commit the report and delivery records together ​

Use the transactional outbox pattern. In the publication transaction, persist authorized notification intents. A unique event_id, channel and target_ref identifies each delivery. This SQL design fragment assumes existing tables, unique constraints, event identity and transactional authorization; it is not a project schema:

sql
BEGIN;
UPDATE reports
SET state = 'published'
WHERE id = $1 AND revision = $2 AND state = 'ready';
-- Application verifies one authorized transition; otherwise roll back.
INSERT INTO delivery_outbox(event_id, channel, target_ref, due_at, state)
VALUES ($3, $4, $5, now(), 'pending')
ON CONFLICT (event_id, channel, target_ref) DO NOTHING;
COMMIT;

The actual application must check affected rows and validate event and target authorization in the transaction. Roll back on a failed transition instead of inserting notifications. If the commit response is lost, inspect the original event identity before repeating it.

Wakeup is not the durable fact ​

After commit, the web process can issue a short wakeup to process due deliveries for that report. If it is lost or execution reaches the platform limit, the records remain durable and periodic scanning compensates. The value of less frequent idle polling depends on real database suspension behavior and tolerated recovery delay; no one scan interval suits every project.

Email and Lark consume independently so one failed channel cannot block another. Use the existing queue's short transaction, leases and fenced commits; see durable jobs.

Suppose 12 records are due when a wakeup begins and each round claims at most 10. A continuation can claim the remaining two originally due records. Keep the original cutoff so a newly deferred failure does not become eligible again just because time advanced during this run. This prevents one failing target from consuming the entire continuation budget. Bound rounds and total time, leaving remaining work to an independent scan.

Keep delivery failures local ​

ObservationHandling
Due pending recordInspect consumer, environment and next scan
RetryInspect transient error, backoff and attempt budget
CanceledCheck subscription and account revocation
AcceptedKeep provider receipt; client visibility remains a separate check
UnknownReconcile the original attempt before resending

Use synthetic reports, two fake channels and a controllable clock to verify immediate wakeup, recovery after a failed wakeup, independent channel failure, fixed-cutoff continuation and no unconditional resend when an accepted external effect loses its response.

Open ETF Agent has scheduled research and email delivery. Multi-channel delivery is in the application roadmap. This is an extension design, not proof that this SQL, these receipts or latency have been verified with a real service.

Engineering notes, evidence and boundaries. · Contact: hpoenixf@foxmail.com · WeChat: hpoenixf0510