Skip to content

fix(cli): consistent wrapper-agent behavior — mount skill by default + kill double-post via self-post detection - #624

Merged
lilyshen0722 merged 5 commits into
mainfrom
fix/wrapper-no-reply-double-post
Jul 5, 2026
Merged

lilyshen0722 merged 5 commits into
mainfrom
fix/wrapper-no-reply-double-post

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Pre-beta smoke testing (rounds one & two) surfaced that local wrapper agents behave inconsistently — some double-post (narrate after tool-posting), some go silent — because the wrapper spawns the CLI with no behavior guidance and blindly echoes its stdout on top of whatever the agent posted itself.

1. Mount the behavior skill by default. The commonly SKILL.md now ships inside @commonlyai/cli (cli/skills/commonly) and the default attach environment mounts it (skills.claude), so commonly agent attach claude gives the agent the house rules, not just the MCP tools. prepublishOnly keeps it in sync with docs/agents/skills/commonly/SKILL.md. Verified: it symlinks into the agent cwd on spawn.

2. Kill the double-post via self-post detection. Snapshot the pod's message ids before the spawn; if a new one appears during it, the agent posted via commonly_post_message, so the wrapper does not echo the CLI's final text. Automatic — no reliance on the agent emitting NO_REPLY or the skill loading (Claude doesn't reliably do either). NO_REPLY/empty output are still honored as explicit signals. Verified live: a fresh agent asked "12 × 12" now posts exactly one message (144) — was two.

This correctly supports intentional multi-post ("on it…" then "…done" = two tool calls, both land) while eliminating the mechanism-level duplicate.

Skill also hardened separately for proactive pinging + the roster (which get_context now returns — shipped in #622, deployed).

🤖 Generated with Claude Code

https://claude.ai/code/session_01MnRCAFgjrrGZxo9VRCmCm9

The double-post wasn't "too many messages" — intentional updates ("on it" →
"done") are good. It was mechanism duplication: an agent posts via
commonly_post_message (MCP), then the wrapper ALSO posts the CLI's final text
(usually a restatement), re-firing any @mention. The agent had no way to say
"I already posted, stay quiet" — the wrapper ignored NO_REPLY and would post
the literal string.

Now the wrapper skips its post when the agent's output is empty or exactly
NO_REPLY (the established platform sentinel; mixed content still posts verbatim).
So an agent that owns its turn via the tool — one message, or a deliberate
sequence — ends with NO_REPLY and the wrapper stays out. Agents that don't post
via the tool are unaffected: their reply is still posted as before.

Skill updated to match: intentional updates are encouraged; end a
tool-posted turn with NO_REPLY to avoid the echo.
…kill double-post

Round-two smoke testing showed the NO_REPLY sentinel alone doesn't fix the
double-post: a wrapper agent (even with the skill mounted) posts its reply via
commonly_post_message AND then narrates ("Posted to the pod: …"), which the
wrapper echoed as a second message — Claude doesn't reliably end on NO_REPLY.

Two changes make wrapper agents behave consistently:

1. Bundle the commonly behavior skill in the CLI package (cli/skills/commonly)
   and mount it via the default attach environment (skills.claude), so a fresh
   `commonly agent attach claude` gives the agent the house rules — not just the
   MCP tools. Without it, wrapper-spawned CLIs fly blind (some narrate, some
   default to NO_REPLY on a normal question). prepublishOnly keeps the bundled
   copy in sync with docs/agents/skills/commonly/SKILL.md.

2. Detect self-posts: snapshot the pod's message ids before the spawn; if a new
   message appeared during it, the agent posted via the tool, so DON'T echo its
   CLI output. Automatic — no reliance on NO_REPLY or the skill loading. Verified
   live: a fresh agent asked "12 × 12" now posts exactly one message (was two).
   NO_REPLY + empty-output are still honored as explicit/secondary signals.
@lilyshen0722 lilyshen0722 changed the title fix(cli): honor NO_REPLY so the wrapper stops duplicating agent posts fix(cli): consistent wrapper-agent behavior — mount skill by default + kill double-post via self-post detection Jul 4, 2026
…I to 0.1.1

The #622 members roster fed pod.members straight into User.find({_id:{$in}}) —
a stray non-ObjectId value (corrupt data, or the test fixture's 'user-1') threw
a Mongoose CastError and took down the entire get_context response. main was
red on podContextService.test.js. Filter to 24-hex ObjectIds before the query
(works live where ids are real ObjectIds; degrades to [] otherwise). Test green.

Bump @commonlyai/cli 0.1.0 -> 0.1.1 so the skill-mount + double-post detection
in this PR reach users on the next publish.
… fix)

The #622 a2a-DM fix repointed commonly_dm_agent from /room to /agent-dm with a
nested target — but the .mjs test still asserted the old /room route + flat body,
so main was red (my grep missed the .mjs extension in #622). Update the
assertion to the new route/shape.
The double-post detection snapshots pod messages before/after each spawn. The
route-aware mock's else-branch (which consumes the event queue) was catching
those GETs and advancing the event counter, breaking session-reuse sequencing.
Answer /messages explicitly with an empty list. CLI suite green locally (155).
@lilyshen0722
lilyshen0722 merged commit 04583f2 into main Jul 5, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/wrapper-no-reply-double-post branch July 5, 2026 00:49
lilyshen0722 added a commit that referenced this pull request Jul 26, 2026
…first (#757) (#759)

In a pod with two BYO-wrapper agents mentioned in one message, whichever agent
finished second had its ENTIRE reply silently discarded. The event was still
acked, so nothing surfaced the loss — this was being worked around by hand,
mentioning one agent at a time.

The wrapper's self-post detection asked "did any bot post during my turn?"
(`m.isBot`) as a proxy for "did I post?". Equivalent in a single-agent pod;
wrong in the multi-agent rooms that are the core use case.

The client cannot answer this itself: deriving its own bot username needs
`resolveAgentType`'s server-only LEGACY_AGENT_MAP and an owner-scoped
`instanceId` assigned at install, and a wrong guess double-posts. So the server
answers it — `getRecentMessages(podId, limit, selfUserId)` stamps an explicit
`self` boolean on each message, wired through both agent-facing message routes.
Omitting the argument emits no `self` key at all, which is how the wrapper
detects an older server and degrades to the legacy any-bot test.

Three sibling defects found while verifying, each fixed with a test:

- The Mongo fallback populated `userId` WITHOUT `isBot`, so every message on
  that path reported `isBot: false` and detection was dead outright —
  guaranteed double-posting whenever PG was unavailable. Untested until now
  because every backend test mocks getRecentMessages.
- The PG path fabricated `isBot` from a username substring ('-bot', endsWith
  'bot', 'openclaw-'), so a human named "talbot" or "abbot" read as a bot and
  suppressed an agent's reply. The mirrored `is_bot` column is authoritative.
- `hasRecentDuplicateUrls` had no author filter, so a HUMAN posting a link
  suppressed an agent's next heartbeat post.

Suppression is now observable: the log names the message id, its author, and
whether the decision came from `self` or the legacy fallback. #757 went
unnoticed because that line said only "posted via tool".

Verified load-bearing: the new tests fail against the pre-fix code and pass
after, and the #624 double-post guard and #702 human-author carve-out stay
green in both states.

Closes #757


Claude-Session: https://claude.ai/code/session_01DMeWzgFxsfBcjoLVLewEES

Co-authored-by: Claude Opus 4.8 <[email protected]>
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