GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(opencode): session-to-session messaging — communicate between two running sessions by iceteaSA · Pull Request #38944 · anomalyco/opencode

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Jul 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #38965

Related to #19215 (agent-to-agent communication primitives). Not "Closes" — this is an experimental, flag-gated primitive.

Re-submission of #32693, closed by the automated cleanup bot on 2026-07-17 while still active. The branch has been force-pushed since (rebased onto current dev), so GitHub refuses an author-side reopen — same situation as #35195. No maintainer decision was involved in the closure.

Stacked PR. This branch sits on top of three PRs: #38942 (message tool) → #32425 (subagent interrupt) → #38943 (coordinator-messaging) → this. The diff therefore shows the whole stack, but only the top commits (packages/opencode/src/s2s/*, the s2s tool, the DB tables, the poller/drain wiring) are new here. Review most easily against #38943, or wait until the base PRs land. The four together are a family of messaging primitives: subagent↔parent (#38942), interrupt (#32425), sibling↔sibling (#38943), and session↔session (this one).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Lets two separate top-level sessions — different windows / OS processes on the same machine — send each other messages. This is distinct from the subagent primitives in the base PRs: there is no parent/child relationship, so the two sides opt in with an explicit mutual-consent handshake first. Gated behind OPENCODE_EXPERIMENTAL_S2S (off by default).

A new s2s tool drives it: invite mints a one-time 10-minute token; the peer runs accept with that token (shared out-of-band), which writes a durable bidirectional consent record; then either side runs msg to send. Peers are addressed by their globally-unique session_id (ses_…), never by slug — slugs are not unique. leave tears the pair down.

How a message actually gets from one process to the other:

  • Send persists a versioned capsule row to a new s2s_inbox table in the shared opencode.db (tables: s2s_inbox durable mailbox, s2s_token one-time invites, s2s_allow directional consent).
  • Receive has two halves. A session actively taking a turn drains its inbox at the runLoop turn boundary (in-context). An idle session is woken by a small per-instance poller (~2s) that claims its rows and starts a loop to drain them. Delivered rows are hard-deleted; a 60s reaper reopens any row claimed by a process that crashed before draining. Incoming messages render in the recipient transcript as an external-context frame tagged source="sibling-session", and are treated as untrusted input (attributes escaped at the sink).

Why the receive path is built the way it is (the non-obvious part): the messaging/poller services are per-instance — they resolve through a request-scoped context reference that is only present inside a live request/run fiber. An earlier version forked the poller at layer-build time, where that reference is absent, so it died on its first tick and the entire recipient path was silently dead in a real process while every unit test passed (the tests inject the context). The fix is to (a) drain in-context at the runLoop boundary, and (b) lazily fork the per-instance wake-poller from inside SessionPrompt.loop, capturing the live fiber's context — plus making the S2SStore service a direct member of the prompt-serving layer groups so a serviceOption lookup in the forked fiber actually finds it. No service was made process-global.

Addressing by session_id (not slug) is deliberate: session.slug has no uniqueness guarantee — an earlier draft added a UNIQUE index on it and that broke new-session creation on a real DB once the small random-slug space saturated. Slugs stay as parent-owned handles for the subagent primitives only.

How did you verify your code works?

  • Live two-process test (the real gate — unit tests structurally can't cover cross-process delivery): two opencode windows, shared DB, invite/accept handshake, then messages both directions. Confirmed at the DB level — consent rows written in both directions, capsule persisted, and the row hard-deleted on delivery on each side; the reply surfaced in the recipient's context as a source="sibling-session" frame. Both halves exercised, including waking a fully idle peer.
  • Automated suites: the test/s2s directory (store, poller, capsule, lifecycle, frame-escaping, the cross-process topology repro, and an in-process fork repro pinning the per-instance-context behavior), plus the messaging/coordinator/interrupt suites it shares files with — green locally. bun typecheck clean on the s2s surface (the repo's pre-existing mcp/catalog.ts errors on dev are unrelated).
  • Pre-merge review council (independent, cross-family): found 4 must-fix items incl. 2 security (an unescaped attribute sink, and leave not revoking cross-process consent), all fixed and re-reviewed clean.
  • Since the original submission this branch has been rebased onto current dev three more times, each with the full suite re-run. One fix landed in that window: several test/s2s files shared Effect's process-global memoMap across files, so a router registered by one suite leaked into another and produced order-dependent failures. A testEffectIsolatedShared helper now allocates a file-local MemoMap, keeping intra-file service identity without the cross-file leak.

Screenshots / recordings

Minor TUI surface (an inbox marker line in the transcript + a session-list tweak), reusing the marker render path from #38942.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR (the only "extra" content is the three base PRs this is stacked on — see the note at the top)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
feat(opencode): coordinator-messaging — sibling/coordinator subagent communication #38943
Closed
3 of 6 tasks
@iceteaSA
iceteaSA force-pushed the session-to-session branch 2 times, most recently from 017a9a0 to 50e2f8d Compare July 26, 2026 10:38
This was referenced Jul 26, 2026
feat(opencode): filter instruction files by reader audience #38957
Closed
[FEATURE]: Two running opencode sessions have no way to communicate #38965
Closed
@iceteaSA
iceteaSA force-pushed the session-to-session branch from 50e2f8d to 89868d4 Compare July 26, 2026 12:22
@iceteaSA iceteaSA mentioned this pull request Jul 26, 2026
feat(opencode): task signals — structured returns, terse completion, sparse context, wake-on-message #35400
Closed
3 tasks done
@iceteaSA
iceteaSA force-pushed the session-to-session branch from 89868d4 to 7316ade Compare August 2, 2026 11:44
@github-actions github-actions Bot mentioned this pull request Aug 8, 2026
docs(specs): document tool.execute.after subagent behavior and propose bus delivery #41305
Closed
3 tasks done
@iceteaSA
iceteaSA force-pushed the session-to-session branch from 7316ade to a5af1cb Compare August 8, 2026 20:06
This was referenced Aug 8, 2026
📊 AI CLI 工具社区动态日报 2026-08-09 litang9/big_model_radar#336
Open
📊 AI CLI 工具社区动态日报 2026-08-10 litang9/big_model_radar#341
Open
@iceteaSA
iceteaSA force-pushed the session-to-session branch from 4c8157d to c7c5ab9 Compare August 19, 2026 18:18
iceteaSA added 10 commits August 22, 2026 16:48
@iceteaSA
feat(opencode): add message tool for agent-to-agent communication
ab50fe8
Lets a subagent message the agent that spawned it — ask a question and block
for the answer, or send a fire-and-forget update — instead of only being able
to ask the human. The parent replies with the same tool.

A send wakes the parent's parked task wait through a background-job channel
and parks on a reply Deferred held by a per-instance Messaging service, so no
new session state is needed. Replies are bounded by a timeout, the channel is
separate from the promotion channel, and a missing parent fails fast.

Off by default behind OPENCODE_EXPERIMENTAL_AGENT_MESSAGING.


Injected parent messages carry the parent session model and variant
explicitly, so an injected message cannot fall through to the agent
default and switch the session model.
@iceteaSA
feat(opencode): interrupt a running subagent — steer / cancel / abort
3eab009
Lets a parent agent (via tools) or the human (via TUI esc) steer, gracefully
cancel, or hard-abort a single running Task subagent mid-run, without
affecting the parent or sibling subagents.

A per-instance Interrupt service holds one pending interrupt per child plus a
terminal record; the child consumes it at its own runLoop turn boundary.
Steer injects a frame and the child adapts and continues; cancel injects a
frame, records a terminal, and force-breaks within a grace window; abort
cancels the BackgroundJob immediately. Interrupt tools reach any descendant
through a bounded ancestry walk that fails closed off the caller's subtree.

Off by default behind OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT.
@iceteaSA
merge: agent-messaging into coordinator-messaging
cf7f927
@iceteaSA
feat(opencode): coordinator-messaging — sibling/coordinator subagent …
13af75e
…communication

Lets the sibling subagents one parent spawns message each other directly
instead of routing everything through the parent. The surface is one
composable primitive — a per-child allow-list (`message_allow`) — so the
parent builds whatever graph it wants: hub, mesh, or chain.

Peer sends are fire-and-forget; the synchronous round-trip stays parent-only,
which is what keeps siblings deadlock-free. Slugs are parent-owned handles
resolved through a registry, authorized at send time against both the
allow-list and true sibling-hood. Recipients drain a FIFO inbox at their own
turn boundary, batched so an M-member graph costs O(1) turns per drain.

The interrupt tools also accept a slug task_id, resolved through the same
registry and still subject to the full ancestry check.

Off by default behind OPENCODE_EXPERIMENTAL_AGENT_MESSAGING.
@iceteaSA
feat(opencode): session-to-session messaging between two running sess…
f2d9f62
…ions

Lets two separate top-level sessions — different windows or OS processes on
the same machine — send each other messages. There is no parent/child
relationship, so both sides opt in with an explicit mutual-consent handshake:
invite mints a one-time token, accept consumes it and writes durable
bidirectional consent, then either side can msg. Peers are addressed by
session_id, never by slug, because slugs carry no uniqueness guarantee.

Send persists a capsule row to a shared table; receive has two halves — a
session taking a turn drains its inbox at the turn boundary, and an idle
session is woken by a per-instance poller that claims its rows. Delivered
rows are hard-deleted and a reaper reopens rows claimed by a crashed process.
Incoming messages render as an external-context frame and are treated as
untrusted input.

The poller forks lazily from inside the run loop so it captures the live
fiber's instance context; forking at layer-build time leaves that context
absent and the receive path dies silently while unit tests still pass.

Off by default behind OPENCODE_EXPERIMENTAL_S2S.
@iceteaSA
fix(opencode): bound s2s delivery failures
336eb3c
@iceteaSA
fix(opencode): bound the s2s poller failure tracking maps
80f21c7
@iceteaSA
fix(opencode): make the s2s tool test base self-contained
5d54905
@iceteaSA
feat(opencode): list s2s peers with names and consent direction
52e00ba
@iceteaSA
docs(opencode): document the s2s list command
ffca17f
@iceteaSA
iceteaSA force-pushed the session-to-session branch from c7c5ab9 to ffca17f Compare August 22, 2026 19:32
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Aug 26, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Aug 26, 2026
@opencode-agent opencode-agent Bot mentioned this pull request Oct 21, 2026
[FEATURE]: Native AI Council workspace for the Windows desktop app #57721
Closed
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Two running opencode sessions have no way to communicate

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@iceteaSA
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.