Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: LAN discovery, pairing and admin tests
run: cargo test --locked --test lan --test lan_messaging --test admin_messaging --test shell_daemon --test update --test remote --test spawn --test usage --test codex_wake
- name: Store, page and phone tests
run: cargo test --locked --test attachments --test channel --test editing --test issues --test phone --test phone_plain --test requirements --test trace --test workflow --test working_on
run: cargo test --locked --test attachments --test channel --test editing --test issues --test phone --test phone_plain --test requirements --test trace --test workflow --test working_on --test codex_remote
ui:
# The admin page end to end (qa/, headless Chrome, a test bridge with
# stand-in agents). Observe mode: it reports but does not block yet; the
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ User-facing changes to session-bridge. Newest first. Each version lists

## Unreleased

### Changes

- Never kill root: the bridge no longer closes or restarts the session that
holds root, from the admin page, `session-bridge close`, or another session's
`close_session`; each says "<name> holds root; the bridge does not close or
restart it". The Projects tab and the conversation header show no Close or
Restart for it, `list_sessions` marks it with `holds_root`, and the bridge's
instructions tell agents never to end its process. To end it, give the
session another role first, or close it in its own terminal.

### Fixes

- A Codex session the bridge starts on your Codex app server is listed under
the name the start returned and acts in its role, root included, from its
first request. Two starts in one folder get their own names and roles. If
the app server cannot create the session's conversation, the start fails
with the reason in its window.
- Starting a session on macOS no longer brings Terminal or iTerm2 to the
front: the new window or tab opens while you keep working where you were,
and in iTerm2 the tab you were looking at stays selected. One exception:
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ not been read yet: from the bridge, or from a Codex session's own queue.

A session's **Close session** button (local sessions only) ends its process
after you confirm. A Codex session that runs inside a shared Codex app server
is not closed this way; close it in its terminal. From a shell:
is not closed this way; close it in its terminal. A session that holds root
has no Close button and is never closed by the bridge, on any path; the
answer is `<name> holds root; the bridge does not close or restart it`. End
it in its own terminal, or give root to another session and another role
(or none) to this one, and then close it. From a shell:
`session-bridge spawn <claude|codex> <role> [--project <name-or-path>]
[--model <model>] [--effort <effort>]` and `session-bridge close <session_id>`.

Expand All @@ -423,8 +427,9 @@ Only you assign root or start a root session; you can edit root's
instructions on the Roles tab but not rename or delete it. Root's own project
is its directory, not just a folder of the same name elsewhere. Root acts only
through the session you gave it (or the session started as root): another
session that takes the same name gets no root powers. Any program of your
account can still run `session-bridge spawn` and `close`, and the control
session that takes the same name gets no root powers and no protection from
a close. Any program of your account can still run `session-bridge spawn`
and `close` (a session that holds root is refused there too), and the control
socket does not prove which session is calling (only a started session's
claim is checked: it must come from its own launch process, on macOS and
Linux), and whoever runs a launch chooses the `claude` or `codex` program it
Expand Down Expand Up @@ -491,7 +496,9 @@ What a session was started with is kept in
session started before restarts existed, or not by the bridge, says it has no
launch record and cannot be restarted. Sessions sharing a process or running
in the Codex app server, and a paired laptop's sessions, are restarted where
they run. Only the admin page restarts sessions.
they run. A session that holds root is not restarted by the bridge: it has
no Restart action, and a request answers `<name> holds root; the bridge does
not close or restart it`. Only the admin page restarts sessions.

## Issues

Expand Down Expand Up @@ -692,6 +699,9 @@ The CLI derives sender identity from `CODEX_THREAD_ID`,
`CLAUDE_CODE_SESSION_ID`, or its Claude ancestor. A human shell without an agent
identity can list/status but cannot silently impersonate a sender.

Never end a root session's process (no kill, no closing its terminal); the
bridge refuses to close or restart it.

### Command reference

| Command | Purpose |
Expand All @@ -706,7 +716,7 @@ identity can list/status but cannot silently impersonate a sender.
| `session-bridge status` | Show the service state and recent messages |
| `session-bridge send <session_id> <message> [--project <name-or-path>]` | Send from an agent's shell tool |
| `session-bridge spawn <claude\|codex> <role> [--project <name-or-path>] [--model <model>] [--effort <effort>]` | Start a session with a role in a terminal |
| `session-bridge close <session_id>` | End a local session's process |
| `session-bridge close <session_id>` | End a local session's process (refused for a session that holds root) |
| `session-bridge network on [--port <n>] [--name <host>]` / `network off` | Announce this laptop on the local network and accept paired bridges |
| `session-bridge discover` | Bridges found on the network, paired or not |
| `session-bridge pair <host>` | Pair with a discovered laptop; type the code it shows |
Expand Down
7 changes: 4 additions & 3 deletions docs/requirements.md

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions docs/restart-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ The dialog
The restart
- R-1 Admin page only; the control socket, MCP and a phone are refused.
- R-2 Allowed for a live local session with a launch record, in a process of
its own that is not a Codex app server (as close, REQ-028). A root session
may be restarted by the user; root stays with its session id.
its own that is not a Codex app server (as close, REQ-028). A session that
holds root is refused before its launch record is looked at, so the answer
is the same with or without one: "<name> holds root; the bridge does not
close or restart it" (REQ-057, which replaces D-4).
- R-3 Everything is checked before anything happens (role, values, flags,
prompt, the session still live under the process id the dialog showed: a
stale one is refused, HTTP 409).
Expand Down Expand Up @@ -98,7 +100,9 @@ Page
refuses. Without a launch record the reason says exactly that: "No launch
record: this session was started before restarts existed, or not by the
bridge, so its start arguments are not known." The other reasons: shares
its process, runs in the Codex app server, on a paired laptop.
its process, runs in the Codex app server, on a paired laptop. A session
that holds root has no Restart action; its row says that it holds root
and is ended in its own terminal (REQ-057).
- P-2 While restarting, the session shows "restarting" (also in
`list_sessions` status), then its normal status.

Expand All @@ -111,10 +115,10 @@ Pure (unit and property tests):
`resume <thread>` plus run arguments (resume spellings) and the prompt
only when re-sent; no value is ever in a shell or AppleScript text
(REQ-028's launch).
2. AC-2: Each R-2 refusal (no launch record, shared process, app server,
paired laptop, not live) and each R-3 check (bad model, effort, flag,
prompt, unknown role, stale process id) is refused with its reason before
any process is signalled.
2. AC-2: Each R-2 refusal (holds root, no launch record, shared process,
app server, paired laptop, not live) and each R-3 check (bad model,
effort, flag, prompt, unknown role, stale process id) is refused with its
reason before any process is signalled.
3. AC-3: The restarting window: messages for a restarting session are not
refused as ended within 120 s; after 120 s without the session they are,
as REQ-038 says (property test over random timings).
Expand Down Expand Up @@ -159,8 +163,10 @@ Admin page (qa/ e2e, headless):
- D-3 First prompt. Recommend: not re-sent unless ticked (the conversation
already has it); when ticked, the edited text is sent as a new message in
the resumed conversation.
- D-4 Root. Recommend: the user may restart a root session; root stays bound
to its session id (unchanged by a resume). Agents never restart sessions.
- D-4 Root. Replaced by REQ-057 (the user, 2026-11-29): the bridge never
restarts a session that holds root. Before that: the user may restart a
root session; root stays bound to its session id (unchanged by a resume).
Agents never restart sessions.
- D-5 Messages. Recommend: a 120 s restarting window (the launch claim
window) in which the session is away, not ended.
- D-6 A process that does not exit. Recommend: stop after 10 s without
Expand Down
56 changes: 56 additions & 0 deletions qa/domains/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import { existsSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import type { Ctx, Domain } from "../framework/context";
import { openConversation } from "./chats";

const card = (project: string) => `article.project[data-project="${project}"]`;
const sessionRow = (id: string) => `tr[data-qa="project-session:${id}"]`;

async function openProject(ctx: Ctx, project: string) {
await ctx.open("projects");
Expand Down Expand Up @@ -98,6 +100,60 @@ export const projects: Domain = {
});
},

/** REQ-057: AC-3: the session that holds root has no Close and no
* Restart, in its Projects row (which says why) and in its conversation
* header; a session without root keeps both, and both come back once root
* is given away. Any page console error (holdsRoot is restart.js's) fails
* the run. */
root: async (ctx) => {
const project = ctx.uid("pr");
const [boss, mate] = [ctx.uid("boss"), ctx.uid("mate")];
const ids = await ctx.step("a session given root and one without", async () => {
const b = await ctx.bridge.addClaude(boss, project);
const m = await ctx.bridge.addClaude(mate, project);
await ctx.pageOk({ method: "assign_role", session_id: b.session_id, role: "root" });
return { boss: b.session_id as string, mate: m.session_id as string };
});
const offers = (id: string) => ctx.page.evaluate((sel: string) => {
const row = document.querySelector(sel);
const restart = row?.querySelector('[data-qa="project-restart"]') as HTMLElement | null;
return row ? { close: !!row.querySelector('[data-qa="project-close"]'), restart: !!restart && !restart.hidden, held: row.querySelector('[data-qa="project-holds-root"]')?.textContent ?? null } : null;
}, sessionRow(id));
await ctx.step("root's row offers neither and says why", async () => {
await openProject(ctx, project);
const v = await ctx.eventually("root's row marked", async () => {
const o = await offers(ids.boss);
return o?.held ? o : null;
});
ctx.expect(!v.close && !v.restart, `root's row: ${JSON.stringify(v)}`);
ctx.expect(v.held === "Holds root: the bridge does not close or restart it", `text: ${v.held}`);
});
await ctx.step("the other row keeps Close and Restart", async () => {
const v = await offers(ids.mate);
ctx.expect(!!v && v.close && v.restart && v.held === null, `other row: ${JSON.stringify(v)}`);
});
await ctx.step("root's conversation header offers neither; the other's keeps Close", async () => {
await openConversation(ctx, boss);
await ctx.page.hidden("#close-session");
await ctx.page.hidden('[data-qa="restart-session"]');
await openConversation(ctx, mate);
await ctx.page.visible("#close-session");
await ctx.page.visible('[data-qa="restart-session"]');
});
await ctx.step("root given away: its row and header offer Close and Restart again", async () => {
await ctx.pageOk({ method: "assign_role", session_id: ids.boss, role: "reviewer" });
await openProject(ctx, project);
const v = await ctx.eventually("the former root's row unmarked", async () => {
const o = await offers(ids.boss);
return o && o.held === null ? o : null;
});
ctx.expect(v.close && v.restart, `former root's row: ${JSON.stringify(v)}`);
await openConversation(ctx, boss);
await ctx.page.visible("#close-session");
await ctx.page.visible('[data-qa="restart-session"]');
});
},

/** REQ-040: the star button stars and unstars a project; starred projects
* come first, then live ones, then by name; stars.json changes only when
* a star does; the control socket cannot star. */
Expand Down
1 change: 1 addition & 0 deletions src/admin/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ td:last-child { text-align: right; white-space: nowrap; }
.project__sessions td:not(:first-child) { color: var(--muted); white-space: nowrap; }
.project__sessions td:last-child { text-align: right; }
.project__name { margin-right: 6px; font-weight: 600; }
.project__held { font-size: 12px; color: var(--muted); }
.project__sessions .badge + .badge { margin-left: 4px; }
.project__spawn { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.project__spawn > label { flex: 1 1 12rem; min-width: 0; }
Expand Down
22 changes: 16 additions & 6 deletions src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,10 @@ function renderSessionActions(known) {
const local = party?.session && !party.session.host && party.session.agent !== "user";
$("spawn-open").hidden = !project;
if (!project) $("spawn-form").hidden = true;
$("close-session").hidden = !local;
// REQ-057: nothing closes the session that holds root. holdsRoot, like
// setRestartButton, comes from restart.js, loaded after this file: both
// are deferred, and renders start on DOMContentLoaded, after both ran.
$("close-session").hidden = !local || holdsRoot(party.session);
// REQ-049: offered from the session's view (restart.js).
setRestartButton($("restart-session"), local ? party.session : null, () => $("composer-hint"));
const chat = selected?.kind === "dm" || selected?.kind === "channel";
Expand Down Expand Up @@ -1968,11 +1971,18 @@ function renderProjects() {
if (s.name === project.master) name.append(badge(masterWord.toLowerCase(), "master"));
row.append(name, cell(s.agent), cell(s.status));
const actions = document.createElement("td");
const close = element("button", "button button--danger schedule__action", "Close");
close.type = "button";
close.dataset.qa = "project-close";
close.addEventListener("click", () => closeFromProjects(s));
actions.append(restartRowButton(s), close);
if (holdsRoot(s)) {
// REQ-057: no Close or Restart for the session that holds root.
const held = element("span", "project__held", "Holds root: the bridge does not close or restart it");
held.dataset.qa = "project-holds-root";
actions.append(held);
} else {
const close = element("button", "button button--danger schedule__action", "Close");
close.type = "button";
close.dataset.qa = "project-close";
close.addEventListener("click", () => closeFromProjects(s));
actions.append(restartRowButton(s), close);
}
row.append(actions);
body.append(row);
}
Expand Down
12 changes: 9 additions & 3 deletions src/admin/restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ const RESTART_WINDOW_MS = 120_000;
// The listing's status for a restart that did not come back (REQ-049 M-2).
const RESTART_LOST = "did not come back";

/** Whether the listing marks `session` as holding root (REQ-057): the page
* offers neither Close nor Restart for it. */
function holdsRoot(session) {
return session?.restart?.holds_root === true;
}

/** What the session view offers (REQ-049 P-1): null when it says nothing
* (an older bridge, the user, another laptop's session), else
* { ok } or { ok: false, reason }. */
* (an older bridge, the user, another laptop's session, the session that
* holds root), else { ok } or { ok: false, reason }. */
function restartOffer(session) {
if (!session || session.host || session.agent === "user" || !session.restart) return null;
if (!session || session.host || session.agent === "user" || !session.restart || holdsRoot(session)) return null;
if (session.status === "restarting") return { ok: false, reason: `${session.name} is restarting.` };
return session.restart.ok ? { ok: true } : { ok: false, reason: String(session.restart.refused ?? "") };
}
Expand Down
6 changes: 6 additions & 0 deletions src/codex_wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ use serde_json::{Value, json};
use std::path::{Path, PathBuf};
use uuid::Uuid;

mod thread;
pub use thread::{
Interrupt, StartedThread, ThreadFailure, create_thread, interrupt, started_thread,
thread_name_set, thread_start, turn_interrupt,
};

/// The queued submission id `codex queue` prints:
/// "Queued message <id> for thread <thread>."
pub fn queued_submission(stdout: &str) -> Option<String> {
Expand Down
Loading
Loading