Skip to content

fix(freshness): a hold on a backlog one read can't clear names catch-up - #4174

Merged
lilyshen0722 merged 1 commit into
mainfrom
cto/f536-catch-up-hint
Nov 15, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
cto/f536-catch-up-hint

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

When an agent has more unseen messages than one pod context read returns, the send-time hold now names the catch-up route instead of only saying "read the conversation" (F536).

Why

A read marks messages read only when it returns every unseen one. recordRead refuses a truncated tail, so that history the agent never saw isn't acknowledged. The pod context read returns the newest 12 messages. On Growth's #2580 walk on prod, a fresh webhook agent sat in a pod with 35 unseen. It read the context, posted, was held, read again and was held again, following the 409's text exactly each time. The only way out was POST /api/agents/runtime/pods/:podId/catch-up, which the hold never named. The MCP server already rewrites its hint (commonly-mcp/src/tools.js:53), and the CLI wrapper handles the 409 in code. Raw CAP clients and the Python webhook SDK had nothing.

What changes

  • backend/services/agentSendFreshness.ts: past CONTEXT_READ_MESSAGES (12) unseen, the hold says why a read won't clear it. It names POST /api/agents/runtime/pods/<podId>/catch-up with confirmSkipHistory:true and ends "held until you catch up". At 12 or fewer, the text is unchanged byte for byte.
  • backend/services/podContextService.ts: the literal 12 becomes the exported RECENT_MESSAGES_READ. A unit test keeps it equal to the freshness constant, so the two can't drift.
  • examples/sdk/python/commonly.py: catch_up(pod_id). Its docstring says it marks older history read unseen, so call it before writing a reply. _post_reply doesn't call it on its own, because that would acknowledge history the reply never saw.
  • docs/development/agent-experience-audit.md: entry 140.

Nothing else reads the text: hosted turns build their own hold text from unseenCount and messages (nativeRuntimeService.ts:1152-1175), and agentEventService only checks that a hold exists.

Proof

  • Written first, failing on main: two unit tests (12 keeps the read-first text, 13 names catch-up), the constant drift test, and a Mongo service test. In that test, an agent with no cursor and 35 unseen reads the context tail of 12. The cursor stays unset, the hold names catch-up, and recordCatchUp clears it.
  • 605 tests pass across the 36 suites that touch the hold or the context read. tsc --noEmit is clean, and lint adds no new warnings.
  • SDK: 8 of 8 pass (python3 -m unittest test_commonly). The new backlog test errors on main's SDK.

Known edge, not fixed here

The threshold counts unseen messages, but the context read returns the newest 12 rows including the agent's own. So a backlog of, say, 10 unseen interleaved with the agent's own posts can still miss on one read and get the read-first text. That's no worse than today. Catch-up clears it either way, and the CLI wrapper's 50-row re-read covers seats.

Tier 1, with one review (Sonnet) below. It deploys with Tuesday's roll.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N4VWLGaqG2kVEDDn4hY3nm

A read marks messages read only when it returns every unseen one, and the
pod context read returns the newest 12. Past that, the hold's "read the
conversation and try again" could never clear: a webhook agent in a pod
with 35 unseen read, posted, and was held again on every try. The hold now
says why and names POST /api/agents/runtime/pods/:podId/catch-up with
confirmSkipHistory:true. A smaller backlog keeps the read-first text.

The Python webhook SDK gains catch_up(pod_id). The threshold is shared with
podContextService's read count, and a test keeps the two equal. AX audit
entry 140.

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

@lilyshen0722 lilyshen0722 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.

This is the one review for this change (D218, Tier 1): a Sonnet subagent, read-only, at e987ee1. It found nothing Major.

Checked and true:

  • Catch-up: the route (agentsRuntime.ts:2136-2166) reads the newest 20 and calls recordCatchUp (agentSendFreshness.ts:115-124). That counts the omitted rows and advances the cursor, from a fresh cursor too.
  • The read rule: recordRead (:50-62) refuses when any unseen row wasn't returned. The context route passes only the returned ids.
  • 12: the context read is 12 (podContextService.ts:473-475). The export const reaches the CJS export through the Object.assign, and the drift test confirms it.
  • Hosted turns: they read only unseenCount and messages (nativeRuntimeService.ts:1152-1175), never hold.message.
  • Old text: the small-backlog branch is byte-identical to main.
  • Callers that return the hold as JSON (agentsRuntime.ts:1874, 2614, 4605; tasksApi.ts:1083, 1220) are all on runtime-token paths, and the catch-up route takes the same agentRuntimeAuth. agentEventService only checks that a hold exists. The CLI branches on the code and never shows the text.
  • podId: it's String(podId) of an id already authorized by ensurePodMatch. It goes out as JSON, so there's no injection concern.
  • Tests: the new tests fail on main. 605 related tests pass, and the SDK passes 8 of 8. The catch_up docstring is honest that it skips history unread.

Minors, with what was done:

  • The threshold counts unseen messages, but the read's 12 rows include the agent's own. A smaller backlog interleaved with its own posts can still miss on one read and show the read-first text. That's no worse than before, and it's stated in the PR body as a known edge.
  • Public MCP seats have commonly_catch_up withheld. No path shows hold.message to such a model, so this is low risk. The MCP server rewrites its own hint (commonly-mcp/src/tools.js:53), and I've checked that the AX entry's claim about it holds.

GATE: PASS

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The freshness hold now distinguishes unseen backlogs that fit within the 12-message context read from larger backlogs. Larger backlogs receive catch-up guidance. The Python SDK adds a catch-up method that confirms skipped history.

Changes: Freshness Holds and Catch-Up

Layer / File(s) Summary
Context limit and freshness hold
backend/services/podContextService.ts, backend/services/agentSendFreshness.ts, backend/__tests__/unit/services/agentSendFreshness.test.js, backend/__tests__/service/agentSendFreshnessMongoCommitFence.test.js
The context service and freshness service use a 12-message limit. Holds retain read-first guidance for backlogs up to the limit and direct larger backlogs to catch-up. Tests cover hold wording and clearing behavior for both cases.
Python SDK catch-up flow
examples/sdk/python/commonly.py, examples/sdk/python/test_commonly.py, docs/development/agent-experience-audit.md
The SDK adds Commonly.catch_up, which confirms skipped history in its request. Tests cover a backlog that remains held after a context read and clears after catch-up. The audit documents the larger- and smaller-backlog cases.

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

Change: Bug fix

Merge Risk: Minimal · up to e987e

This change adds catch-up guidance to the send hold for large unseen backlogs and a Python SDK catch-up method. The hold text at 12 or fewer unseen messages is unchanged, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: when a backlog exceeds what one pod context read can clear, the freshness hold now names the catch-up route. The diff adds CONTEXT_READ_MESSAGES and a catch-up-specifi…
Description check Passed The description matches the changeset. It explains the over-12-unseen hold text, the RECENT_MESSAGES_READ constant and drift test, the Python catch_up(pod_id) method, and audit entry 140. It also give…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: when a backlog exceeds what one pod context read can clear, the freshness hold now names the catch-up route. The diff adds CONTEXT_READ_MESSAGES and a catch-up-specific hold message in agentSendFreshness.ts, exports RECENT_MESSAGES_READ, adds catch_up to the Python SDK, and adds audit entry 140. The title is specific and matches the changeset, and it follows the conventional fix(scope) form.

Full details: Description check

Explanation

The description matches the changeset. It explains the over-12-unseen hold text, the RECENT_MESSAGES_READ constant and drift test, the Python catch_up(pod_id) method, and audit entry 140. It also gives test results and a known edge case about counting unseen versus returned messages.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b714feb and e987ee1.

Files selected for processing: 7

  • backend/__tests__/service/agentSendFreshnessMongoCommitFence.test.js
  • backend/__tests__/unit/services/agentSendFreshness.test.js
  • backend/services/agentSendFreshness.ts
  • backend/services/podContextService.ts
  • docs/development/agent-experience-audit.md
  • examples/sdk/python/commonly.py
  • examples/sdk/python/test_commonly.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit fc915e4 Nov 15, 2026
35 checks passed
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