Repository navigation
A folder can have several Sonny leads: the last one written to opens, /lead switches - #365
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
e9be12c to
4b6f861
Compare
There was a problem hiding this comment.
💡 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".
| } | ||
| let named = std::env::args().any(|arg| arg == "--bot"); | ||
| match project::lead_project(bot) { | ||
| Some(_) if !named && bot.ends_with(".lead") => {} |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Fixed in bdef2d5: the resume command names every lead with --lead, the first (--lead lead) included.
Generated by Claude Code
| let name = match stem { | ||
| "" => n.to_string(), | ||
| stem => format!("{stem}-{n}"), | ||
| }; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
| create(client, &dir, model, Some(&bot)).await?; | ||
| Ok(Lead { | ||
| project, | ||
| bot, | ||
| new: true, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
bdef2d5 to
5f46445
Compare
There was a problem hiding this comment.
💡 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".
| if let Pick::Named(name) = pick | ||
| && lead_bot(&project, name) != first | ||
| { | ||
| return Err(format!("lead_missing: {project} has no lead {name} yet")); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
| && !self.theirs.contains(bot) | ||
| && (self.subs.iter()).any(|sub| sub.bots.iter().any(|glob| subs::matches(glob, bot))) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
31dfbaa to
bb58487
Compare
There was a problem hiding this comment.
💡 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".
| 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
| .join(".agent/sonny/last-lead") | ||
| .join(fingerprint(&dir.to_string_lossy())), |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
| let make = |bot: String| { | ||
| let (dir, project) = (dir.clone(), project.clone()); | ||
| async move { | ||
| if !lead_named(lead_short(&bot)) { |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Fixed in ce12dae: make now checks the whole name after P.lead., so billing.api is lead_invalid.
Generated by Claude Code
There was a problem hiding this comment.
💡 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".
| create(client, &dir, model, None).await?; | ||
| return Ok(Lead { | ||
| project, | ||
| bot, | ||
| new: false, | ||
| moving, | ||
| above: None, | ||
| bot: first, | ||
| new: true, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
…ext name, and a restored pane names its lead Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
…lder's lead with /lead Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
…for hears it Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
…hen the first is gone Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGFFmteuHGN4MViNPqg
dd99b1d to
d996fb9
Compare
There was a problem hiding this comment.
💡 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".
| self.theirs = (records.keys()) | ||
| .filter(|name| self.sibling(name)) | ||
| .cloned() | ||
| .collect(); | ||
| grow(&mut self.theirs, records); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
…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]>
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 oferrand.lead's ~576k tokens of old history. This PR is option A from the design page: named peer leads.Names
PROJECT.lead. Another lead isPROJECT.lead.NAME, where NAME is lowercase letters, digits and hyphens, at most 32, and neverside-…, so side chats stay apart. They are peers: no lead watches or outranks another.project::lead_project/is_leadreplace thestrip_suffix(".lead")checks in served, declared, background, calls, task, acp and main (show,kin, the side source,--bot).start_taskrefuses a task name that names a lead.Opening and switching
sonnyin 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 NAMEopens one, andsonny --new-lead [NAME]makes one (numberedlead.2… without a name)./leadlists the folder's leads,/lead NAMEswitches, and/lead new [NAME]makes one and switches. The window re-execs itself on--botthat lead, as if opened on it.client::project::createtakes the lead to make in place of the coordinator (the unusedafterparameter goes).T3 Code
errand.lead.fix-the-login-redirect), or the first lead when the folder has none yet./lead NAMEor/lead new [NAME]binds the thread to that lead instead and ends the prompt.Two leads at once
taskssubscription is lineage only. The first lead keeps itsPROJECT.*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).lineage_of). The other leads show as rows (first lead,lead billing).kinnever 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.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
/lead rm.Tests
cargo test -p sonny -p agent-client, clippy with-D warnings, and fmt all pass locally. New tests cover lead names, thread names,kinandlineage_ofwith two leads, andSub::leadfor an extra lead.