Skip to content

fix(agent): keep a catbus tab's session through restarts, and make claude-only agent-only - #70

Merged
williamdes merged 3 commits into
mainfrom
claude/mobile-render-agent-fixes-3je33h
Nov 16, 2026
Merged

williamdes merged 3 commits into
mainfrom
claude/mobile-render-agent-fixes-3je33h

Conversation

@williamdes

Copy link
Copy Markdown
Member

Catbus tabs were not restored

A catbus tab came back from a restart on the wrong session, or as a bare shell, because other processes running in the tab spoke for it.

  • Every catbus-agent process reported itself. A --prompt-file review started by a git hook, a --once run and a spawned sub-agent each inherit the tab's environment and mint their own session id, so each replaced the id the app resumes with. Only the interactive session reports now (applink::owns_the_tab). --no-tui sessions still report, since a tab can host one.
  • A claude started inside a catbus tab fires the system-wide Claude hooks. Its SessionStart replaced the tab's session id (and, on the desktop, its kind), and its SessionEnd wiped the attachment. The GUI and headless owners now share one rule, report_may_touch_attachment, which refuses a wrapped agent's word on the attachment; the GUI had no guard before. claude-hook session-end now names its kind so the wipe can be refused, and the status endpoint keeps the reporter's kind on a wipe for that purpose.

catbus-agent still does not execute the /etc/claude-code hooks: they would stamp the tab as claude and resume the wrong binary.

Claude-only becomes agent-only

The setting now takes claude or catbus.

Surface New
Preference agent_only: "claude" | "catbus"
Launch flag --agent-only <claude|catbus>
CLI verb agent-only claude|catbus|off
API POST /agent-only with {"agent": "claude"|"catbus"|"off"}
Menu one entry per agent; "New bash tab" still cancels

The old names (--claude-only, claude-only on|off, POST /claude-only) are removed, not aliased. A preferences file with claude_only: true is read as agent_only: "claude" and the old key is not written back.

Verification

  • cargo test (GUI default): 1572 passed, 0 failed
  • cargo test --no-default-features --features headless,energy,catbus: 1464 passed, 0 failed
  • cargo test -p catbus-agent: all passed
  • cargo clippy --all-targets: clean for the code touched here. With the newer toolchain this was run on, it still fails on four older lints in files this PR does not change (tab-atelier-api/src/respond.rs, catbus-agent/src/cost.rs, src/api.rs:3933, examples/transcript-compact.rs); not checked on the pinned rustc 1.92.

The app itself was not launched.


Generated by Claude Code

…aude-only agent-only

A catbus tab came back from a restart on the wrong session, or as a bare
shell, because other processes in the tab spoke for it:

- every catbus-agent run reported its own session id, including a
  --prompt-file review started by a git hook, a --once run and a spawned
  sub-agent; only the interactive session reports now
- a claude started inside a catbus tab fires the system-wide Claude hooks:
  its SessionStart replaced the tab's session id (and, on the desktop, its
  kind) and its SessionEnd wiped the attachment. Both owners now share one
  rule that refuses a wrapped agent's word on the attachment, and
  session-end names its kind so the wipe can be refused

The claude-only setting becomes agent-only and takes claude or catbus:
preference agent_only, flag --agent-only <agent>, verb agent-only
claude|catbus|off, POST /agent-only, and one menu entry per agent. The old
names are removed; a preferences file with claude_only: true is read as
agent_only: claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G6dpqPucDGns6rELSQeSdr
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;

/// Set once at start-up by a process that is in a tab without being the tab's agent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What if user does mix no tui sessions and normal dessions in the tab lifetime?
Does it stay coherent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not fully, as first pushed — good catch. Three cases:

  • One after another (TUI session ends, then a --no-tui one starts, or the reverse): coherent. The last one started is the tab's session. One caveat that this PR does not change: the app restores with catbus-agent --resume <id> only, so a --no-tui session comes back with its conversation but as a TUI.
  • A --no-tui session started behind the tab's agent (from a tool call, say): this was broken. Both reported, and each took the tab's session id back on its next turn. Fixed in 1b992a3: only a session whose stdin is the tab's terminal reports (owns_the_tab now takes on_terminal). 9f6bbe1 gives the existing abandoned-turn test's agent a terminal, since it models a tab's own process.
  • Two sessions that both hold the terminal (one backgrounded with & in the tab's shell): still last-report-wins. I left that alone; telling them apart needs the foreground process group, which means unsafe or a new dependency in a crate that denies unsafe.

catbus-agent: clippy clean, 649 tests pass.


Generated by Claude Code

… tab

A --no-tui session started behind the tab's own agent, from a tool call,
inherits the tab's environment and reported its own session id. The two
then traded the tab's session back and forth, each taking it on its next
turn. A session whose stdin is not a terminal is not the one a person is
at, so it stays silent.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G6dpqPucDGns6rELSQeSdr
The test's agent reports to the app as a tab's own process would, and only a
session holding the tab's terminal speaks for the tab now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G6dpqPucDGns6rELSQeSdr
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.46512% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.29%. Comparing base (d18b0c7) to head (9f6bbe1).

Files with missing lines Patch % Lines
src/app.rs 0.00% 71 Missing ⚠️
src/lib.rs 70.73% 24 Missing ⚠️
src/main.rs 0.00% 3 Missing ⚠️
src/api/agent_only.rs 85.71% 2 Missing ⚠️
src/cli/share_link.rs 91.30% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main      #70    +/-   ##
========================================
  Coverage   80.28%   80.29%            
========================================
  Files         248      248            
  Lines       76107    76232   +125     
========================================
+ Hits        61103    61207   +104     
- Misses      15004    15025    +21     
Flag Coverage Δ
rust 80.29% <60.46%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member Author

codecov/patch is failing at 60.5% against an 80.3% target. Most of the 102 uncovered lines are in src/app.rs (71 lines): the GUI menu entries, the tab-open path and the agent-only mode setter, which no test harness reaches. The rest is in src/lib.rs and the new CLI/API glue. main has no branch protection, so this is not a merge gate. I have not added tests for the GUI path. Tell me if you want tests for the lib.rs and CLI parts before merging.


Generated by Claude Code

@williamdes
williamdes merged commit 6a62b16 into main Nov 16, 2026
3 of 4 checks passed
@williamdes
williamdes deleted the claude/mobile-render-agent-fixes-3je33h branch November 16, 2026 08:44
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.

2 participants