Skip to content

fix: match root planner by exact name in kickoff dedupe#113

Open
Mubashirrrr wants to merge 1 commit into
cursor:mainfrom
Mubashirrrr:fix/kickoff-dedupe-prefix-collision
Open

fix: match root planner by exact name in kickoff dedupe#113
Mubashirrrr wants to merge 1 commit into
cursor:mainfrom
Mubashirrrr:fix/kickoff-dedupe-prefix-collision

Conversation

@Mubashirrrr
Copy link
Copy Markdown

@Mubashirrrr Mubashirrrr commented Jun 4, 2026

Problem

orchestrate kickoff is meant to be idempotent: if a recent root planner for the same goal is already running, it adopts that agent instead of spawning a duplicate. But the dedupe in findActiveRootPlanner adopts an active planner belonging to a different goal when one slug is a prefix of another.

Kicking off goal auth while a planner for goal auth-ui (agent named auth-ui-root) is active prints adopting <auth-ui agent> and attaches the new run to the wrong goal's planner. The intended auth run never starts, and the operator silently lands in an unrelated orchestration.

Root cause

The kickoff action names every root planner deterministically as `${rootSlug}-root` (cli/task.ts), but the dedupe scan matched with a bare prefix check:

if (!name.startsWith(rootSlug)) continue;

"auth-ui-root".startsWith("auth") is true, so a slug that is a prefix of another goal's slug collides. Non-root task agents use a different scheme (`${rootSlug}/${name}`), so only root planners are affected — but any two goals where one slug prefixes the other will cross-adopt.

Fix

Match the canonical planner name exactly. Since the name is fully deterministic, exact equality is both correct and the tightest possible check:

const rootPlannerName = `${rootSlug}-root`;
...
if (name !== rootPlannerName) continue;

Surgical, one-line behavioral change plus a clarifying comment. No other call sites or naming paths are touched.

Test

Added a regression test to __tests__/kickoff-dedupe.test.ts: an active refactor-ui-root planner must not be adopted when kicking off slug refactor (prefix overlap), asserting findActiveRootPlanner(...) returns null.

  • Fail-before: with the original startsWith check, the new test fails — findActiveRootPlanner returns the unrelated bc-refactor-ui agent instead of null.
  • Pass-after: with the exact-match fix, the new test passes.
  • Full suite green: bun test → 208 pass / 0 fail; tsc --noEmit clean.

Repro

import { findActiveRootPlanner } from "./cli/task.ts";

// Active planner for goal "auth-ui"; we kick off the distinct goal "auth".
const r = await findActiveRootPlanner(
  { async list() { return { items: [{
      agentId: "bc-authui",
      name: "auth-ui-root",
      createdAt: Date.now() - 1_000,
      latestRun: { id: "run-authui", status: "running" },
  }] }; } },
  "auth",
);
// before fix: r.agentId === "bc-authui"  (wrong goal adopted)
// after  fix: r === null                 (no match; a new planner is spawned)

Note

Medium Risk
Changes kickoff idempotency behavior for overlapping goal slugs; fix is narrow but affects which cloud agent a new run attaches to.

Overview
Kickoff dedupe in findActiveRootPlanner now matches the canonical root planner name `${rootSlug}-root` with exact equality instead of name.startsWith(rootSlug). That stops orchestrate kickoff from adopting another goal’s active planner when one slug is a prefix of another (e.g. kicking off auth while auth-ui-root is running).

A regression test covers the refactor vs refactor-ui-root case and expects no adoption.

Reviewed by Cursor Bugbot for commit c5e6407. Bugbot is set up for automated code reviews on this repo. Configure here.

findActiveRootPlanner adopted any active cloud agent whose name merely
started with the kickoff slug (`name.startsWith(rootSlug)`). Because the
kickoff command names every root planner exactly `${rootSlug}-root`, a
slug that is a prefix of another goal's slug would wrongly adopt the
unrelated planner: kicking off goal `auth` while `auth-ui-root` is
active matched `"auth-ui-root".startsWith("auth")`, silently attaching a
fresh run to the wrong goal's planner instead of starting a new one.

Match the deterministic canonical name `${rootSlug}-root` exactly. Adds
a regression test asserting a prefix-only slug overlap does not adopt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant