Skip to content

fix(wake): the pod host stands down while a person's own agent greets them - #4224

Closed
commonly-agent wants to merge 1 commit into
mainfrom
fix/host-defers-to-owner-greeting
Closed

commonly-agent wants to merge 1 commit into
mainfrom
fix/host-defers-to-owner-greeting

Conversation

@commonly-agent

Copy link
Copy Markdown
Contributor

What was wrong

A person starts their own hosted agent in a pod and writes right away, mentioning nobody. Two things answer:

  • the pod host (scout), which opts into wake-on-message, so the unaddressed message wakes it;
  • the person's own agent, whose first-contact greeting is running at the same moment.

So the person gets two replies to one first message. In the case that surfaced this, the two runs started 163 ms apart.

The fix

The greeting answers the message. A hosted greeting always sees the person's message, by one of two paths:

  • hosted native turns inline the last 8 pod messages (HOSTED_NATIVE_RECENT_MESSAGES);
  • the unseen-messages hold (agentSendFreshness) stops a post when a message landed after the turn started reading.

Seeing it isn't answering it, so the hosted first-contact cue gains one line: if the person already wrote in this pod, answer that in the greeting. The event is also marked hostedGreeting: true.

The host stands down while that greeting runs. In enqueueWakeOnMessage, the host's wake becomes a digest when four conditions hold:

  • the sender is a person;
  • the host isn't addressed;
  • the sender's own agent has a hostedGreeting first_contact that is pending, folding or delivered;
  • that greeting is under 60 s old.

The host still receives the message, just not as a turn, the same way the loop dampener demotes a wake.

Unchanged:

  • every other agent;
  • an @scout mention;
  • a bot sender;
  • greetings from non-hosted agents, which can't be relied on to see the message;
  • the host's own greeting.

A failed lookup wakes the host, so delivery wins when unsure.

Proof

New agentMentionService.hostDefersToGreeting.test.js (6 cases), plus 2 cases in firstContactService.test.js. Related suites, containerized: 28 suites, 504 tests pass.

Reverse check: main's agentMentionService.ts and firstContactService.ts swapped in, the fix's tests rerun:

      ✕ a hosted greeting is marked and told to answer the person first
    ✕ an unaddressed message while the sender's hosted greeting is in flight reaches the host as a digest
    ✕ only the host stands down: another opted-in agent still wakes
Tests:       3 failed, 39 passed, 42 total

With the fix restored, all 42 pass.

Backend only, so it reaches prod with the next roll.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MDs9DNuyu8j1BUsdEuiKcF

… them (F562)

A person who starts their own hosted agent and writes at once got two
answers to one message: the pod host, woken by the unaddressed message,
and their agent's first-contact greeting.

A hosted greeting always sees that message (hosted native turns inline
recent pod messages, and the unseen-messages hold catches one that lands
mid-turn). Its cue now tells it to answer what the person wrote, and its
first_contact event is marked hostedGreeting. While such a greeting from
the sender's own agent is in flight (pending, folding or delivered, under
60 s old), the host takes the message as a digest instead of a wake.

Only the host stands down, only for a human sender, never when it is
@mentioned, and a failed lookup wakes it as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MDs9DNuyu8j1BUsdEuiKcF
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Hosted-agent greetings now instruct the agent to answer the person’s prior message and mark the event as a hosted greeting. For unaddressed human messages, a recent matching greeting changes the host’s delivery from wake to digest.

Changes: Hosted greeting delivery

Layer / File(s) Summary
Hosted greeting instruction and event marker
backend/services/firstContactService.ts, backend/__tests__/unit/services/firstContactService.test.js
Hosted greetings include an answer-first cue and set hostedGreeting: true in the event payload. Non-hosted greetings omit the cue and field. Tests cover both cases.
Defer host wake during greeting
backend/services/agentMentionService.ts, backend/__tests__/unit/services/agentMentionService.hostDefersToGreeting.test.js
For unaddressed human messages, the service checks once per fan-out for a qualifying hosted greeting from the sender within 60 seconds. A match changes host delivery to digest; a lookup failure preserves wake. Tests cover other delivery paths and targets.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Human
  participant agentMentionService
  participant first_contact_event_lookup
  participant Host
  Human->>agentMentionService: Post unaddressed message
  agentMentionService->>first_contact_event_lookup: Check for recent hosted greeting
  first_contact_event_lookup-->>agentMentionService: Return matching event or no match
  agentMentionService->>Host: Set delivery to digest for matching greeting
Loading

Possibly related PRs

Suggested reviewers: lilyshen0722

Merge Risk: Low · up to 159a6

Hosted greetings now answer the person's first message and the pod host defers to the greeting briefly, so a person is less likely to get two replies. The host still receives a digest, and it wakes if the lookup fails. The tests stub the greeting lookup instead of exercising the real event writer and reader, so a mismatch in the stored event shape could go undetected. Adding a round-trip test would close that gap.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@commonly-agent commonly-agent left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

HEAD: 159a60f — GATE: HOLD

One review round, from an Opus subagent with a fresh context. Two findings block this.

  1. The person can end up with no reply. The host turns its wake into a digest on the bet that the greeting will answer. Every first-contact greeting gets hostedGreeting: true when the agent is provisioned on the native engine. But a greeting turn can exit without posting:

    • the daily turn cap, per install or per user, is reached;
    • turns are configured to zero;
    • the model is unavailable, the call fails or hits the wall clock;
    • the model ends with NO_REPLY.

    None of these exits posts for a first_contact, and none hands the message back to the host. Before this change, the host answered. That is a worse failure than the duplicate reply this PR removes.

  2. Backend lint fails on an accidental installKey =( edit.

Minor findings:

  • A message can land between the greeting's freshness check and its ack.
  • The lookup has no fitting index.
  • The welcome-wake path still double-replies.
  • The tests are mock-only.

A safe version needs a hand-back: wake the host on the person's unaddressed messages when a hosted first-contact run ends without posting. That means touching every decline exit in the native runtime, or holding the host's wake until the greeting's outcome is known. That costs more than the duplicate reply does. Today the second reply already sees the first, since the guard re-decides after an unseen message.

Closing this unmerged and parking the issue with that design note.

GATE: HOLD

@commonly-agent

Copy link
Copy Markdown
Contributor Author

Closing unmerged per the HOLD above. Deferring the host is only safe with a hand-back for every way a greeting can end without posting, and that costs more than the duplicate reply it removes. Parked with that design note.

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