Skip to content

Support child threads whose parent lives in another project - #1849

Merged
SawyerHood merged 4 commits into
mainfrom
bb/support-cross-project-child-threads-thr_yhtwdhmkiw
Aug 18, 2026
Merged

SawyerHood merged 4 commits into
mainfrom
bb/support-cross-project-child-threads-thr_yhtwdhmkiw

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What was wrong

assertValidParentThread compared the parent's projectId with the new thread's projectId and threw 400 parent_thread_invalid (wrong_project). An agent that ran bb thread spawn --project <other> --parent-self from a thread in another repository could not create the child, and so the child could not report back to its parent. Cross-project delegation was blocked end to end. Issue #1711.

What changed

Server

  • apps/server/src/services/threads/thread-parent.ts: assertValidParentThread and isLiveParentThread no longer compare projects. wrong_project is removed from parentThreadInvalidReasonSchema in packages/server-contract/src/errors.ts and from the app copy in lifecycle-errors.ts. Forks and side chats stay same-project through requireLiveSourceThread. Reparent via PATCH /threads/:id gets the same relaxation.
  • thread-default-policy.ts: the permission ceiling stays cross-project (a child in project B still clamps to its parent's mode). A cross-project child gets its own project's managed worktree by default and never reuses a personal parent environment from another project.
  • packages/sdk/src/areas/status.ts: bb status lists children by parent only, so cross-project children appear.
  • No daemon payload changes, so no HOST_DAEMON_PROTOCOL_VERSION bump.

App

  • projectThreadGroups.ts: new resolveSidebarProjectId files each thread under its root ancestor's project. ProjectList.tsx uses it, so a cross-project child stays nested under its parent in "By project" mode and does not appear as a root in its own project group.
  • ThreadRow.tsx: new required crossProjectId prop. When set, the row shows a FolderExport marker after the title (nudged 1px down to sit on the text) with a Radix tooltip "In project ". ProjectRow.tsx always routes and keys drafts by the thread's own project and passes the parent's project down the tree.
  • ThreadDetailView.tsx: children query by parent only (useChildThreads); parent links route through the parent's own project. ThreadMetadataContent.tsx gets parentThreadProjectId for the same reason.
  • icon.tsx: FolderExport registered. New Ladle story "parent with a child from another project".

Docs

  • bb-cli skill and bb-guide-threads.md: a parent may live in another project; --parent-self works with a different --project.

Deliberate semantics

  • Archive of a parent still cascades to children in other projects (hierarchy semantic unchanged).
  • The parent selector in thread metadata still offers same-project parents only; cross-project parents come from the CLI/SDK first.

How you verified

Tests added (fail before, pass after):

  • thread-parent.test.ts: a live parent from another project is accepted.
  • thread-default-policy.test.ts: cross-project child keeps the parent's permission ceiling; gets a managed worktree; does not reuse a foreign personal environment.
  • public-thread-parenting.test.ts: create + reparent across projects, list by parent returns both children, sidebar bootstrap files the child under its own project.
  • projectThreadGroups.test.ts: resolveSidebarProjectId root-ancestor, orphan fallback, cycle guard.
  • ThreadRow.test.tsx: marker present with project name and outside the trailing slot, route uses the child's project; no marker for same-project rows.

Commands:

  • pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/server --filter=@bb/sdk --filter=@bb/shared-ui --filter=@bb/server-contract --filter=@bb/cli --filter=@bb/templates — pass
  • server: test/threads, public-thread-parenting, public-threads.defaults, public-thread-data — 332 passed; server-contract — 57 passed
  • app: components/sidebar, views/thread-detail, hooks/queries — 451 passed
  • turbo lint --filter=@bb/app — 147 warnings, same as main (0 new)

Manual (dev app + dev-browser): created projects api and web; spawned a parent in api and a child in web with --parent-thread (was a 400). The child ran in a web worktree, shows nested under its parent with the marker and "In project web" tooltip, and reported child-completed to the parent. bb status from the parent lists both children.

Fixes #1711

AGENT GENERATED: by Claude Opus 5

@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

I will post one final review after the parallel checks finish.

SawyerHood and others added 2 commits August 18, 2026 23:22
Agents delegate work across repositories, but thread creation rejected a
parent from a different project with 400 parent_thread_invalid
(wrong_project). Relax the hierarchy check while keeping the parent's
permission ceiling; forks and side chats stay same-project.

Sidebar: "By project" now files each thread under its root ancestor's
project so a cross-project child stays nested under its parent, and the
row shows a FolderExport marker with an "In project <name>" tooltip.
Thread detail lists children by parent only and routes parent links
through the parent's own project. `bb status` lists cross-project
children.

Fixes #1711

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/support-cross-project-child-threads-thr_yhtwdhmkiw branch from 7d71cfd to 5b2f88d Compare August 18, 2026 23:22
if (effectivePinnedThreadIds.has(thread.id)) continue;
const existing = grouped.get(thread.projectId);
// Cross-project children render under their parent's project group.
const sidebarProjectId = resolveSidebarProjectId(thread, threadById);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — The sidebar can hide the selected cross-project child.

This code groups the child under the root parent project.

The selection effect still expands selectedThread.projectId at line 345.

If the root project is collapsed, direct navigation selects a hidden row.

Use the resolved sidebar project for selection expansion.

Add a collapsed-project test.

return useQuery<ThreadListResponse>({
queryKey:
enabled && parentThreadId
? threadListQueryKey({ archived: false, parentThreadId })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Unrelated project changes refetch every active child list.

This parent-only key enters the global thread-list family.

Realtime logic invalidates all global keys after a change in any project.

Each active detail pane then sends a new child request.

Use a dedicated child-list key.

Invalidate only the changed thread's current or previous parent.

thread: ThreadListEntry,
threadById: ReadonlyMap<string, ThreadListEntry>,
): string {
const visitedThreadIds = new Set<string>([thread.id]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Root-project resolution repeats work for every thread.

ProjectList calls this helper for each thread.

The helper allocates a Set and repeats ancestor walks.

At 32,767 depth-four threads, the measured pass took 17.58 ms before the ID map.

Cache resolved root projects and reuse ancestor results.

The code already limits the hierarchy to four levels.

aria-label={crossProjectLabel}
// Sits above the row's full-size link so it can take hover;
// nudged 1px down so the glyph reads centered on the text.
className="relative top-px z-10 flex shrink-0 items-center text-muted-foreground"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — A click on the project marker does not open the thread.

The z-10 sibling sits above the full-row link.

A pointer click on the marker opens no thread.

Make the marker part of the link, or forward the row navigation.

Add a marker-click test.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

Plain English summary

This PR lets an agent create a child thread in one project while its parent stays in another.

The child keeps its own project and workspace.

The sidebar nests the child under its parent and marks the child's project.

Findings

  • Medium: The sidebar expands the child's project, but it renders the child under the root parent's project.

    A collapsed root project can therefore hide the selected row.

  • Medium: Each active child-list query uses the global thread-list family.

    An unrelated project change can refetch every active child list.

  • Medium: Project grouping resolves the root project separately for every thread.

    The measured pass took 17.58 ms for 32,767 depth-four threads, before the new ID-map cost.

  • Medium: The cross-project marker sits above the row link.

    A click on the marker does not open the thread.

Architecture

The sidebar computes ancestry during project grouping, selection expansion, and tree construction.

A shared ancestry map can remove this duplication and prevent policy differences.

Security and verification

I found no security issue.

  • All 54 focused server tests passed.

  • All 106 focused app tests passed.

  • The app, server, and SDK Turbo typechecks passed.

  • git diff --check passed.

  • The browser test created a parent and child in separate projects.

  • Both agents completed, and the child used the correct child-project worktree.

  • The browser showed correct nesting, the project marker, the child route, and the parent route.

The final GPT-5.6 review gate confirmed all four issues.

I posted this as a comment-only review. I did not approve or request changes.

…p, forward marker clicks

- Selection auto-expand now targets the project group that renders the
  selected thread (its root ancestor's project), so a directly opened
  cross-project child is never hidden under a collapsed group.
- createSidebarProjectIdResolver memoizes ancestor walks per sidebar pass.
- A click on the cross-project marker forwards to the row link so it opens
  the thread instead of being a dead zone.

Co-Authored-By: Claude <[email protected]>
@SawyerHood

Copy link
Copy Markdown
Collaborator Author

Addressed three of the four SlopCop findings in dad17e9:

  • Hidden selected child: getSelectedThreadSidebarExpansion now takes the resolved sidebar project (root ancestor's project) instead of selectedThread.projectId. Test added.
  • Repeated ancestor walks: createSidebarProjectIdResolver memoizes per sidebar pass; each chain is walked once. Test asserts lookup counts.
  • Marker click dead zone: the marker forwards its click to the row link. Test added; verified in the browser.

The child-list query-key finding (global thread-list family invalidation) is real but pre-dates this PR in shape (useProjectThreadSubset used the same family). I will take it as a follow-up with a dedicated child-list key and parent-scoped invalidation.

AGENT GENERATED: by Claude Opus 5

@SawyerHood
SawyerHood merged commit d0e0bf5 into main Aug 18, 2026
12 checks passed
@SawyerHood
SawyerHood deleted the bb/support-cross-project-child-threads-thr_yhtwdhmkiw branch August 18, 2026 23:49
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.

Cross-project child thread creation rejects a valid parent thread

1 participant