Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript

fix(push): an agent opening a conversation must reach the phone too

zhuangxialiecc96c154fe34
diff --git a/server/src/__integration__/agent-reply-push.test.ts b/server/src/__integration__/agent-reply-push.test.ts
index 24a0fd2..1c1d6a9 100644
--- a/server/src/__integration__/agent-reply-push.test.ts
+++ b/server/src/__integration__/agent-reply-push.test.ts
@@ -27,6 +27,8 @@ import assert from 'node:assert/strict'
import { pool } from '../db/pool.js'
import { ensureSchemaOnce, resetAllTables, seedCompanyWithAgent, teardownAll } from './_helpers.js'
import { runCli } from '../agents/cli.js'
+import { startPrivateChat } from '../agents/private_chat.js'
+import { startPulledGroup } from '../agents/scanner_helper.js'
import { __setNotifyHookForTesting } from '../push.js'
interface Captured {
@@ -143,3 +145,72 @@ test('[integration] a muted conversation is still muted', async () => {
const withRecipients = sent.filter((s) => s.recipientUserIds.length > 0)
assert.equal(withRecipients.length, 0, 'pushed into a muted conversation')
})
+
+// ─── an agent can also START the conversation ───────────────────────────────
+//
+// A reply lands in a thread the human already knows about. The `dm_with` and
+// `pull_group` tools open a brand-new one, so their opening line is the message
+// a human has the least other way to discover — and both wrote the row and
+// enqueued the broadcast without ever dispatching a push. In-app they toast
+// like anything else (NotificationToasts skips only system rows); the phone was
+// the one surface that stayed quiet, which is the same asymmetry the reply
+// fix above was about.
+
+test('[integration] an agent opening a DM reaches the phone', async () => {
+ const { companyId, agentId } = await seedCompanyWithAgent()
+ const humanId = 'u-dm-target'
+ await seedOfflineHuman(companyId, humanId)
+
+ const { messageId } = await startPrivateChat({
+ instigatorId: agentId,
+ partnerId: humanId,
+ topic: 'the migration window',
+ opening: 'I need ten minutes on the migration window before Friday.',
+ })
+ await new Promise((r) => setTimeout(r, 150))
+
+ assert.equal(sent.length, 1, 'an agent-opened DM produced no push')
+ assert.deepEqual(sent[0].recipientUserIds, [humanId])
+ assert.match(sent[0].body, /migration window/)
+ assert.equal(sent[0].authorName, `Agent ${agentId}`, 'pushed with a raw agent id as the title')
+ assert.ok(messageId)
+})
+
+test('[integration] an agent pulling a group reaches the phone', async () => {
+ // A pull exists to interrupt someone — there is a six-hour cooldown on it for
+ // that reason — so it reaching every surface except the phone was backwards.
+ const { companyId, agentId } = await seedCompanyWithAgent()
+ const humanId = 'u-pulled'
+ await seedOfflineHuman(companyId, humanId)
+
+ await startPulledGroup({
+ instigatorId: agentId,
+ title: 'Friday migration',
+ members: [humanId],
+ reason: 'two teams are about to touch the same table',
+ opening: 'Pulling you in: two teams are about to touch the same table.',
+ })
+ await new Promise((r) => setTimeout(r, 150))
+
+ assert.equal(sent.length, 1, 'an agent-pulled group produced no push')
+ assert.deepEqual(sent[0].recipientUserIds, [humanId])
+ assert.match(sent[0].body, /same table/)
+})
+
+test('[integration] an agent-only conversation still pushes to nobody', async () => {
+ // The guard rail: this must not become "push on every agent write". Recipients
+ // are computed by joining `users`, and agents have no row there.
+ const { companyId, agentId } = await seedCompanyWithAgent()
+ const { agentId: peerId } = await seedCompanyWithAgent({ companyId })
+
+ await startPrivateChat({
+ instigatorId: agentId, partnerId: peerId, topic: 'handoff', opening: 'taking the deploy',
+ })
+ await startPulledGroup({
+ instigatorId: agentId, members: [peerId], title: 'deploy', reason: 'handoff', opening: 'ditto',
+ })
+ await new Promise((r) => setTimeout(r, 150))
+
+ const withRecipients = sent.filter((s) => s.recipientUserIds.length > 0)
+ assert.deepEqual(withRecipients, [], 'pushed for a conversation with no humans in it')
+})
diff --git a/server/src/agents/private_chat.ts b/server/src/agents/private_chat.ts
index 575475f..521abbb 100644
--- a/server/src/agents/private_chat.ts
+++ b/server/src/agents/private_chat.ts
@@ -13,6 +13,7 @@ import { randomUUID } from 'node:crypto'
import type { PoolClient } from 'pg'
import { pool } from '../db/pool.js'
import { CH_MESSAGE_NEW } from '../redis.js'
+import { dispatchMessagePush } from '../push.js'
import { enqueueBroadcast, nudgeRealtimeOutbox } from '../realtime-outbox.js'
/** Find an existing direct conversation between two participants, or
@@ -236,5 +237,16 @@ export async function startPrivateChat(args: {
client.release()
}
+ // #199 gave `cumora reply` the push it was missing, but an agent can also
+ // START a conversation, and this opening line is the one a human has the
+ // least other way to learn about: a brand-new thread they were not looking
+ // at, whose first message is authored by an agent. In-app it toasts like any
+ // other — NotificationToasts skips only system rows — so the phone was the
+ // one surface that stayed quiet. Fire-and-forget after COMMIT, for the same
+ // reason the other two dispatches are: a push must never hold up the write.
+ // A DM between two agents pushes to nobody on its own, because
+ // computeMessageRecipients joins `users`.
+ void dispatchMessagePush({ conversationId, authorId: instigatorId, messageId, body: opening, companyId })
+
return { conversationId, messageId }
}
diff --git a/server/src/agents/scanner_helper.ts b/server/src/agents/scanner_helper.ts
index 3f656bf..25a42ad 100644
--- a/server/src/agents/scanner_helper.ts
+++ b/server/src/agents/scanner_helper.ts
@@ -1,6 +1,7 @@
/** Helper for tool-driven group pulls (separate from the periodic scanner). */
import { randomUUID } from 'node:crypto'
import { pool } from '../db/pool.js'
+import { dispatchMessagePush } from '../push.js'
import { CH_GROUP_PULLED, CH_MESSAGE_NEW, publish } from '../redis.js'
/** Hours an agent must wait between human-interrupting group pulls. */
@@ -143,6 +144,13 @@ export async function startPulledGroup(args: {
console.warn(`[pull_group] durable message ${messageId} committed but publish failed`, error)
})
+ // The point of a pull is to interrupt someone — there is a six-hour cooldown
+ // on it for exactly that reason. Yet the interruption reached the websocket
+ // and the desktop toast and no phone, the same gap #199 closed for `cumora
+ // reply`. An agent-only pull pushes to nobody on its own, because
+ // computeMessageRecipients joins `users`.
+ void dispatchMessagePush({ conversationId, authorId: instigatorId, messageId, body: opening, companyId })
+
console.log(`[pull_group] ${instigatorId} pulled ${conversationId}: ${title}`)
return { conversationId }
}