Skip to content

fix(sdd): stop task-brief leaking trailing plan sections - #2359

Open
akalongman wants to merge 2 commits into
obra:devfrom
akalongman:fix/sdd-task-brief-trailing-sections
Open

akalongman wants to merge 2 commits into
obra:devfrom
akalongman:fix/sdd-task-brief-trailing-sections

Conversation

@akalongman

@akalongman akalongman commented Sep 21, 2026 •

Copy link
Copy Markdown

Targets dev.

Who is submitting this PR? (required)

Field Value
Your model + version Claude Fable 5.1 (claude-fable-5-1) ran the session; Claude Opus 5, 1M context (claude-opus-5[1m]) subagents measured the transcripts, drafted this diff and ran the tests
Harness + version Claude Code 2.1.278 (Linux)
All plugins installed superpowers 6.3.0, azure 1.2.49, security-guidance 2.0.8, php-lsp 1.0.0, context7, frontend-design, skill-creator (claude-plugins-official); phpstorm-plugin 1.0.0 (phpstorm-marketplace)
Human partner who reviewed this diff @akalongman

What problem are you trying to solve?

scripts/task-brief starts a task at its Task N heading and ends it only
at the next Task <digits> heading, so the last task of a plan absorbs every
section that follows it. Plans written by writing-plans routinely end with
## Self-review notes, ## Done when, ## Final verification or a
## Verification checklist, and those land in the brief that is handed to an
implementer as its requirements.

It happened in a real run. In a 14-task plan executed with SDD on
2026-09-19, the brief for the last task
(task-16-brief.md in that run's workspace) is
31 lines, and line 27 is ## Self-review notes, the plan author's own
checklist. The implementer for that task received it as part of its
requirements, and the task reviewer received the same file as What Was
Requested.

It happens in this repository's plans too. Extracting every task of every
plan under docs/superpowers/plans/ with the shipped script, 13 task
extractions across 10 plans carry a trailing section: ## Self-Review Checklist into the last task of the visual-companion plans, ## Amendment 1
through ## Amendment 4 into four tasks of
2026-07-30-codex-efficiency-fixes.md, ## Verification checklist (run after Task 15) into task 15 of 2026-05-06-lift-drill-into-evals.md, ## Chunk 2
and ## Chunk 3 group headers into the tasks that precede them.

Across 93 real plans on this machine (732 task extractions), 78 extractions
carry 847 lines of text that belongs to no task.

What does this PR change?

A task now also ends at the next heading of level 2 or deeper that is not
deeper than the task's own heading, and only where two independent fence
parses agree the heading is outside a fenced example.

Rebased on 2026-11-12 onto dev at df2e996, after #2604, #2605 and #2606
reworked task-brief. The terminator is now a rule of its own after dev's
Task-heading rule, and dev's whole-ID match, sub-task rule and
unclosed-fence refusal stay as they are. The terminator never fires inside
dev's fence, so a fence that never closes still refuses (exit 4) or warns
exactly as before.

Is this change appropriate for the core library?

Yes. It is a correctness fix to a shipped core script that every SDD run
calls once per task. No new dependency, no new file, no project-specific
behaviour.

What alternatives did you consider?

End the task at any ## heading that is not a Task heading. Rejected
after measuring it: plans embed whole markdown documents inside a task (this
repository's 2026-04-06-worktree-rototill.md pastes a full SKILL.md, and
2026-08-27-diagnosing-superpowers.md pastes prompt files), and their inner
headings then cut the task short. On the repository's own plans that variant
truncated task 2 of the rototill plan from 261 lines to 60 and task 4 of the
diagnosing plan from 305 to 43. Losing requirements is a much worse failure
than carrying a checklist, so the terminator is gated instead.

Fix the fence tracking and rely on it alone. The existing every-fence-line
toggle mistracks tilde fences, nested fences and indented fences, which is
what #2304 fixes. But the embedded documents above are genuinely ambiguous
markdown: a bare inside amarkdown block closes it under CommonMark,
however the author meant it, so a single correct parser still cuts those
tasks short. Requiring two parsers to agree is what makes the new terminator
safe on plans that already exist.

Name the trailing sections (Self-review, Done when, ...). A word list
cannot cover ## Amendment 2 or ## Chunk 3, and it would have to grow with
every plan template.

Leave it to the plan author. The plans that leak were written by
writing-plans and are well formed; nothing in the plan format says a task
owns everything below it until the next task.

Does this PR contain multiple unrelated changes?

No. One script, one behaviour, plus its tests.

Existing PRs

#2176 (open, issue #2175) fixes the neighbouring half of the terminator:
Task 6b matching a request for Task 6. #2604 has since fixed the same on
dev with a whole-ID match, which this PR keeps as it is, so the two halves
compose on dev itself: the ID match stops a letter-suffixed sibling task
from merging in, this PR stops a non-task section from merging in.

#2304 (open) rewrites the fence rule to follow CommonMark, for a different
symptom: a fenced example containing ### Task 99 ends the real task early.
This PR leaves the existing fence line untouched and adds its stricter parse
under a separate name, so the two do not conflict textually. If #2304 lands
first, the cfence parse here becomes partly redundant and the terminator
can be gated on the corrected infence alone, at the cost of the ambiguous
embedded-document case; I would rather keep both parses and say why.

#1949, #1938 and #1858 touch where the brief is written, not what it
contains.

Environment tested

Harness (e.g. Claude Code, Cursor) Harness version Model Model version/ID
Claude Code (Linux, GNU awk 5.x, bash 5.2) 2.1.278 Claude Opus 5, 1M context claude-opus-5[1m]

New harness support (required if this PR adds a new harness)

Not applicable. No harness is added.

Clean-session transcript for "Let's make a react todo list"
Not applicable: this PR adds no harness support.

Evaluation

  • The initial prompt was a request to review a local skill that dispatches
    work through subagent-driven-development, using the transcripts of five
    real runs. The leaked ## Self-review notes in a real task brief came out
    of reading the workspace those runs left behind.
  • This is a script fix, not a skill-text change, so it was evaluated against
    files rather than sessions: every task of 93 real plans (732 extractions)
    and of this repository's 16 plans was extracted with the shipped script and
    with the fixed one, and every difference was read.
  • Outcome: 78 of the 732 extractions lose 847 lines in total, no extraction
    gains a line, and the first line dropped is a plan-level heading in every
    case (## Self-review notes 7 times, ## Self-Review 6, ## Self-review
    5, ## Done when 5, ## Final verification 3, then ## Spec coverage check, ## Notes for the reviewer, ## Out of scope for this plan,
    ## Execution handoff, ## Chunk 2, and so on).
  • Re-measured after the rebase, against dev's script: 2092 extractions
    from 260 plans, of which 167 lose 2902 lines in total. No extraction gains
    a line or changes its exit status, every change only drops lines from the
    end, and the first line dropped is a plan-level heading in every case.

Rigor

  • If this is a skills change: I used superpowers:writing-skills and
    completed adversarial pressure testing (paste results below)
  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table,
    rationalizations, "human partner" language) without extensive evals
    showing the change is an improvement

No skill prose changes, so the writing-skills box does not apply. The
adversarial cases are in the new fixtures and in the corpus run: a task with
deeper sub-headings of its own (kept), a plan-level section after the last
task (cut), a task containing an embedded markdown document with a bare
closing fence (not cut, because the parses disagree), and the 93-plan corpus
where the rule had to produce no new truncation anywhere.

bash tests/claude-code/test-sdd-workspace.sh passes on the rebased branch,
72 assertions, five of them new:

  [PASS] task-brief stops the last task at the next plan-level section
  [PASS] task-brief keeps a task's deeper sub-headings and stops at the next task
  [PASS] task-brief does not cut a task on a heading inside ambiguous fencing
  [PASS] task-brief keeps a fenced same-level heading inside its task
  [PASS] task-brief ends a task at an unfenced same-level heading

Against dev's script the two that expect a section cut off (the first and
the last) fail, and the three guards pass. scripts/lint-shell.sh (ShellCheck 0.11.0) passes on both
changed files.

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

@obra obra added bug Something isn't working plans Retired: use skill:writing-plans / skill:executing-plans skill:subagent-driven-development The subagent-driven-development skill subagents Retired: use skill:subagent-driven-development / skill:dispatching-parallel-agents labels Sep 26, 2026
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

The trailing-section leak this fixes is real and worth fixing — the corpus numbers check out (I reproduced 13 of the 13 repo-plan cases). But the new terminator also cuts a task at a same-level heading that is genuinely part of the task, and it does so silently, with exit 0.

Blocker — ###-level sub-sections inside a ### Task N are dropped. The rule at skills/subagent-driven-development/scripts/task-brief:62 is lvl <= tasklvl, and writing-plans/SKILL.md prescribes task headings at ###. So a ###-level sub-section ends its own task:

### Task 1: Build the widget
### Requirements
Must support A, B, C.
### Steps
1. Do A

On dev this yields an 11-line brief with Requirements/Steps intact; with this change it yields 2 lines — ### Task 1: Build the widget and nothing else, exit 0, no warning. The implementer is dispatched with a task whose entire body is the heading. I found the same shape in this repo's own plans: 2026-03-23-codex-app-compatibility.md:137 (### Step 1.5: Detect Environment) and :212 (### Step 5: Cleanup Worktree) are same-level headings that follow a ### Task heading. Since the failure is silent, this is worse than the leak being fixed.

Related: same-name/ambig is not the only escape. The !cfence guard on line 62 is the right instinct, but the cut is driven purely by lvl, so no fence state can save a same-level heading. Suggest requiring lvl < tasklvl (strictly shallower) as a floor, or only cutting on a known trailing-section heading name, plus a regression fixture with same-level sub-sections.

Minor — the CRLF close-check is narrower than #2304's. Line 54 uses /^[ \t]*$/, while #2304 (commented on separately) landed /^[ \t\r]*$/ after finding that a \r on the closing fence leaves the fence open. If both land, please take #2304's form here. Note the two PRs conflict on this file and #2304 carries mavericksea-ai's wrong-task fixture, which is worth keeping.

@akalongman

Copy link
Copy Markdown
Author

Checked both points against the branch.

The same-level heading case. The constructed example (### Requirements directly under ### Task 1, unfenced) would end the task, as you say. The two real instances cited do not: 2026-03-23-codex-app-compatibility.md:137 and :212 are inside a ```markdown fence (the plan quotes the text to insert into the skill file), and the branch produces the same brief as dev for those tasks, 79 and 80 lines, because the cfence guard on line 62 exists for exactly that shape. Ran both scripts on all eight tasks of that plan: identical output.

I also measured the pattern over the 123 plans on this machine, 969 Task N headings: no unfenced same-level sub-heading occurs inside a task. The 18 same-level headings that do follow a task are all trailing sections (Self-review, Done when, Out of scope), which is the leak this PR fixes. writing-plans puts a task's steps in bullets, not sub-headings, so a same-level heading after a task is the next section. A lvl < tasklvl floor would reintroduce the leak in all 18, and cutting only on known section names is a list that goes stale.

To make the behaviour explicit rather than silent, the branch now carries two test cases: a fenced same-level heading stays in its task (the cited plan's shape), and an unfenced one ends it. If you have a real plan where an unfenced same-level heading is part of the task, I would like to see it; the corpus here has none.

CRLF. Agreed, aligned the close check with #2304's [ \t\r]*. No CRLF fixture added here so the overlap with #2304's stays one line.

@xjsns346 xjsns346 mentioned this pull request Oct 6, 2026
4 of 5 tasks
@obra obra removed plans Retired: use skill:writing-plans / skill:executing-plans subagents Retired: use skill:subagent-driven-development / skill:dispatching-parallel-agents labels Oct 22, 2026
A task ended only at the next Task heading, so sections after the last
task (Self-review, Done when, Notes) rode into that task's brief. A task
now also ends at the next heading of the same or a shallower level, when
two fence parses agree the heading sits outside a code fence. Task IDs
keep the whole-ID match of obra#2604, and sub-task headings stay in their
parent's brief. Three assertions added to
tests/claude-code/test-sdd-workspace.sh.
The strict fence parser's close check now allows a trailing carriage
return, the form obra#2304 landed. Two test cases make the same-level
heading rule explicit: a fenced same-level heading stays in its task
(the shape real plans use to quote text for insertion), an unfenced one
ends it (a sibling section such as Self-review or Done when).

@danishkumar26 danishkumar26 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.

What this change does: Rewrites the task-brief ending rule in skills/subagent-driven-development/scripts/task-brief so a task stops at the next same-or-shallower heading (level 2+) instead of leaking trailing plan sections (Self-review, Done when) into the last task's brief. Adds a second, stricter fence parser (cfence) alongside the existing one; a heading ends a task only when both parsers agree it is outside a fence, otherwise the old behavior stands. Adds five test scenarios covering trailing sections, deeper sub-headings, ambiguous fencing, fenced same-level headings, and unfenced same-level headings.

  1. (Nothing to fix.) The rule is confined to one awk block with the in-code contract documented; deeper headings (e.g. #### Notes) still belong to the task. Verified locally: all task-brief assertions pass, exit 0, including the 5 new scenarios.

Verdict: Ship.

Not checked: none — script-level change, test suite runs locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working skill:subagent-driven-development The subagent-driven-development skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants