Skip to content

A folder can have several Sonny leads: the last one written to opens, /lead switches - #365

Merged
lydakis merged 9 commits into
mainfrom
claude/project-thread-0hljhk
Oct 29, 2026
Merged

lydakis merged 9 commits into
mainfrom
claude/project-thread-0hljhk

Conversation

@lydakis

@lydakis lydakis commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Before this, a folder had exactly one lead, PROJECT.lead, and every Sonny window and every T3 Code thread opened there drove it. A fresh T3 thread in Errand opened in the middle of errand.lead's ~576k tokens of old history. This PR is option A from the design page: named peer leads.

Names

  • The first lead keeps PROJECT.lead. Another lead is PROJECT.lead.NAME, where NAME is lowercase letters, digits and hyphens, at most 32, and never side-…, so side chats stay apart. They are peers: no lead watches or outranks another.
  • project::lead_project / is_lead replace the strip_suffix(".lead") checks in served, declared, background, calls, task, acp and main (show, kin, the side source, --bot).
  • start_task refuses a task name that names a lead.

Opening and switching

  • sonny in a folder opens the lead the person last wrote to there. A TUI or ACP prompt notes it under ~/.agent/sonny/last-lead/, and with no note the first lead opens.
  • sonny --lead NAME opens one, and sonny --new-lead [NAME] makes one (numbered lead.2… without a name).
  • /lead lists the folder's leads, /lead NAME switches, and /lead new [NAME] makes one and switches. The window re-execs itself on --bot that lead, as if opened on it.
  • client::project::create takes the lead to make in place of the coordinator (the unused after parameter goes).

T3 Code

  • A new thread is a new lead, named after its first words (for example errand.lead.fix-the-login-redirect), or the first lead when the folder has none yet.
  • A first message of /lead NAME or /lead new [NAME] binds the thread to that lead instead and ends the prompt.
  • Resumed threads and task threads are unchanged.

Two leads at once

  • Lookout: an extra lead's tasks subscription is lineage only. The first lead keeps its PROJECT.* name glob, so a bot no agent made still reaches someone, but the glob skips the other leads and everything they or theirs made (theirs).
  • Window and /status: when the folder has other leads, a window lays out and lists only its lead's lineage (lineage_of). The other leads show as rows (first lead, lead billing). kin never takes another lead of the folder as a task, and a bot named like the project goes to the first lead only when no agent made it.
  • lead.md: the other leads' tasks are theirs, so work goes through their lead. A lead checks their tasks before starting one, leaves changes it didn't make alone, and never switches the folder's branch. The task rule now reads "only this folder's leads work in it".
  • task.md: a task finds its lead as created_by, not ${AGENT_BOT%%.*}.lead.

The daemon doesn't change. Single-lead folders behave as before: one lead, the same name glob, and a reconcile that only switches to lineage once another lead appears.

Not in this PR

  • A model-picked name: names come from the first words.
  • The overlap notice for two leads' tasks touching the same files.
  • /lead rm.
  • A grouped tree in /status.

Tests

cargo test -p sonny -p agent-client, clippy with -D warnings, and fmt all pass locally. New tests cover lead names, thread names, kin and lineage_of with two leads, and Sub::lead for an extra lead.

@lydakis lydakis self-assigned this Oct 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T08:29:49.004397Z d996fb9 New commits
🔒 Security Review ✅ Completed 2026-10-29T08:32:23.182247Z d996fb9 New commits
ℹ️ 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.

@lydakis
lydakis force-pushed the claude/project-thread-0hljhk branch from e9be12c to 4b6f861 Compare October 29, 2026 06:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9be12ceb4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/main.rs Outdated
}
let named = std::env::args().any(|arg| arg == "--bot");
match project::lead_project(bot) {
Some(_) if !named && bot.ends_with(".lead") => {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pin the first lead in its generated resume command

When Sonny opens the first lead without --bot (including with --lead lead), this branch generates a resume command with neither --bot nor --lead. Herdr and cmux persist that command to restore the pane after a restart. If the person subsequently writes to another lead in the folder, the restored first-lead pane instead opens that other lead through Pick::Last, silently changing its conversation. Include the first lead's identity in the resume command just as for named leads.

AGENTS.md reference: AGENTS.md:L32-L32

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in bdef2d5: the resume command names every lead with --lead, the first (--lead lead) included.


Generated by Claude Code

Comment thread sonny/src/project.rs Outdated
Comment on lines +587 to +590
let name = match stem {
"" => n.to_string(),
stem => format!("{stem}-{n}"),
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reserve suffix space when generating duplicate thread names

When two new ACP threads have the same opening words and those words generate a 31- or 32-character stem, appending -2 produces a name longer than the 32-character limit. For example, Investigate authentication issue generates the valid stem investigate-authentication-issue, but the next thread generates a 34-character name that make rejects with lead_invalid. This prevents the second thread's prompt from running. Truncate the stem to leave room for the numeric suffix before checking availability.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in bdef2d5: free cuts the stem so -N fits in 32.


Generated by Claude Code

Comment thread sonny/src/project.rs Outdated
Comment on lines +573 to +577
create(client, &dir, model, Some(&bot)).await?;
Ok(Lead {
project,
bot,
new: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require exclusive creation before binding a new thread

If two ACP threads concurrently submit opening prompts with the same generated stem, both can pass the preceding find check before either creates the bot. agent_client::project::create intentionally returns an existing bot with created: false, including when its daemon create request loses a race, but this create wrapper discards that result and both callers report new: true. Consequently, supposedly independent new threads bind to the same conversation, where their prompts can steer one another or fail as busy. Preserve the creation result and retry with another available name when a new-thread creation loses the race.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in bdef2d5: create reports whether it made the bot. A lead found there instead is lead_exists, and a new thread or an unnamed /lead new takes the next free name (up to 8 tries).


Generated by Claude Code

@lydakis
lydakis force-pushed the claude/project-thread-0hljhk branch from bdef2d5 to 5f46445 Compare October 29, 2026 06:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f46445b34

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/project.rs Outdated
Comment on lines +542 to +545
if let Pick::Named(name) = pick
&& lead_bot(&project, name) != first
{
return Err(format!("lead_missing: {project} has no lead {name} yet"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve existing named leads before requiring the first lead

If shop.lead is deleted while shop.lead.billing remains, sonny --lead billing now reports lead_missing without looking up the existing billing lead. This also prevents an ACP thread from opening that conversation with /lead billing. Named conversations should remain resumable independently of the first lead's lifetime; look up the requested lead before concluding that it is missing.

AGENTS.md reference: AGENTS.md:L32-L32

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 31dfbaa. When the first lead is gone, a named pick now looks up P.lead.NAME in this folder and opens it. test_acp deletes calc.lead and then adopts /lead again to check this.


Generated by Claude Code

Comment thread sonny/src/lookout/mod.rs Outdated
Comment on lines 1412 to 1413
&& !self.theirs.contains(bot)
&& (self.subs.iter()).any(|sub| sub.bots.iter().any(|glob| subs::matches(glob, bot)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor explicit subscriptions to another lead in the folder

When shop.lead explicitly subscribes to {"name":"billing","bots":["shop.lead.billing"]}, the new theirs check excludes that bot before the subscription can match. Consequently, the subscription is accepted and listed but never delivers the billing lead's messages or completed turns. This contradicts the explicit-name behavior documented in docs/LOOKOUT.md and the subscriptions tool description in sonny/src/served.rs. Restrict the sibling exclusion to implicit task coverage, allowing an explicit subscription to watch the named lead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 27ee29a. Sibling leads are now left out only of the tasks subscription Sonny gives a lead. A subscription the lead asks for that names another lead hears it. Test: another_lead_and_its_tasks_are_heard_only_when_asked_for.


Generated by Claude Code

@lydakis
lydakis force-pushed the claude/project-thread-0hljhk branch 2 times, most recently from 31dfbaa to bb58487 Compare October 29, 2026 07:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb58487918

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/main.rs
let name = bot["name"].as_str().unwrap_or("");
name != self.lead && project::lead_project(name) == Some(self.project.as_str())
});
let mine = shared.then(|| lineage_of(&bots, &self.lead, first));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep named leads lineage-scoped when the first lead is deleted

If the first lead is deleted while a named lead and their tasks remain, reopening the named lead makes shared false, so mine is disabled and reconciliation inserts every project task into that lead's lineage. Running tasks belonging to the deleted first lead then open in the surviving lead's layout, and subsequent events are treated as its tasks. The same conditional in status_rows also shows those unrelated tasks. Apply lineage filtering whenever the current lead is a named lead, even if no sibling lead is currently listed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in b0de9b9: a lead other than the first always keeps to its own lineage, in the window and in /status, whether or not other leads are listed.


Generated by Claude Code

Comment thread sonny/src/project.rs
Comment on lines +174 to +175
.join(".agent/sonny/last-lead")
.join(fingerprint(&dir.to_string_lossy())),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Namespace the last-lead record by daemon or store

When the same folder is used with two stores under one HOME, both stores share this record because its key contains only the folder path. Writing to shop.lead.billing in store A therefore changes what Sonny selects in store B. If store B contains only shop.lead, opening Sonny there now fails with lead_missing because Pick::Last selects the nonexistent billing lead without a fallback; if both stores contain billing leads, it instead selects a conversation that was not last used in store B. Include the daemon or store identity in the record's namespace, as the multiplexer place records already do.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Partly fixed in b0de9b9: when the last-used note names a lead this store doesn't have, the first lead opens instead of lead_missing. Keying the note by store is logged as #368.


Generated by Claude Code

Comment thread sonny/src/project.rs Outdated
let make = |bot: String| {
let (dir, project) = (dir.clone(), project.clone());
async move {
if !lead_named(lead_short(&bot)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the entire requested lead name before creating it

With an existing first lead, requesting /lead new billing.api passes this check because lead_short("shop.lead.billing.api") returns only api. The bot is then created successfully, but lead_project does not recognize it as a lead: it disappears from /lead listings, prompts do not record it as the last-used lead, and reopening its TUI or resuming its ACP thread treats it as a non-lead. Validate the complete requested suffix against lead_named, rather than only its final dot-separated component, before creating the bot.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in ce12dae: make now checks the whole name after P.lead., so billing.api is lead_invalid.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce12dae653

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/project.rs
Comment on lines +559 to +563
create(client, &dir, model, None).await?;
return Ok(Lead {
project,
bot,
new: false,
moving,
above: None,
bot: first,
new: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve the last-used lead before recreating a missing first lead

If the person last wrote to shop.lead.billing and subsequently deletes shop.lead, opening Sonny without flags creates a fresh shop.lead instead of resuming the surviving billing conversation. Pick::Last only reads the last-lead record below this early return, so it never checks that record when the first lead is missing. Resolve the recorded lead in this branch before deciding that a new first lead is needed.

AGENTS.md reference: AGENTS.md:L32-L32

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in dd99b1d: when the first lead is missing, Pick::Last checks the last-used lead first. If that lead is in this folder, it opens, and a new first lead is made only when it isn't.


Generated by Claude Code

… /lead switches

The folder's first lead stays PROJECT.lead; another is PROJECT.lead.NAME, a
peer with its own conversation and tasks. `sonny` opens the lead the person
last wrote to there (from the TUI or T3 Code), `--lead NAME` opens one,
`--new-lead [NAME]` makes one, and `/lead`, `/lead NAME` and `/lead new
[NAME]` do the same from a window, which reopens on the lead it switches to.

In T3 Code a new thread is a new lead, named after its first words, unless
the folder has none yet or the first message is `/lead NAME`.

Each lead hears and shows only its own tasks: an extra lead's lookout
subscription is by lineage alone, the first lead's name glob skips the
other leads and theirs, and a window's tasks and /status follow lineage
when the folder has other leads. lead.md says the other leads' tasks are
theirs and not to switch the folder's branch; task.md finds its lead by
created_by.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
@lydakis
lydakis force-pushed the claude/project-thread-0hljhk branch from dd99b1d to d996fb9 Compare October 29, 2026 08:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d996fb99f2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/lookout/mod.rs
Comment on lines +1390 to +1394
self.theirs = (records.keys())
.filter(|name| self.sibling(name))
.cloned()
.collect();
grow(&mut self.theirs, records);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve sibling task exclusions after their lead is deleted

If shop.lead.billing is deleted while its task shop.invoices survives, a subsequent subscription reload calls roots and rebuilds theirs exclusively from leads still present in records. The deleted billing lead is no longer a seed, so grow cannot classify its surviving tasks, and the first lead's shop.* subscription starts delivering their messages and completions to shop.lead. Preserve these exclusions across subscription reloads, or seed them from surviving tasks' sibling-lead creator identities, so deleting a lead does not transfer its conversations to another lead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This one happens only after a lead is deleted while its tasks are still there. It's logged in #368 for a follow-up, so this PR can make the release.


Generated by Claude Code

@lydakis
lydakis merged commit 22fb427 into main Oct 29, 2026
4 checks passed
lydakis added a commit that referenced this pull request Oct 29, 2026
…of its own (#374)

#365 let a folder have several leads but left the README saying a folder
has one and a T3 Code thread is that one. The README now gives --lead,
--new-lead and /lead, what each lead hears and is told, and how a new
T3 Code thread picks its lead; LOOKOUT.md says what another lead's tasks
subscription holds.


Claude-Session: https://claude.ai/code/session_013jkdGH7ReQfFZ1hChr3jXE

Co-authored-by: Claude <[email protected]>
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