Skip to content

fix(agent-runtime): auto-route bot posts in agent-dm pods - #290

Closed
samxu01 wants to merge 1 commit into
mainfrom
fix/dm-agent-runtime-auto-route
Closed

samxu01 wants to merge 1 commit into
mainfrom
fix/dm-agent-runtime-auto-route

Conversation

@samxu01

@samxu01 samxu01 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Agent-side POST /pods/:podId/messages only fired enqueueMentions — so a bot posting in an agent-dm with no @peer text left the other bot's event queue empty (stranded the nova↔theo smoke).
  • Branch on pod.type and call enqueueDmEvent for agent-dm posts, mirroring the human-side messageController path. Only agent-dm qualifies on the agent side: agent-admin / agent-room are operator-driven 1:1 with one human and one agent, and the human peer has no event queue.
  • Non-DM pods continue to gate on explicit @mentions via enqueueMentions. Bot-loop guard inside enqueueDmEvent (8 consecutive bot turns / 30 min) is unchanged and still backstops runaway ping-pong.

Test plan

  • tsc:check clean
  • After Deploy Dev: post via commonly_post_message from one agent in an agent-dm pod with no @-tag → confirm the other bot receives a chat.mention event in AgentEvent
  • Re-run nova↔theo smoke (DM 69f7f1a4261550171efc7c94) and verify both bots round-trip

🤖 Generated with Claude Code

Stranded the nova↔theo smoke: when an agent calls commonly_post_message
in an agent-dm pod with no `@peer` text, the route only fired
enqueueMentions — which extracts nothing without an `@`. The peer's
event queue stayed empty, so neither bot ever received a chat.mention
for the other's message.

Fix: branch on pod.type and call enqueueDmEvent for agent-dm posts. The
human-side messageController already does this for all three DM-shaped
pod types (agent-admin / agent-room / agent-dm). The agent side only
needs it in agent-dm — agent-admin and agent-room are operator-driven
1:1 with one agent and one human, and the human peer has no event
queue to deliver to.

Non-DM pods continue to gate on explicit @mentions via enqueueMentions.
The bot-loop guard inside enqueueDmEvent (8 consecutive bot turns
within 30 min) is unchanged and still backstops a runaway ping-pong.
samxu01 added a commit that referenced this pull request May 4, 2026
Stranded the nova↔theo smoke: when an agent calls commonly_post_message
in an agent-dm pod with no `@peer` text, the route only fired
enqueueMentions — which extracts nothing without an `@`. The peer's
event queue stayed empty, so neither bot ever received a chat.mention
for the other's message.

Fix: branch on pod.type and call enqueueDmEvent for agent-dm posts.
The human-side messageController already does this for all three
DM-shaped pod types. The agent side only needs it in agent-dm —
agent-admin and agent-room are operator-driven 1:1 with one agent and
one human, and the human peer has no event queue.

Non-DM pods continue to gate on explicit @mentions via enqueueMentions.
Bot-loop guard inside enqueueDmEvent (8 consecutive bot turns within
30 min) is unchanged and still backstops runaway ping-pong.
@samxu01

samxu01 commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Squash-merged to main as 6b80f94 (alongside the rate-limit fix in 80da816 to clear the CodeQL alert).

@samxu01 samxu01 closed this May 4, 2026
@samxu01
samxu01 deleted the fix/dm-agent-runtime-auto-route branch May 4, 2026 02:04
samxu01 added a commit that referenced this pull request May 4, 2026
CodeQL js/missing-rate-limiting on POST /memory/sync (the only remaining
alert after the SQL-injection coercions). Same pattern as PR #290's
earlier fix on /pods/:podId/messages — phase4RateLimit (120 req/60s,
keyed per agent) brings these inline with /room, /agent-dm, /pods/:podId/ask.

Also pre-empted PUT /memory which I touched substantively in Phase 2
(cycles append-mode wiring) — adding rate-limit before CodeQL flags it
on the next scan.
samxu01 added a commit that referenced this pull request May 4, 2026
…ack-gate (#293)

Closes the read-and-write loop on the memory layer. Builds on Phase 1
(PR #288) and the §10 amendment. Three additions land in one PR:

- New `cycles[]` section (§10.1): heartbeat-cadence agent journal,
  agent-writable, cap 40 / ≤500 chars / hard-private. Mirrors
  system_exchanges shape with inverted read/write roles. Whole-array
  overwrite returns 403 + cycles_append_only.
- Broader event payload injection (§10.2): list() now mutates-on-claim
  (status-gated findOneAndUpdate per candidate), captures
  memoryRevisionAtDelivery from a single AgentMemory read, and spreads
  a four-field digest bundle into the returned payload — memoryDigest
  (system_exchanges delta), cyclesDigest (last 5), longTermDigest
  (head ≤800 chars), recentDailyDigest (last 2 within 7 days, ≤400 chars
  each). Each sub-field is independently emit-gated.
- Inline HEARTBEAT cue (§10.3): ~80-token narrative directive prepended
  to scheduler heartbeat payload.content instructing the agent to
  extract one takeaway per cycle and append to cycles[]. Same lesson
  as the §9 DM frame — narrative wins over structured metadata.

Lifecycle change: AgentEvent.status now `pending → delivered → acked`.
`delivered` is intermediate (claimed, awaiting explicit ack). The
status-gated acknowledge rewrite + $max-bumped lastSeenRevision make
first-ack monotone and dup-ack a noop. memoryRevisionAtDelivery is
captured on the doc at claim time so the bump survives the fetch→ack
window without trusting the client.

Tests: 32 cycles + digest unit (new file), 9 event-service unit (6
new), 6 cycles integration (new). 32+9+52 = 93 green locally; CI
clean across Test & Coverage, E2E, Service Tests, Analyze.

Rate-limit hardening: phase4RateLimit applied to PUT /memory and
POST /memory/sync (matches /pods/:podId/messages from PR #290).

CodeQL js/missing-rate-limiting still flags those routes as a
false-positive (the middleware IS applied identically to the cleared
route), accepted per PR #290 precedent — not a merge blocker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant