Skip to content

fix(reef): discover trusted peers as conversations#109905

Merged
steipete merged 7 commits into
mainfrom
fix/reef-conversation-discovery
Jul 17, 2026
Merged

fix(reef): discover trusted peers as conversations#109905
steipete merged 7 commits into
mainfrom
fix/reef-conversation-discovery

Conversation

@steipete

@steipete steipete commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Closes #109893
Related: #108666

What Problem This Solves

Fixes an issue where agents using Reef could not discover an approved, connected peer as a conversation until another path had already created a local model-context session for that peer.

Why This Change Was Made

The Gateway now owns external conversation discovery and asks the selected channel plugin for directory entries. Reef exposes locally trusted peers through that directory; listing persists only an address, while the first turn lazily creates and binds the canonical backing session. An optional query keeps handles reachable beyond the default result page. Canonical route identity remains separate from the exact delivery target, so delivery aliases cannot create duplicate conversation references.

This is an additive Gateway protocol change. It does not alter SQLite tables or advance any schema version; the per-agent schema remains version 11.

User Impact

Agents can list and turn to trusted Reef peers on first contact without raw transport targets or a pre-existing local session. Reef stays a transport-backed conversation surface rather than masquerading as a duplicate model session.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling channel: reef Channel integration: reef size: XL maintainer Maintainer-authored PR labels Jul 17, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 8:17 AM ET / 12:17 UTC.

Summary
The PR adds Gateway-owned conversation discovery that catalogs trusted Reef peers from channel directories without creating model-context sessions, then lazily binds a session on the first correlated turn.

PR surface: Source +484, Tests +598, Docs 0, Other +87. Total +1169 across 25 files.

Reproducibility: yes. On the affected main baseline, approve a connected Reef peer with no local session and call conversations_list with channel reef; the persisted-only listing returns no conversation reference, as described by the canonical issue and encoded in the new regression tests.

Review metrics: 2 noteworthy metrics.

  • Gateway protocol surface: 1 method added. conversations.list becomes an additive cross-client control-plane contract requiring compatibility review.
  • Conversation binding contract: 3 fields made optional, 0 schema-version bumps. sessionId, sessionKey, and role may now be absent in persisted records, changing session-consumer assumptions without altering SQLite DDL.

Stored data model
Persistent data-model change detected: serialized state: src/config/sessions/conversation-registry.test.ts, serialized state: src/config/sessions/conversation-registry.ts, unknown-data-model-change: src/config/sessions/conversation-registry.test.ts, unknown-data-model-change: src/config/sessions/conversation-registry.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #109893
Summary: This PR is the explicit candidate fix for the canonical first-contact Reef discovery bug; the earlier architecture issue established the adjacent conversation/session contract but no longer tracks this narrow defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted exact-head proof of fresh trusted-peer discovery and a successful correlated two-way Reef turn.
  • Rebase onto current main and refresh the affected checks and review against the merge result.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR explicitly defers live two-peer Reef proof until after landing; before merge, add a redacted transcript, recording, live output, or logs showing discovery and a correlated turn on the exact head, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review if needed.

Risk before merge

  • [P1] The PR has no live evidence that a fresh trusted Reef peer is discovered and successfully completes a correlated turn in both directions without a pre-existing session.
  • [P1] The additive conversations.list protocol and address-only persisted records change assumptions across Gateway clients and session consumers; automated tests do not fully establish upgrade compatibility for existing stores and clients.
  • [P1] The branch is behind current main, so mergeability and affected-surface review must be refreshed against the actual merge result.

Maintainer options:

  1. Prove the exact-head upgrade path (recommended)
    Rebase, run a redacted live two-peer Reef scenario for both an unbound peer and an existing bound conversation, and merge only after the exact merge head passes review and checks.
  2. Pause the protocol expansion
    Hold the PR if maintainers do not want conversations.list and address-only conversation records to become permanent cross-client contracts.

Next step before merge

  • [P1] The next action is contributor-supplied live proof followed by protected maintainer review of the additive protocol and session-state compatibility surface, not an automated code repair.

Security
Cleared: The diff adds an admin-scoped Gateway method but introduces no dependency, workflow, secret, permission, artifact-download, or supply-chain change, and no concrete authorization regression is established.

Review details

Best possible solution:

Keep Gateway-owned directory discovery and address-only persistence with lazy session creation, then land only after rebasing and proving both fresh-peer discovery and correlated two-way Reef turns against the exact head while preserving existing bound conversations.

Do we have a high-confidence way to reproduce the issue?

Yes. On the affected main baseline, approve a connected Reef peer with no local session and call conversations_list with channel reef; the persisted-only listing returns no conversation reference, as described by the canonical issue and encoded in the new regression tests.

Is this the best way to solve the issue?

Yes, provisionally. Moving discovery into the credential-owning Gateway, delegating peer enumeration to the channel directory, persisting only the external address, and delaying model-context creation preserves the established session/conversation ownership boundary; exact-head live and upgrade proof remains required.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against db3213264a65.

Label changes

Label justifications:

  • P1: The bug blocks first-contact Reef discovery and correlated agent-to-agent handoffs for every trusted peer lacking a pre-existing session.
  • merge-risk: 🚨 compatibility: The PR adds a Gateway method and changes the conversation-record contract consumed by clients and runtime paths.
  • merge-risk: 🚨 session-state: The PR changes when persisted conversations acquire session bindings, so ordering errors could create stale or mis-associated model context.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR explicitly defers live two-peer Reef proof until after landing; before merge, add a redacted transcript, recording, live output, or logs showing discovery and a correlated turn on the exact head, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review if needed.
Evidence reviewed

PR surface:

Source +484, Tests +598, Docs 0, Other +87. Total +1169 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 12 571 87 +484
Tests 10 629 31 +598
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 87 0 +87
Total 25 1288 119 +1169

What I checked:

  • Canonical bug: The PR explicitly closes the open Reef discovery bug, whose reproduction shows an approved peer missing from conversations_list until another path creates a local session. (a2ec3f69046d)
  • Gateway discovery implementation: The new Gateway path queries configured and live channel directories, resolves routable addresses, registers address-only conversation identities, and returns the persisted list. (src/gateway/conversation-list.ts:103, 1960114a1f1a)
  • Session-state boundary: Conversation registry records now permit sessionId, sessionKey, and role to remain absent until an operation needs model context. (src/config/sessions/conversation-registry.ts:22, 1960114a1f1a)
  • Prior directory findings resolved: The current head treats live discovery as best-effort, merges it with configured entries, and skips or falls back around empty, failed, duplicate, or unroutable directory results; focused tests cover those cases. (src/gateway/conversation-list.test.ts:85, eb1aade5bf3f)
  • Prior turn-ordering finding resolved: Turn capability and correlated message-id preparation now occur before route resolution or session binding, with a regression test asserting unsupported channels create no session or durable operation. (src/gateway/conversation-turn.ts:265, 1960114a1f1a)
  • Automated validation: The PR reports exact-head focused Testbox runs, protocol checks, changed checks, builds, and fresh autoreview; these support the patch but do not substitute for a real two-peer Reef run. (src/gateway/conversation-list.test.ts:1, 1960114a1f1a)

Likely related people:

  • steipete: The surrounding external-conversation architecture, linked canonical bug, Reef behavior, and current repair commits all trace to this contributor, making them the clearest routing candidate for the protocol and session-state decision surface. (role: feature owner and recent area contributor; confidence: high; commits: a2ec3f69046d, 4d5f8b3467f8, eb1aade5bf3f; files: src/gateway/conversation-list.ts, src/gateway/conversation-turn.ts, src/config/sessions/conversation-registry.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-17T10:10:10.097Z sha d9085e2 :: needs real behavior proof before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-17T11:44:42.201Z sha 842540b :: needs real behavior proof before merge. :: [P2] Skip unroutable directory entries instead of failing the list

@steipete
steipete force-pushed the fix/reef-conversation-discovery branch from 300dac1 to f26c137 Compare July 17, 2026 10:39

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

Copy link
Copy Markdown
Contributor

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: 4b12d5ae16

ℹ️ 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".

Comment thread src/gateway/conversation-list.ts Outdated
@steipete steipete self-assigned this Jul 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 17, 2026

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

Copy link
Copy Markdown
Contributor

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: 842540b7dd

ℹ️ 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".

Comment on lines +173 to +177
const route = await params.deps.resolveOutboundSessionRoute({
cfg: params.config,
channel: plugin.id,
plugin,
agentId: params.agentId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Skip unroutable directory entries without aborting the list

When a directory entry's route resolver throws, this unguarded await makes the whole conversations.list request fail even though the code already treats null routes as entries to skip. This can happen with configured Google Chat user directory entries that do not yet have a DM space: resolveGoogleChatOutboundSpace throws No Google Chat DM found ..., so one stale/unroutable allowlist user prevents listing every other conversation for that channel. Catch per-entry route errors here and continue/log, matching the existing if (!route) continue behavior.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 17, 2026
@steipete
steipete force-pushed the fix/reef-conversation-discovery branch from 842540b to eb1aade Compare July 17, 2026 11:54

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

Copy link
Copy Markdown
Contributor

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: eb1aade5bf

ℹ️ 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".

Comment thread src/gateway/conversation-turn.ts
@steipete
steipete force-pushed the fix/reef-conversation-discovery branch from eb1aade to 1960114 Compare July 17, 2026 12:13

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

Copy link
Copy Markdown
Contributor

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: 1960114a1f

ℹ️ 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".

Comment thread src/gateway/conversation-list.ts Outdated

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

Copy link
Copy Markdown
Contributor

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: 230a5017c5

ℹ️ 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".

...(route.peer.kind === "direct"
? { nativeDirectUserId: route.peer.id }
: { nativeChannelId: route.peer.id }),
...(display ? { label: display } : {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Preserve labels when refreshing directory addresses

When a directory entry has no name or handle (for example entries produced by config-backed directory helpers that only return {kind, id}), this registers an identity without a label. upsertConversationIdentity treats a missing label as NULL on conflict, so merely running conversations.list for that channel can erase a label previously learned from inbound/session metadata for the same conversationRef. Preserve the existing label when directory discovery has no display metadata, or only overwrite it when a display value is present.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at 230a5017c5c8f983c48de0ba34d944d989233f7e.

  • Gateway-owned discovery exposes trusted Reef peers as address-only conversations, without fabricating model sessions.
  • First correlated turn validates support before lazy canonical session binding and registers correlation before delivery.
  • Directory discovery preserves canonical route identity separately from the exact delivery target.
  • SQLite tables and schema version are unchanged; the per-agent schema remains version 11.

Proof:

Known proof gap: the two-host Clawd↔Molty live round trip requires deployment of the landed commit. I will run and report that proof immediately after merge.

@steipete
steipete merged commit 8020dd3 into main Jul 17, 2026
130 checks passed
@steipete
steipete deleted the fix/reef-conversation-discovery branch July 17, 2026 12:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
* fix(reef): discover trusted peer conversations

* test(reef): document temporary state cleanup

* test(gateway): include conversation discovery in method order

* chore: leave changelog to release automation

* fix(gateway): preserve configured conversation discovery

* fix(gateway): validate turns before session binding

* fix(gateway): preserve directory conversation identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: web-ui App: web-ui channel: reef Channel integration: reef docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Reef trusted peers are absent from conversation discovery

1 participant