Skip to content

One rule decides where a new conversation runs - #1301

Merged
Varuas37 merged 1 commit into
mainfrom
claude/project-thread-xquerh
Nov 10, 2026
Merged

Varuas37 merged 1 commit into
mainfrom
claude/project-thread-xquerh

Conversation

@Varuas37

Copy link
Copy Markdown
Contributor

Before:

  • Forking a chat that runs on this computer could put the fork on the default device.
  • Forking a chat in a channel whose threads run on a cloud VM was refused.
  • When an agent made a thread and named where it runs, the thread left the channel and lost the parent's approval mode.

After:

  • A fork runs exactly where its source runs and stays in its source's channel.
  • An agent's thread that names a place stays in its channel and keeps the parent's approval mode.
  • Everything else lands where it did before.

Closes #1300

Background

Slice P2 of the plan "Simplify where agents run". P1 (#1293) gave the gateway one Place type. The decision of which place a new chat gets was still spread over four spots:

  • the person/agent/channel/default-device rules inside create_admitted
  • the elsewhere flag in thread_start
  • the fork code in handoffs.rs
  • the pool-or-cloud overflow in place_in_pool

The problem

Each spot answered part of the question with its own inputs.

Forks went through the person rules:

  • A here fork named no place, so it fell to the default device.
  • A fork of a remote channel chat named both a place and a channel, which a person may not do.

The elsewhere flag dropped a named-place thread out of its channel.

The solution

sequenceDiagram
    participant Caller as Person, agent tool or fork
    participant Service as ConversationService
    participant Decide as decide_place
    participant Env as Environments
    Caller->>Service: create (place name?, channel?, fork's source place?)
    Service->>Decide: asked name, channel's place, default device, Creation
    Decide-->>Service: one Place, or InvalidInput / EnvironmentNotConfigured
    Service->>Env: place(conversation, Place)
    Env->>Env: pool? pool_choice(pool now, cloud)
Loading
  • place_decision.rs has two pure functions:
    • decide_place(PlaceAsk { asked, channel, default_device, creation }), with Creation being Person, Thread or Fork(Place):
      • A fork gets its source's place.
      • A person's chat gets: the place it named outside a channel, else the channel's place, else the default device, else here.
      • An agent's thread gets: the place it named, else the channel's place, else here.
      • A person naming a place in a channel is refused InvalidInput before the name is read, as before.
    • pool_choice(PoolNow, cloud) gives the same answers as the old place_in_pool, case by case.
  • RequestedConversation.fork: Option<Place>: a fork carries its source's place. It is no longer a name next to a flag. The request fingerprint folds that place in as remote_name(), so a fork's fingerprint is the same as before and a retry of a fork saved by the old build still replays.
  • thread_start loses its elsewhere flag.
  • Docs: docs/design/channels.md and the create_thread tool description now say what happens. channel-workspaces.md lists the new source.

How we checked it

  • Unit table: tests/conversation/place_decision.rs covers every combination of name, channel, default device and creation kind, including forks. It also covers the pool overflow table.
  • Service tests that fail on the old code:
    • a_fork_of_a_conversation_here_runs_here_whatever_the_default_device (mutation_commands.rs). I checked that it fails when forks are treated as a person's creation.
    • The owned-thread test in channels.rs now also makes a thread that names here, and checks its channel and approval mode.
  • Rust suites:
    • The conversation and composition library tests pass: 2,073 tests.
    • cargo clippy -D warnings passes on Linux, and on Windows through the mingw cross-check.
  • Conversation stress (gate 19):
    • await: the scripted agent's create_thread names here.
    • channel: makes a thread from a channel chat and checks it is listed in that channel. On the old code that thread was in no channel. The step also forks the channel chat from its row and checks the fork is in the channel.
    • Ran locally with awaits=1 channels=1: 6/6 held.
  • Review: three independent review rounds. None found a correctness bug. Their findings on coverage, fingerprints and docs are fixed.

Tradeoffs

  • Refusal order: a place name that is no place is now refused before agent selection and before make_room. At the conversation limit, such a request no longer evicts an idle chat first. No test pins this.
  • Remote note: whether an agent is told that its channel folder is on a remote gateway now follows the asked place, not the channel's place. That only differs for the new case: a thread naming another computer inside a channel. There is no service test with a remote host in a channel, because the fixtures have no remote environment.
  • Stress fork check: the stress step checks only the fork's channel. The fork's place is covered by the Rust test, because nothing runs on Boat in the stress run.

Rollout

Nothing special. Stored data is unchanged, and fork fingerprints are unchanged.


Generated by Claude Code

decide_place reads what a creation asked for, its channel's place, the
default device and whether it is a person's, an agent's thread or a
fork; pool_choice holds the pool's overflow to a cloud VM. An agent's
thread naming a place stays in its channel on its parent's approval
mode, and a fork runs where its source runs, in its source's channel.

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

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

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

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb0c4a5d-72fb-4687-a595-0d75fa67f396
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T15:26:44.294823Z 4def7a7 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.

@Varuas37
Varuas37 merged commit 6c70aeb into main Nov 10, 2026
14 checks passed
@Varuas37
Varuas37 deleted the claude/project-thread-xquerh branch November 10, 2026 16:15
Varuas37 added a commit that referenced this pull request Nov 10, 2026
**Before:**
- `Environments` answered where a conversation runs, and also held the
command policy and how long artifact publish and fetch calls wait.
- Its placements store was an `Option`. Production always set it; tests
left it empty, so every place, placement and erase call had a "no store"
branch.

**After:**
- `Environments` holds places and the placements store only. The store
is required.
- The command policy and both waits live in `EnvironmentToolConfig`,
held by the conversation service and read by the environment tools,
artifact fetch and artifact publish.
- Nothing a person or agent sees changes.

Closes #1302

## Background

Slice P3 of the plan "Simplify where agents run". P1 (#1293) made one
`Place` type, and P2 (#1301) made one rule that decides a new
conversation's place. P3 trims `Environments` down to that job.

## The problem

Two owners lived in one type:

- Code that only needed a wait or the command policy had to reach
through `Environments`.
- Tests built `Environments` without a store, so production code kept
`None` branches that only tests ever took.

## The solution

```mermaid
sequenceDiagram
    participant Comp as composition/local_auth
    participant Svc as ConversationService
    participant Env as Environments
    participant Tools as environment tools / artifacts
    Comp->>Env: places + placements store (required)
    Comp->>Svc: EnvironmentToolConfig (Cedar command policy, publish/fetch waits)
    Tools->>Svc: inner.tool_config.commands / publish_wait / fetch_wait
    Tools->>Env: which place runs this conversation
```

- **New `application/tool_config.rs`:** `EnvironmentToolConfig {
commands, publish_wait, fetch_wait }`. `Default` has no policy and the
old `PUBLISH_CALL_WAIT` / `FETCH_CALL_WAIT`, which moved here.
- **`ConversationDependencies.tool_config`:** `local_auth.rs` builds it
from the Cedar command policy next to the environments.
- **`placement.rs`:** the policy and wait fields and their methods are
gone, and `placements` is no longer `Option`. The test-only
`From<Arc<dyn Environment>>` uses `HereOnlyPlacements`, which reads
Here, accepts Here and refuses any other place as `Unavailable`.
- **Tests:** the dependency literals take `tool_config:
Default::default()`. The lease harness takes the config as an argument,
so tests that vary the policy or the waits say so.

## How we checked it

- **Library tests:** the full `nessa-server` lib suite gives 4,810
passed. The 6 that fail also fail on main in this sandbox: they need a
non-root user (managed_runtimes, codex cleanup, native_hooks ×2,
quarantine ×2).
- **Clippy:** `cargo clippy -D warnings` passes on Linux, and on Windows
through the mingw cross-check.
- **Review:** two independent review rounds. Round 1 found no bugs and
its low findings are fixed: naming, the here-only store, Windows
visibility, and the command artifact deadline still using the publish
wait. Round 2 found nothing actionable.
- **Stress:** no new step. Nothing a person or agent does behaves
differently; the existing gate covers these paths.

## Tradeoffs

The plan's P3 also splits Reach into a small Connection trait, with SSH,
paired and cloud adapters, and removes `let_go`, `unowned` and the
`unreachable!`. That is deferred to C1/C3. Those pieces exist only for
the Workspace variant, and workspace-sdk has no Connection trait yet to
adapt to.

## Rollout

Nothing special. No stored data or wire format changes.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01JcBpmUavSQzUs5aJwmDfpv)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Varuas37 added a commit that referenced this pull request Nov 11, 2026
**Before:** A channel's main agent and its threads could run only on
This Mac, Boat, or (threads only) Any computer.

**After:** Either can also run on one named computer: an SSH host the
gateway serves or a paired computer. Channel settings and the
new-channel flow list those computers, and a computer the gateway does
not serve is refused with `channel_place_unavailable`.

Closes #1305

## Background

Slice P5 of the plan "Simplify where agents run". P1 (#1293) made one
`Place` type, P2 (#1301) one rule that decides a new conversation's
place, and P3 (#1303) trimmed `Environments` to places only. A channel
keeps two places: one for its main agent (`coordinator`) and one for the
threads it starts.

## The problem

- The channel store only accepted the words `local`, `boat` and `pool`
(SQL `CHECK`s), and the domain refused `pool` for the main agent.
- So a person who had a devbox over SSH, or a paired Mac, could pick it
for one chat but never make it a channel's home.
- The client also rejected `pool` coming back for a main agent, and the
phone's contract does not even list `pool` for threads.

```mermaid
sequenceDiagram
    participant P as Person
    participant D as Desktop
    participant G as Gateway
    P->>D: open channel settings
    D-->>P: This Mac / Boat / Any computer only
    Note over P,D: devbox and paired Macs never offered
```

## The solution

```mermaid
sequenceDiagram
    participant P as Person
    participant D as Desktop
    participant G as Gateway
    participant W as Worker "devbox"
    D->>G: devices.list
    G-->>D: online workers + SSH hosts
    P->>D: Computer ▸ devbox (threads)
    D->>G: channel.setPlacement(threads = "devbox")
    G->>G: is devbox served? (under the channel lock)
    alt served
        G-->>D: ok, saved in channels.sqlite3 v6
        P->>D: new chat in the channel
        G->>W: run it on devbox
    else not served
        G-->>D: channel_place_unavailable
    end
```

- **Domain** (6ec9311): `ChannelExecution` holds any `Place`. The
words `local`, `boat`, `pool` keep their meaning; any other word must
name an SSH host or `peer:<key>`. The internal names `here`, `peer:any`
and `boat:thread` are refused. The main agent may now use the pool.
- **Store** (6ec9311): channels.sqlite3 goes to v6.
`channels-any-place.sql` rebuilds the three tables whose placement
columns had `CHECK`s and keeps every row.
- **Service** (6ec9311, 2a1b166): create and setPlacement check a
named computer against the places the gateway serves, under the
channel's lock and only when it changes, so a channel already on a
computer that is offline still loads and can move.
- **Wire** (6ec9311): placement fields are 1-253 byte strings; new
error code `channel_place_unavailable`. Generated Rust and TypeScript
regenerated.
- **Desktop** (6ec9311, 2a1b166): channel settings gain a Computer
segment with a menu of online workers and SSH hosts (hosts named like a
kind are left out). The new-channel flow offers the same; a refusal
sends the person back to the placement step. Headings use
`channelPlaceWords` (Local / Boat / Any computer / host name).
- **Stress step `place`** (6ec9311, 8e6a5b1, 189569f): pairs a
worker, picks it for a channel's threads from the settings dialog,
starts a chat in the channel and checks its lease is on that worker;
also checks an unknown peer is refused.

## How we checked it

- **Stress:** `place` alone, 20/20 held on latest main. The full gate
runs in CI.
- **Library tests:** channel and place tests (268) pass, including a
v1-v5 → v6 upgrade test that keeps rows and then stores `devbox`, and a
service test where a channel names a served host and its new chats run
there. The full `nessa-server` lib suite passed before the rebase; the 6
tests that need a non-root user fail on main too.
- **Desktop:** typecheck and the workspace/client vitest suites pass
(2,253 tests), with a settings test for a channel on `devbox`.
- **Clippy:** `-D warnings` on Linux, and on Windows through the mingw
cross-check.
- **Review:** one independent review round; its findings (stress
destructuring, SSH hosts named like a kind, a check-then-save race,
wording) are fixed in 2a1b166. A second round found nothing
actionable.

## Tradeoffs and follow-ups

- **Moving the main agent still starts a new main conversation.** The
plan wants it kept; that needs P4's changeable placement record, so it
waits on P4.
- **A typo becomes an SSH host name.** `Place::named` reads any plain
word as a host, so `"devbx"` is refused as `channel_place_unavailable`,
not as an unknown word.
- **The phone must be re-vendored** to decode the new values (its
contract lacks `pool` for threads already). That follows in nessa-ios
once this merges.

## Rollout

The channel store upgrades itself from v5 to v6 on first open, in one
transaction. Rolling back means restoring a v5 `channels.sqlite3` from
backup, since older builds refuse a newer schema.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01JcBpmUavSQzUs5aJwmDfpv)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

Decide where a new conversation runs in one place (decide_place)

2 participants