Skip to content

feat: opt-in durable cross-CLI agent communication through Relay - #500

Merged
khaliqgant merged 5 commits into
mainfrom
feat/relay-agent-communication
Sep 20, 2026
Merged

khaliqgant merged 5 commits into
mainfrom
feat/relay-agent-communication

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Explicit communication.links lets concurrent agents exchange durable messages through the existing Relay broker and Relaycast injection. Each step retains its declared CLI; Relay supplies its launch/injection behavior. Ordinary flows—including multi-agent DAGs without links—do not load the optional runtime or start a broker.

Each directed link lowers to a separate kernel stream. Sends and deliveries are journaled before injection, and only an explicit processing acknowledgement advances the cursor. Resume restores sent/processed history and redelivers unacknowledged messages. Observer channel creation/publication runs independently: failures emit diagnostics without failing or blocking the conversation.

Preflight checks local Relay prerequisites before submission and probes known CLIs under the same filtered environment used for execution. Other interactive CLIs get an honest unverified-auth warning. The broker excludes unrelated ambient credentials; CLI sessions get supported provider authentication and a unique helper token. Missing, incorrect, or cross-session tokens are rejected before journal operations. Local processes still share an OS user/home: this is not isolation against hostile same-user processes.

Dedicated workers opt into the backward-compatible worker.attach.required_streams field, preventing ordinary steps from taking a communicating peer's slot. Resume reattaches ordinary and linked workers, and CLI waiting distinguishes temporary capacity backpressure from a terminal park. Use the matching daemon build: older daemons refuse the new optional attach field.

Validation, with literal commands and complete captured output in the review evidence:

  • 259 SDK tests across 21 files; SDK build, public type contracts, test types, generated-schema consistency, and the full Rust workspace suite.
  • Final real Claude → Codex → Cursor run 01M2Z04VN15G7ATCGZBH2CM785: three sends, deliveries, processing acknowledgements, and successful completions. Each CLI first verified that unrelated/broker credentials were absent and session authentication was present.
  • Real-daemon mixed-flow resume regression with two ordinary and two communicating agents; kernel tests pin worker eligibility and refusal of unheld required streams.
  • Earlier real SIGKILL/resume proof remains in the initial evidence. The review evidence retains failed observations too.

The final live run used installed Claude/Codex binary paths because this machine's mise wrappers hung under the filtered environment. Gemini lacked Google authentication; OpenCode hit a free-model quota and a rejected configured key. No all-CLI live coverage is claimed.

Current scope: local interactive CLI sessions with shell tools and stream surfaces. Usage is explicitly unmetered; timeouts bound duration. Injection is at-least-once across attempts. Hosted provisioning, the public TypeScript channel API, and permission enforcement are outside this change. No merge or release performed.

Usage and trust boundary · Mixed-CLI example


Note

High Risk
Touches local execution credentials, journal channel semantics, worker dispatch/eligibility, and crash/resume redelivery—security- and correctness-sensitive paths beyond documentation-only changes.

Overview
Adds opt-in live messaging between concurrent local agents when a flow declares communication.links. Compile expands links into journaled channels, typed agent instructions, and per-step stream surfaces; ordinary multi-agent DAGs without links are unchanged.

Runtime: --local-agent runs dedicated communication workers that journal sends/deliveries/acks, inject inbound messages via Relay PTY, and expose a token-gated shell helper (send / ack / complete). Optional @agent-relay/* peers load lazily; flows check/run/resume refuse missing workspace key, packages, Node, or broker with probe_failed before touching the daemon. Resume rebuilds conversation history and redelivers unacked messages; observer Relay channel publication failures are non-fatal diagnostics.

Safety & scheduling: Filtered broker/agent env (provider creds per CLI, session tokens, no ambient secrets in probes), managed_cli_unverified for interactive CLIs, unmetered budget warnings, and kernel worker.attach.required_streams so ordinary steps cannot occupy linked workers. CLI park detection waits on live sibling leases before treating capacity as terminal.

Adds schema/docs, example workflows, verification scripts, and broad SDK/kernel tests plus captured live evidence (Claude→Codex→Cursor).

Reviewed by Cursor Bugbot for commit 55e58e7. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 1df038d0-80f9-4974-bba2-4d0cce8d4718

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@khaliqgant khaliqgant changed the title feat: opt-in durable agent communication through Relay feat: opt-in durable cross-CLI agent communication through Relay Sep 20, 2026
@khaliqgant
khaliqgant marked this pull request as ready for review September 20, 2026 08:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T08:27:28.459051Z 4aef60f Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 4 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +77 to +79
await this.relay.messaging.messages.send({ channel: this.relay.channel,
text: `${peer} -> ${this.dispatch.step_id}: ${JSON.stringify(entry.payload.message)}`,
metadata, idempotencyKey: `${key}-projection` });

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.

🔴 Projection outage fails durable conversation

When channel projection fails after injection, pump rejects the attempt. Relaycast is only a view, but its availability now controls workflow completion.

Learn more

The direct message on lines 75–76 performs the agent injection. The following channel send only creates the human-readable Relaycast projection. Awaiting both in one failure path lets a projection outage reject pump, which rejects the session result in run. The worker then records worker_error even though the durable journal and agent delivery succeeded. This contradicts RFC-0001 settled decision 7, which defines Relaycast as a projection without execution semantics.

Example: Relay injects message offset 4 into reviewer, then publishing designer -> reviewer to wf-... times out. Reviewer may process the message, but the step fails and a retry injects it again instead of continuing the durable conversation.

Recommended fix: Decouple projection publication from delivery success. Record or expose projection failures as non-execution diagnostics, while keeping journal delivery and direct injection failures fail-closed. Preserve a stable projection idempotency key so a later best-effort retry cannot duplicate the observer entry.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +145 to +147
const { attachCommunicationWorkers } = await import('../communication/local.js');
communicationWorkers = await attachCommunicationWorkers(spec, socketPath, dataDir);
}

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.

🟡 Relay prerequisites bypass preflight

checkFlow accepts communication flows without the Relay packages or workspace key. attachCommunicationWorkers then fails before submission as a protocol error.

Learn more

Communication adds two locally checkable runtime requirements: both optional Relay packages must resolve, and RELAY_API_KEY must contain an existing workspace key. The normal check path only probes each agent CLI. These lines discover both requirements after daemon connection and classify any setup exception through protocolFailure, although the daemon protocol did not fail. RFC-0001 covenant 2 requires submit-time preflight to refuse or warn on every provable assumption.

Example: A machine has Claude installed and authenticated but omits @agent-relay/sdk. flows check conversation.flow.yaml reports success; flows run ... --local-agent connects to the daemon, throws during worker attachment, and exits with protocol_error before creating a run.

Recommended fix: Add explicit communication-environment diagnostics to the check/run preflight boundary. Verify package resolvability, RELAY_API_KEY, and any required local runtime before daemon submission, and return a closed refusal kind rather than protocol_error. Keep the optional imports lazy for ordinary flows.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread packages/sdk/src/communication/relay.ts Outdated
Comment on lines +96 to +98
broker = await HarnessDriverClient.spawn({ workspaceKey, brokerName: prefix, cwd, channels: [],
...(process.env.RELAYFLOW_RELAY_BROKER_BIN ? { binaryPath: process.env.RELAYFLOW_RELAY_BROKER_BIN } : {}),
env: { ...process.env, RELAY_API_KEY: workspaceKey, RELAY_WORKSPACE_KEY: workspaceKey } });

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.

🟥 Managed agents inherit ambient credentials

Every communicating CLI inherits the runner's complete environment. The agent can read unrelated credentials, bypassing the flow's declared identity and permission scope.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const helperPath = join(directory, 'tool.mjs');
const sockets = new Set<Socket>();
let busy = false;
const server = createServer({ allowHalfOpen: true }, socket => {

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.

🟨 Local processes can impersonate agents

The helper socket accepts every local connection without session authentication. Another same-user process can send messages, acknowledge deliveries, or complete the agent step.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@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: 4aef60f5e3

ℹ️ 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 +77 to +79
await this.relay.messaging.messages.send({ channel: this.relay.channel,
text: `${peer} -> ${this.dispatch.step_id}: ${JSON.stringify(entry.payload.message)}`,
metadata, idempotencyKey: `${key}-projection` });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep observer projection failures out of step execution

When the human-facing channel publication fails after the direct injection succeeds, this awaited projection rejects pump(), which rejects the worker result and completes the agent attempt with worker_error; the next attempt may then reinject a message the agent already received. The wf-* publication is explicitly an observer projection, so a transient channel outage must not turn a durable, successfully injected exchange into a failed run; report the projection failure separately without failing the step.

AGENTS.md reference: AGENTS.md:L45-L49

Useful? React with 👍 / 👎.

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3eb8ca1. Configure here.

Comment thread packages/sdk/src/communication/local.ts Resolved
@khaliqgant
khaliqgant merged commit e21caad into main Sep 20, 2026
9 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