1	# M12 Wave 1.5 — broker loopback-conn + local `spt rc` attach
2
3	> JIT plan (todlando, 2026-06-14). doyle-scoped after W1 PASS. Goal: LOCAL `spt rc <id>`
4	> attach rides the BYTE-IDENTICAL `serve_attach` pump as cross-node — because self-dial is
5	> impossible (iroh: "Connecting to ourself is not supported", pinned by
6	> `loopback_self_dial_is_refused_local_uses_fallback_transport`). doyle ruling = **B1**: an
7	> in-process broker loopback connection, NOT B2 local-direct (which would reintroduce a
8	> lesser-tested local branch). Sensitive broker-layer work (KNOWN-HAZARDS 6.7 zone).
9
10	## The invariant (doyle, binding)
11	ONE `serve_attach` pump. Transport is swappable UNDER the stream. Cross-node = QUIC conn;
12	local = broker loopback conn. Both surface as broker net-stream events (`NetStreamData` /
13	`net_stream_subscribe` / `net_stream_send`) so `serve_attach` (target) + the `rc::pump`
14	(operator) are unchanged. The W1.5 int test MUST assert both transports hit the same pump.
15
16	## What already exists (W1)
17	- Operator pump: `spt/src/rc.rs` `run_attach` + `pump` (transport-invariant — reads
18	  `NetStreamData`, writes via `send_attach_input`). Currently codes the now-REFUSED self-dial
19	  (`brain.net_dial(net_status().addr)`) — **this is the one line W1.5 swaps** to a loopback-dial.
20	- Target serve: `spt-daemon/src/attach.rs serve_attach`, auto-dispatched at
21	  `dispatch.rs:335-360 StreamFamily::Attach` (resolves session_id→endpoint via `brain.sessions()`).
22	- Cross-node conn: `brain.net_dial(addr,op) -> NetDialed{conn_id}` (brain.rs:800) →
23	  `NetHost::dial` (nethost.rs:615) → iroh connect → registers in `NetShared::conns`.
24
25	## B1 design (the loopback conn)
26	A broker-internal connection with NO iroh handshake whose two bidi stream ends are wired
27	in-process, so a stream opened by the operator side delivers its bytes as `NetStreamData` to
28	a subscriber on the "remote" side (which the dispatch loop serves via `serve_attach`), and
29	vice-versa. Local `spt rc`: loopback-dial → `conn_id` → `request_attach(conn_id, session_id)`
30	→ subscribe → pump — identical to cross-node from `request_attach` up.
31
32	### Investigation TODOs (read before coding — NOT yet done)
33	1. **`spt-daemon/src/broker.rs`**: the conn table + stream table + how `dispatch_*` routes an
34	   inbound stream's first frame to `StreamFamily::Attach`→`serve_attach`. How a QUIC stream's
35	   bytes become `NetStreamData` events (the accept/serve plumbing). Find the seam to inject a
36	   local pair.
37	2. **`spt-daemon/src/nethost.rs`** (`NetHost::dial` ~615, `NetShared::conns`): how conns get a
38	   `conn_id` + how streams open on a conn. Add a `dial_loopback()` / a `Conn::Loopback` variant
39	   that needs no iroh endpoint.
40	3. **Stream open + cross-wire**: `net_open_stream(conn_id)` on a loopback conn must mint a
41	   stream whose sends loop back to a peer stream id the dispatch loop picks up as inbound.
42	   Likely an in-process channel pair inside the broker, surfaced through the SAME
43	   `NetStreamData`/`net_stream_send`/`net_stream_subscribe` IPC the QUIC path uses.
44	4. **Brain-side**: a `brain.net_dial_loopback(op) -> conn_id` (or reuse `net_dial` with a
45	   sentinel local addr the broker recognizes). Decide: new frame KIND vs sentinel addr.
46	5. **Origin for the gate**: `serve_attach`'s `origin_node` is the handshake-proven id. A
47	   loopback conn has no handshake — use THIS node's own id as origin (access_check is
48	   default-open for self; confirm). Don't fabricate a foreign origin.
49
50	## Tasks
51	- **T1.5.1** Broker loopback conn: `Conn::Loopback` + in-process stream cross-wiring; inbound
52	  loopback streams dispatch to `serve_attach` exactly like QUIC. (broker.rs + nethost.rs)
53	- **T1.5.2** `brain.net_dial_loopback` (or sentinel) → `conn_id`; minimal Brain API.
54	- **T1.5.3** Swap `rc.rs` conn-acquisition: local `run_attach` loopback-dials instead of
55	  `net_dial(own_addr)`. (One seam; pump unchanged.)
56	- **T1.5.4** Int test `local_attach_via_loopback_conn_rides_the_same_pump`: spawn a session,
57	  loopback-dial, request_attach, drive input, render echo, detach→session outlives. PLUS the
58	  **one-pump assertion**: both the cross-node int and this local int exercise the same
59	  `serve_attach`+pump path (assert by construction / shared helper, per doyle).
60	- **T1.5.5** Activate REQ-RC-1 local int evidence (int already active from W1 cross-node face;
61	  add the `[int->REQ-RC-1]` tag on the local test). `traceable-reqs check` EXIT=0.
62
63	## Gate (doyle)
64	Local `spt rc` attaches a broker-held PTY via the loopback conn over the byte-identical pump;
65	both transports proven to hit one pump; full suite + clippy -D warnings + traceable EXIT=0.
66	Then **REQ-HOST-RUN-2** (project cwd via additive `SpawnReq.cwd`) before the M12 gate.
67
68	## Crystallized design (2026-06-14, post-investigation — doyle GO, all 3 Qs answered)
69	doyle answers: (1) origin = THIS node's own id, broker-minted ONLY (never wire-derivable); access
70	`same-node short-circuit` already Allows (access.rs:89, documented access.rs:26-27) — NO access
71	change. (2) explicit new frame KIND `net-dial-loopback` (NOT sentinel addr). (3) one-pump =
72	by-construction via a SHARED serve_attach+pump test helper both cross-node + local int call.
73
74	**Transport seam = `tokio::io::duplex(CAP)`** — one full-duplex pair wires an entire operator↔peer
75	stream. Split each end (`tokio::io::split`); feed the SAME `StreamLog`/subscribe/send_stream/read-pump
76	machinery — only the LEAF send/recv halves become enums. That IS the one-pump invariant by construction.
77
78	- **nethost.rs**: `ConnEntry.conn` → `enum ConnKind { Quic(Connection), Loopback }`
79	  (`conn_remote_addr_json` Loopback→Null). `StreamEntry.send` → `enum SendHalf { Quic(SendStream),
80	  Loopback(WriteHalf<DuplexStream>) }` (async `write_all` + `finish`= quinn `finish()` / loopback
81	  `shutdown()`). Read pump takes `enum RecvHalf { Quic(RecvStream), Loopback(ReadHalf<DuplexStream>) }`
82	  — Quic `read_chunk`, Loopback `AsyncReadExt::read`. `register_stream` accepts SendHalf+RecvHalf.
83	  - `dial_loopback(&self)->(u64,String)`: SINGLETON (`loopback_conn: Mutex<Option<u64>>`), mints/reuses
84	    a `ConnKind::Loopback` row, `remote_id_hex = self.local_id.to_hex()`, NO closed-watcher/accept-loop.
85	  - `open_stream` branches on ConnKind::Loopback → `duplex(CAP)`→split→register TWO rows: operator
86	    (initiated_locally=true) + peer (initiated_locally=false, own hex). Returns operator stream_id.
87	    Peer row → dispatch loop → serve_attach with own-node origin → access Allow by construction.
88	- **msg.rs**: `KIND_NET_DIAL_LOOPBACK = "net-dial-loopback"`; reuse `NetDialed` reply; req payload Null
89	  (non-journaled — singleton is idempotent by reuse, no op needed).
90	- **brain.rs**: `net_dial_loopback(&mut self)->io::Result<NetDialed>`.
91	- **broker.rs**: dispatch arm `KIND_NET_DIAL_LOOPBACK`→`dispatch_net_dial_loopback`: `host.dial_loopback()`
92	  →`net_dialed_envelope(conn_id, remote, None, true, Null)`.
93	- **rc.rs**: swap lines 192-195 (`net_status().addr`+`net_dial`) → `net_dial_loopback()`.
94	- **tests/attach.rs**: extract shared helper driving request_attach→subscribe→wait_for_stream→serve_attach
95	  thread→input→render_until→detach→assert(Detached + session outlives). Cross-node + new local
96	  `local_attach_via_loopback_conn_rides_the_same_pump` BOTH call it. Tag `[int->REQ-RC-1]`.
97
98	## Notes
99	- rc.rs today codes the refused self-dial → LOCAL `spt rc` errors at runtime until T1.5.3
100	  (expected; local is W1.5). Cross-node rc works now.
101	- Commit only when the operator asks (not on default branch unprompted).
102

# M12 Wave 1.5 — broker loopback-conn + local `spt rc` attach

> JIT plan (todlando, 2026-06-14). doyle-scoped after W1 PASS. Goal: LOCAL `spt rc <id>`
> attach rides the BYTE-IDENTICAL `serve_attach` pump as cross-node — because self-dial is
> impossible (iroh: "Connecting to ourself is not supported", pinned by
> `loopback_self_dial_is_refused_local_uses_fallback_transport`). doyle ruling = **B1**: an
> in-process broker loopback connection, NOT B2 local-direct (which would reintroduce a
> lesser-tested local branch). Sensitive broker-layer work (KNOWN-HAZARDS 6.7 zone).

## The invariant (doyle, binding)
ONE `serve_attach` pump. Transport is swappable UNDER the stream. Cross-node = QUIC conn;
local = broker loopback conn. Both surface as broker net-stream events (`NetStreamData` /
`net_stream_subscribe` / `net_stream_send`) so `serve_attach` (target) + the `rc::pump`
(operator) are unchanged. The W1.5 int test MUST assert both transports hit the same pump.

## What already exists (W1)
- Operator pump: `spt/src/rc.rs` `run_attach` + `pump` (transport-invariant — reads
  `NetStreamData`, writes via `send_attach_input`). Currently codes the now-REFUSED self-dial
  (`brain.net_dial(net_status().addr)`) — **this is the one line W1.5 swaps** to a loopback-dial.
- Target serve: `spt-daemon/src/attach.rs serve_attach`, auto-dispatched at
  `dispatch.rs:335-360 StreamFamily::Attach` (resolves session_id→endpoint via `brain.sessions()`).
- Cross-node conn: `brain.net_dial(addr,op) -> NetDialed{conn_id}` (brain.rs:800) →
  `NetHost::dial` (nethost.rs:615) → iroh connect → registers in `NetShared::conns`.

## B1 design (the loopback conn)
A broker-internal connection with NO iroh handshake whose two bidi stream ends are wired
in-process, so a stream opened by the operator side delivers its bytes as `NetStreamData` to
a subscriber on the "remote" side (which the dispatch loop serves via `serve_attach`), and
vice-versa. Local `spt rc`: loopback-dial → `conn_id` → `request_attach(conn_id, session_id)`
→ subscribe → pump — identical to cross-node from `request_attach` up.

### Investigation TODOs (read before coding — NOT yet done)
1. **`spt-daemon/src/broker.rs`**: the conn table + stream table + how `dispatch_*` routes an
   inbound stream's first frame to `StreamFamily::Attach`→`serve_attach`. How a QUIC stream's
   bytes become `NetStreamData` events (the accept/serve plumbing). Find the seam to inject a
   local pair.
2. **`spt-daemon/src/nethost.rs`** (`NetHost::dial` ~615, `NetShared::conns`): how conns get a
   `conn_id` + how streams open on a conn. Add a `dial_loopback()` / a `Conn::Loopback` variant
   that needs no iroh endpoint.
3. **Stream open + cross-wire**: `net_open_stream(conn_id)` on a loopback conn must mint a
   stream whose sends loop back to a peer stream id the dispatch loop picks up as inbound.
   Likely an in-process channel pair inside the broker, surfaced through the SAME
   `NetStreamData`/`net_stream_send`/`net_stream_subscribe` IPC the QUIC path uses.
4. **Brain-side**: a `brain.net_dial_loopback(op) -> conn_id` (or reuse `net_dial` with a
   sentinel local addr the broker recognizes). Decide: new frame KIND vs sentinel addr.
5. **Origin for the gate**: `serve_attach`'s `origin_node` is the handshake-proven id. A
   loopback conn has no handshake — use THIS node's own id as origin (access_check is
   default-open for self; confirm). Don't fabricate a foreign origin.

## Tasks
- **T1.5.1** Broker loopback conn: `Conn::Loopback` + in-process stream cross-wiring; inbound
  loopback streams dispatch to `serve_attach` exactly like QUIC. (broker.rs + nethost.rs)
- **T1.5.2** `brain.net_dial_loopback` (or sentinel) → `conn_id`; minimal Brain API.
- **T1.5.3** Swap `rc.rs` conn-acquisition: local `run_attach` loopback-dials instead of
  `net_dial(own_addr)`. (One seam; pump unchanged.)
- **T1.5.4** Int test `local_attach_via_loopback_conn_rides_the_same_pump`: spawn a session,
  loopback-dial, request_attach, drive input, render echo, detach→session outlives. PLUS the
  **one-pump assertion**: both the cross-node int and this local int exercise the same
  `serve_attach`+pump path (assert by construction / shared helper, per doyle).
- **T1.5.5** Activate REQ-RC-1 local int evidence (int already active from W1 cross-node face;
  add the `[int->REQ-RC-1]` tag on the local test). `traceable-reqs check` EXIT=0.

## Gate (doyle)
Local `spt rc` attaches a broker-held PTY via the loopback conn over the byte-identical pump;
both transports proven to hit one pump; full suite + clippy -D warnings + traceable EXIT=0.
Then **REQ-HOST-RUN-2** (project cwd via additive `SpawnReq.cwd`) before the M12 gate.

## Crystallized design (2026-06-14, post-investigation — doyle GO, all 3 Qs answered)
doyle answers: (1) origin = THIS node's own id, broker-minted ONLY (never wire-derivable); access
`same-node short-circuit` already Allows (access.rs:89, documented access.rs:26-27) — NO access
change. (2) explicit new frame KIND `net-dial-loopback` (NOT sentinel addr). (3) one-pump =
by-construction via a SHARED serve_attach+pump test helper both cross-node + local int call.

**Transport seam = `tokio::io::duplex(CAP)`** — one full-duplex pair wires an entire operator↔peer
stream. Split each end (`tokio::io::split`); feed the SAME `StreamLog`/subscribe/send_stream/read-pump
machinery — only the LEAF send/recv halves become enums. That IS the one-pump invariant by construction.

- **nethost.rs**: `ConnEntry.conn` → `enum ConnKind { Quic(Connection), Loopback }`
  (`conn_remote_addr_json` Loopback→Null). `StreamEntry.send` → `enum SendHalf { Quic(SendStream),
  Loopback(WriteHalf<DuplexStream>) }` (async `write_all` + `finish`= quinn `finish()` / loopback
  `shutdown()`). Read pump takes `enum RecvHalf { Quic(RecvStream), Loopback(ReadHalf<DuplexStream>) }`
  — Quic `read_chunk`, Loopback `AsyncReadExt::read`. `register_stream` accepts SendHalf+RecvHalf.
  - `dial_loopback(&self)->(u64,String)`: SINGLETON (`loopback_conn: Mutex<Option<u64>>`), mints/reuses
    a `ConnKind::Loopback` row, `remote_id_hex = self.local_id.to_hex()`, NO closed-watcher/accept-loop.
  - `open_stream` branches on ConnKind::Loopback → `duplex(CAP)`→split→register TWO rows: operator
    (initiated_locally=true) + peer (initiated_locally=false, own hex). Returns operator stream_id.
    Peer row → dispatch loop → serve_attach with own-node origin → access Allow by construction.
- **msg.rs**: `KIND_NET_DIAL_LOOPBACK = "net-dial-loopback"`; reuse `NetDialed` reply; req payload Null
  (non-journaled — singleton is idempotent by reuse, no op needed).
- **brain.rs**: `net_dial_loopback(&mut self)->io::Result<NetDialed>`.
- **broker.rs**: dispatch arm `KIND_NET_DIAL_LOOPBACK`→`dispatch_net_dial_loopback`: `host.dial_loopback()`
  →`net_dialed_envelope(conn_id, remote, None, true, Null)`.
- **rc.rs**: swap lines 192-195 (`net_status().addr`+`net_dial`) → `net_dial_loopback()`.
- **tests/attach.rs**: extract shared helper driving request_attach→subscribe→wait_for_stream→serve_attach
  thread→input→render_until→detach→assert(Detached + session outlives). Cross-node + new local
  `local_attach_via_loopback_conn_rides_the_same_pump` BOTH call it. Tag `[int->REQ-RC-1]`.

## Notes
- rc.rs today codes the refused self-dial → LOCAL `spt rc` errors at runtime until T1.5.3
  (expected; local is W1.5). Cross-node rc works now.
- Commit only when the operator asks (not on default branch unprompted).


Investigate codebase to ground W2 plan. Parallel.


Grep

endpoint run|endpoint list|fn run_attach|ratatui|crossterm|nucleo


Found 19 files
traceable-reqs.toml
crates\spt\src\cli.rs
crates\spt-daemon\src\harnesshost.rs
crates\spt\src\rc.rs
M12-W1-PLAN.md
Cargo.lock
crates\spt\Cargo.toml
M12-PLAN.md
M12-ENDPOINT-RUN-PICKER.md
M12-CANDIDATES.md
CHANGELOG.md
docs\DEFERRED.md
docs-site\src\cli\reference.md
docs-site\src\networking\overview.md
docs-site\src\instances\overview.md
crates\spt-daemon\src\config.rs
PRD.md
M8-PLAN.md
M8-ACCEPTANCE.md


No files found