Repository navigation
task-brief: track fence character and length so fenced examples cannot end a task early - #2304
mavericksea-ai wants to merge 2 commits into
Conversation
…t end a task early
|
Independent repro from a real plan, on Superpowers 6.4.1 (Claude Code 2.1.282, macOS awk, found by a Claude Opus 5.5 session). Beyond truncation, the same bug also sends content to the wrong task. When a fenced fixture holds a heading like ### Task 1: write a fixture
````markdown
```markdown
### Task 2: heading inside the fixture
```
````
Step 2 of Task 1.
### Task 2: real task two
|
The fence rule accepted only spaces and tabs after a closing fence, so in a plan with CRLF line endings the first fenced block never closed and every later task was reported not found. Allow a trailing carriage return. Add two cases to the SDD workspace test: a fenced heading that carries a real task number, where the next task's brief must start at its real heading (the shape oiler reproduced in obra#2304), and a CRLF plan whose fenced block must close so the next task is found.
|
Thanks @oiler, this is a really useful reproduction. The wrong-task effect is worse than the truncation I described, and a real 7-task plan makes it concrete. Testing your case properly also turned up something my first commit got wrong: in a plan with CRLF line endings, the closing fence never closed, so every task after the first code block came back "not found". The shipped script handles that case, so it was a regression in this PR. 80f8ed1 fixes it and adds your shape as a fixture (Task 2's brief must start at its real heading, with none of Task 1), plus a CRLF plan. The test now has 20 checks, all passing under gawk, mawk and BWK awk. |
Strong fix. The closing-fence rule is correct on both counts: it requires the same character and Answering the question Two things worth knowing before merge: Minor — an unterminated fence now makes later tasks unfindable. Minor — this and #2359 conflict. Both rewrite the same awk block in |
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).
|
Thanks @Enough1122, both points are real, and the first is slightly worse than described. Reproduced on this head with a minimal two-task plan: an unclosed ~~~ fence makes task 1's brief absorb everything to EOF at exit 0, and the later task comes back not found at exit 3. dev, which never tracked tilde fences, happens to split that plan correctly. For an unclosed ``` fence, dev and this head behave the same: task 1 absorbs the remainder at exit 0, which is exactly #2436. I would rather not treat EOF-in-fence as "not a fence": that restores today's behaviour for the tilde case but keeps the silent exit-0 absorb for the backtick case, and a brief that is silently wrong is the failure class this PR is for. The direction #2436 and #2438 take looks right to me: a plan with an unclosed fence is malformed, and the script should say so loudly rather than hand an implementer a brief that quietly carries other tasks' text. The cheap version on this head is an END check: if a fence is still open at EOF, exit non-zero with "unclosed fence opened at line N" instead of the misleading "task not found". Happy to add that here as a third commit with two fixtures (unclosed backtick, unclosed tilde), or to leave the loud-fail to #2438 built on top of this head, whichever the maintainers prefer; @ada-sen, your view welcome since #2438 is yours. On sequencing with #2359: I suggest this PR lands first. The fence state here (the fence character and length plus the CRLF closer) already carries what the parallel parse in #2359 lacks, and @akalongman's e3136cf adopted the CRLF closers, so rebasing #2359's same-or-shallower terminator onto this head matches the composition you resolved locally. @akalongman, does that ordering work for you? |
|
@mavericksea-ai yes, #2304 first works for me, and I checked the composition rather than assume it. What the rebase of #2359 onto this head looks like. The /^```/ { tfence = !tfence }
!infence && /^#+[ \t]/ {
match($0, /^#+/); lvl = RLENGTH
if ($0 ~ /^#+[ \t]+Task[ \t]+[0-9]+/) {
intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
tasklvl = lvl
} else if (intask && !tfence && lvl > 1 && lvl <= tasklvl) {
intask = 0
}
}Task recognition is this PR's, unchanged. The toggle can only veto a cut, never cause one, so its known blind spots (tilde, nested, indented fences) can at worst leave a trailing section in a brief, which is today's behaviour, never truncate one. Measured.
Why the second vote stays, and why I would not take the single strict parse @Enough1122 described. Gating the cut on the corrected One thing this head changes on that same shape, for your list. A plan whose task holds such an embedded document, followed by a real Sequence that works for me: this PR lands (with or without the END check as a third commit; either way #2359 does not touch that part), and I rebase #2359 onto |
|
Thanks @akalongman for checking the composition against real plans. Agreed on #2304 first, then your rebase of #2359. I’ll keep this PR focused on the fence fix and leave the unclosed-fence diagnostic to #2438 unless the maintainers prefer it here. The ambiguous-fence case you flagged is useful coverage for that follow-up. |
… to EOF task-brief ignores Task headings inside fenced code blocks by toggling a flag on every ``` line. When a plan leaves a fence open (an edit deletes a closing fence), the flag stays set for the rest of the file, every later Task heading is invisible, and the requested task's brief runs to EOF. The script then reported success: obra#2436 saw a 177-line task come back as a 1159-line brief holding tasks 6 through 10, handed to an implementer as its requirements. The awk now notes whether a Task heading line appears inside the fence that is still open at EOF. If one does while the requested task is being captured, the task's end cannot be found, so task-brief deletes the partial output and exits 4, naming the line where the fence opened. If the open fence hides the requested heading itself, it names the fence before the existing not-found error (exit 3), and suppresses the "use the English word Task" hint, which would otherwise blame the plan's English headings for what the fence did. A fence left open that hides no Task heading changes nothing about the brief, so it is still written, with a warning on stderr. Real plans do this: in a corpus of 1,288 plans, refusing on any fence left open at EOF blocked three correct briefs in two plans, each ending in a stray ``` that hides no task. With this rule every brief in that corpus matches dev's. An unclosed fence in a later task leaves an earlier task's brief alone. The plan path reaches awk through the environment rather than -v, which would interpret the backslashes of a Windows path as escapes. The fence rule itself is unchanged, so this composes with obra#2304's CommonMark fence tracking: a correct parser still cannot close a fence the author never closed. Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
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).
Who is submitting this PR? (required)
What problem are you trying to solve?
skills/subagent-driven-development/scripts/task-briefextracts one task from a plan for the implementer and the reviewer. Its awk toggles an in-fence flag on any line starting with three backticks, so a~~~fence is not tracked at all, a four-backtick fence containing a three-backtick block toggles the flag back off inside the example, and an indented fence is not seen. In each case a heading such as### Task 99: Example onlyinside a fenced example is read as a real task boundary, extraction stops there, and the script exits 0 with a shorter brief. Anything after the example in that task, including its final requirements, never reaches the implementer or the reviewer.Reproduced with
task-brief PLAN 1 OUTon the shipped script at b36e082 (task-brief is identical ondevat 5940bd8):The 13 existing sdd-workspace checks pass on the current script; none exercises this boundary.
Two more effects came up after this PR opened. The same boundary also sends content to the wrong task: when the fenced heading carries a real task number, the tail of Task 1 lands in Task 2's brief (oiler's reproduction below, on a real 7-task plan). And the first commit of this PR regressed plans with CRLF line endings: its closing-fence check allowed only spaces and tabs, so a fence ended by a CRLF line never closed and every later task was reported not found. The shipped toggle handles a simple fenced block in a CRLF file, and Git for Windows checks files out with CRLF by default.
What does this PR change?
The fence rule now follows the CommonMark definition: it records the opening fence character and length, accepts up to three spaces of indentation, ignores a backtick line whose info string contains a backtick, and closes only on the same character at the same or greater length with nothing else on the line. Fence lines that belong to the task are still printed. Four fixtures are added to
tests/claude-code/test-sdd-workspace.sh: a three-backtick control, a tilde case, a four-backtick fence wrapping a three-backtick block, and an indented three-backtick case, each asserting the line after the example is still in task 1's brief.A second commit, 80f8ed1, allows a trailing carriage return in the closing-fence check and adds two fixtures: a fenced
### Task 2heading inside Task 1, asserting Task 1 keeps its end and Task 2's brief starts at its real heading with none of Task 1; and a CRLF plan whose fenced block must close so Task 2 is found.Is this change appropriate for the core library?
Yes. It is a correctness fix to a shipped core script, no new skill, no project-specific behaviour and no third-party integration.
What alternatives did you consider?
Rejecting tilde fences outright, or changing the task-heading regex to ignore headings inside examples: both leave the nested four-backtick case broken and the second cannot tell an example heading from a real one. A full Markdown parser is out of proportion for a 20-line awk script. Tracking the fence delimiter the way CommonMark defines it is the smallest change that closes every case in the fixtures.
Does this PR contain multiple unrelated changes?
No. One script fix and its tests.
Existing PRs
Environment tested
New harness support (required if this PR adds a new harness)
Not applicable, no harness added.
Evaluation
Rigor
Human review
No CI in the repository;
bash tests/claude-code/test-sdd-workspace.shwas run locally on macOS, all checks passing. The follow-up commit was also run on Linux under gawk, mawk and BWK awk (which macOS's awk is based on), 20 of 20 passing.