Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/lib/mailbox.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
/**
* Mailbox — Durable message store with unread/read semantics.
*
* ## Migration note (commit 44a153a3)
*
* Previously messages were written to `.genie/mailbox/<worker>.json` files and
* delivered by a polling loop that woke up every few seconds to check for new
* entries. This introduced latency proportional to the poll interval and made
* cross-process coordination fragile.
*
* The current implementation replaced file-based polling with PostgreSQL:
* - Messages are persisted to the `mailbox` table (durable, queryable).
* - A `AFTER INSERT` trigger fires `pg_notify('genie_mailbox_delivery', …)`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Grammar: use "An" before vowel sound.

"A AFTER INSERT trigger" should be "An AFTER INSERT trigger".

📝 Proposed fix
- *  - A `AFTER INSERT` trigger fires `pg_notify('genie_mailbox_delivery', …)`
+ *  - An `AFTER INSERT` trigger fires `pg_notify('genie_mailbox_delivery', …)`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* - A `AFTER INSERT` trigger fires `pg_notify('genie_mailbox_delivery', …)`
* - An `AFTER INSERT` trigger fires `pg_notify('genie_mailbox_delivery', …)`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/mailbox.ts` at line 13, Fix the grammar in the mailbox comment:
replace the phrase "A `AFTER INSERT` trigger" with "An `AFTER INSERT` trigger"
so the article matches the vowel sound before the quoted `AFTER INSERT` trigger
text; update the comment containing "AFTER INSERT" to use "An" accordingly.

* with payload `<to_worker>:<message_id>`.
* - `subscribeDelivery()` calls `sql.listen('genie_mailbox_delivery', …)` so
* the scheduler daemon receives the notification instantly — no polling.
* - A 30-second fallback poll catches any notifications missed during
* reconnects or daemon restarts.
*
* `.genie/mailbox/` JSON files are no longer written or read; references to
* that path in older docs are outdated.
*
* Messages persist to PostgreSQL `mailbox` table before any push delivery
* attempt. This ensures durability (DEC-7).
*
* Delivery is state-aware: messages are queued and pushed to tmux
* panes only when the worker is idle (not mid-turn).
*
* PG LISTEN/NOTIFY triggers instant delivery notification on new inserts.
*/

import { v4 as uuidv4 } from 'uuid';
Expand Down