Skip to content

[codex] Add observer link and active chat reconciliation - #388

Merged
willwashburn merged 3 commits into
mainfrom
codex/observer-link-channel-reconcile
Jul 1, 2026
Merged

willwashburn merged 3 commits into
mainfrom
codex/observer-link-channel-reconcile

Conversation

@willwashburn

@willwashburn willwashburn commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

What changed

  • Added a Join button beside the broker details Workspace key that opens https://agentrelay.com/observer?key=....
  • Added periodic reconciliation for the active visible chat room so Pear picks up durable Relay messages even when the local broker stream does not emit a renderable relay_inbound.
  • Covered the active-room polling gate and hook wiring in the message reconciliation tests.

Why

Messages sent by agents can be persisted and visible in the observer backend while Pear misses the live event path. The active room previously reconciled on tab/status/focus events, so a new backend-visible message could remain absent in Pear until another lifecycle event happened.

Validation

  • npx vitest run src/renderer/src/hooks/use-message-reconciliation.test.ts
  • npm run typecheck:web

Review in cubic

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@willwashburn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6987acc3-845d-4ae9-a582-d5b4e22ef9a0

📥 Commits

Reviewing files that changed from the base of the PR and between 5b656e0 and 3fd2494.

📒 Files selected for processing (3)
  • src/renderer/src/components/broker/BrokerDetailsPage.tsx
  • src/renderer/src/hooks/use-message-reconciliation.test.ts
  • src/renderer/src/hooks/use-message-reconciliation.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/observer-link-channel-reconcile

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

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an observer link for workspace keys in the broker details page, implements periodic polling for visible active chat rooms, and adds deduplication logic to handle cases where a canonical message echo arrives before its optimistic counterpart. Feedback was provided regarding the deduplication window in isCanonicalAlreadyPresent; using the full 10-second window could cause subsequent identical messages to be incorrectly dropped, so a smaller 2-second window is recommended instead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +489 to 494
function isCanonicalAlreadyPresent(
messages: ChatMessage[],
candidate: Pick<ChatMessage, 'body' | 'projectId' | 'timestamp' | 'to'>
): boolean {
return messages.some((message) => message.local !== true && humanMessageContentMatches(message, candidate))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using humanMessageContentMatches inside isCanonicalAlreadyPresent applies the full 10-second HUMAN_MESSAGE_DEDUPE_WINDOW_MS deduplication window.\n\nIf a user sends an identical message (e.g., "ok", "yes", or "?") within 10 seconds of a previously confirmed message (where the canonical echo has already arrived and set local: false), the second message will be matched by isCanonicalAlreadyPresent and silently dropped.\n\nSince the inverse race (where the canonical echo beats the optimistic append) only occurs within a very tight window (typically milliseconds), we should use a much smaller window (e.g., 1–2 seconds) for isCanonicalAlreadyPresent to avoid dropping legitimate subsequent identical messages.

function isCanonicalAlreadyPresent(\n  messages: ChatMessage[],\n  candidate: Pick<ChatMessage, 'body' | 'projectId' | 'timestamp' | 'to'>\n): boolean {\n  const REVERSE_RACE_WINDOW_MS = 2000\n  return messages.some((message) =>\n    message.local !== true &&\n    isHumanMessage(message) &&\n    message.body === candidate.body &&\n    (!message.projectId || !candidate.projectId || message.projectId === candidate.projectId) &&\n    normalizeMessageTarget(message.to) === normalizeMessageTarget(candidate.to) &&\n    Math.abs(message.timestamp - candidate.timestamp) < REVERSE_RACE_WINDOW_MS\n  )\n}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in 8bde2d6. I cherry-picked the follow-up dedupe fix onto this PR: the inverse-race guard now uses the tighter HUMAN_RACE_DEDUPE_WINDOW_MS, humanMessageContentMatches accepts a custom window, and isCanonicalAlreadyPresent only matches unclaimed canonical records (local === undefined) rather than reconciled history. Also added regression coverage for a repeated identical send after the first message has reconciled. Validated with npx vitest run src/renderer/src/stores/agent-store.test.ts src/renderer/src/stores/agent-store.stress.test.ts and npm run typecheck:web.

willwashburn and others added 2 commits June 30, 2026 16:32
…ght window

isCanonicalAlreadyPresent matched against any non-local record across the
full 10s human dedupe window, including already-reconciled history
(local: false) from an earlier send. That falsely suppressed the optimistic
append of a later, legitimately repeated identical send. Scope the match to
standalone, still-unclaimed canonical records (local === undefined) within a
tight 2s race window — the guard exists to catch a sub-second startup race,
not general dedupe.

Addresses review feedback from gemini-code-assist, chatgpt-codex-connector,
and coderabbitai on PR #387.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts:
#	src/renderer/src/hooks/use-message-reconciliation.test.ts
@willwashburn
willwashburn marked this pull request as ready for review July 1, 2026 00:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bde2d6f41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


function observerUrlForWorkspaceKey(workspaceKey: string | undefined): string | undefined {
const key = workspaceKey?.trim()
return key ? `https://agentrelay.com/observer?key=${encodeURIComponent(key)}` : undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Build observer links from the configured cloud host

When Pear is running against a non-production cloud/relay deployment (RELAY_CLOUD_URL or a saved auth apiUrl; see src/main/auth.ts:getApiUrl), the workspace key belongs to that deployment, but this hard-coded production URL sends the Join flow and key to agentrelay.com, so observer joins either fail or use the wrong environment. Derive the observer origin from the configured cloud URL or include that URL in BrokerDetails before rendering the link.

Useful? React with 👍 / 👎.

@willwashburn
willwashburn merged commit ea70c41 into main Jul 1, 2026
5 checks passed
@willwashburn
willwashburn deleted the codex/observer-link-channel-reconcile branch July 1, 2026 01:09
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