Skip to content

fix(loop): budget.mjs exits 0 unbudgeted, and prose guards the marker #155

Closed

Description

@sydevs-bot

Summary

node workflow/lib/budget.mjs --kind <name> exits 0 when writing.budgets names no <name>, so a typo'd or unnamed kind reads as a pass (budget.mjs:194). That silence hid the missing review-body budget for three weeks (#145, now being fixed by #153). The same script is the right home for the one mechanical item in preflight's never-cut rule — whether the text ends with identity.commentMarker — because CLAUDE.md gives mechanical rules to scripts, not prose.

This ticket is blocked by #153. Everything this ticket builds on beyond budget.mjs:194 exists only on claude/chore-145-review-body-budget, not on main. Verified in this run against main at a45fc7d: writing.budgets has no reviewBody key, handler-preflight has no never-cut rule naming the marker, and budget.test.mjs has six tests and no corpus test. Do not start this until #153 merges.

Approach

Two phases, one PR, one commit each, Phase 1 first. Both change workflow/lib/budget.mjs, which every run in all five repos invokes, so the commits stay separately revertable — but they do not split into two PRs. (why: docs/why.md#a-ticket-is-built-in-phases-never-split)

Phase 1 — an unbudgeted kind is a failure, and the caller must still know which failure

check() returns UNBUDGETED (budget.mjs:53-55) and the CLI exits 0 on it (budget.mjs:194). Make it exit non-zero and name the kind.

The loop risk #145 deferred this for is real, and already live on the other path. --fit exits non-zero on UNBUDGETED today (budget.mjs:188), and handler-journal/SKILL.md:57 tells a run Exit 1 → cut prose from Friction. A run that hits UNBUDGETED there is told to cut prose that is not over budget, forever. Confirmed in this run:

printf 'x' | node workflow/lib/budget.mjs --fit --kind nosuchkind   → UNBUDGETED, exit 1
printf 'x' | node workflow/lib/budget.mjs       --kind nosuchkind   → UNBUDGETED, exit 0

So Phase 1 is not only an exit code. The response must key on the printed verdict word, which already distinguishes the two, not on the exit code:

  • budget.mjs:194 — exit non-zero on UNBUDGETED, naming the kind.
  • handler-journal/SKILL.md:57 — replace Exit 1 → cut prose with a rule that cuts on OVER and stops on UNBUDGETED.
  • handler-preflight/SKILL.md:97 — Over means cut likewise names the verdict, not the exit.

The standing guard #153 leaves is narrower than its PR body claims, which is the argument for this phase. Its corpus test scans SKILL.md for a literal --kind <name>. Run in this session against main's skills, the set it finds is ['journalEntry']; with #153 merged it becomes journalEntry and reviewBody. comment and reviewReply are referenced only as writing.budgets.comment in prose, so a run types them by hand and no test ever covers them — exactly the case #153's own detail admits it misses.

Phase 2 — the marker check moves into the script

budget.mjs already holds the text on stdin and loadLoopConfig() on identity.commentMarker. The requirement is per-kind, not blanket: handler-journal entries carry no marker.

Shape: a sibling list, not a per-kind object. budget.mjs is the only reader of writing.budgets — grepped across workflow/, dispatcher/ and .github/ in this run, nothing else touches the key. Both of its lookups require a number (budget.mjs:51-53, budget.mjs:106-107), and #153 adds a deepEqual of DEFAULT_BUDGETS against the config. So:

  • writing.markerRequired: ["comment", "reviewReply", "reviewBody"] beside writing.budgets keeps the number contract and both of feat(loop): a review body gets its own budget kind, and the rules that spend it #153's tests untouched.
  • Turning each budget value into {chars, marker} breaks both lookups, the deepEqual, and every existing --kind call.
  • budget.mjs reads the new key and fails a listed kind whose text does not end with the marker.
  • handler-preflight/SKILL.md:95-96 keeps the rule as an imperative and cites the script where the script decides.

Acceptance criteria

  • --kind <name> with no budget for <name> exits non-zero and names the kind.
  • Every --kind the skills name still measures and passes as before.
  • handler-journal and handler-preflight tell a run to cut on OVER and to stop, not cut, on UNBUDGETED.
  • A kind declared to require the marker fails when the text does not end with identity.commentMarker.
  • A kind not declared to require it passes without one.
  • writing.budgets values are still plain integers.
  • handler-preflight's never-cut rule cites the script wherever the script decides.
  • workflow/.claude-plugin/plugin.json version is raised above whatever main carries when this lands — main and feat(loop): a review body gets its own budget kind, and the rules that spend it #153's branch are both at 2.5.0 today.

Verification checklist

  • printf 'x' | node workflow/lib/budget.mjs --kind nosuchkind exits non-zero and prints nosuchkind
  • printf 'x' | node workflow/lib/budget.mjs --fit --kind nosuchkind exits non-zero and prints UNBUDGETED, not OVER
  • printf 'x' | node workflow/lib/budget.mjs --kind journalEntry exits 0
  • printf 'x' | node workflow/lib/budget.mjs --kind comment exits non-zero, naming the missing marker
  • printf 'x<sub>…marker…</sub>' | node workflow/lib/budget.mjs --kind comment exits 0, with the real identity.commentMarker from loop-config.json appended
  • node --test workflow/lib/budget.test.mjs passes — 8 of 8 or more once feat(loop): a review body gets its own budget kind, and the rules that spend it #153 is in
  • node --test dispatcher/test/*.test.mjs passes — 106 passed on main in this run
  • claude plugin validate ./workflow --strict prints √ Validation passed and exits 0 — this is what main reports in this run, not the four ${CLAUDE_PLUGIN_ROOT} warnings feat(loop): a review body gets its own budget kind, and the rules that spend it #153's body quotes
  • node workflow/lib/rule-delta.mjs --base main workflow/skills — account for every removed directive, since both phases rewrite run-loaded prose

Downstream impact

No consumer repo file changes, so contractSync is not involved. But budget.mjs is invoked by every run in all five repos, and after Phase 1 a mistyped --kind fails a run instead of passing it. The two skills whose instruction changes are read on every dispatch.

Open questions

  • Does --fit enforce the marker too? fit() cuts list items from the end of 📄 Did and is journal-only, and journalEntry is not marker-required — so the interaction may be unreachable. Confirm before adding a guard for it.
  • Does check() enforce the marker unconditionally, or behind a flag? Unconditional means a maintainer measuring a draft before appending the marker gets a failure. Arguably correct — that draft is not the artifact the budget measures — but it is a behaviour change for a human at a terminal.

Notes

Blocked by: #145 — this ticket's reviewBody budget, never-cut rule and corpus test all land with #153, which closes #145.

🤖 Written by the sydevs autonomous loop — see what this is

Activity

  1. added theissue type on Oct 6, 2026
  2. added
    proposal
    bot:working
    on Oct 6, 2026
  3. sydevs-bot commented on Oct 6, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running

    recent dispatches
    • 05:33Z implement · attempt 1 · session · done
    • 05:33Z implement · attempt 1 · session
    • 00:50Z revise · attempt 1 · session · done
    • 00:50Z revise · attempt 1 · session

    Written by the sydevs dispatcher. Sessions never edit this comment.

  4. sydevs-bot commented on Oct 6, 2026

    @sydevs-bot
    ContributorAuthor

    ✍️ Revised against main at a45fc7d. The title and type stand.

    Blocked by #145. Three of this ticket's premises exist only on #153's unmerged branch: the reviewBody budget, preflight's never-cut rule, and the corpus test. On main there is no reviewBody key and budget.test.mjs has six tests. Added the marker line, so the dispatcher parks this until #153 merges and closes #145.

    Two parts became two phases on one PR. The body said each lands on its own. A ticket is built in phases, never split.

    Both decisions are now taken, from the code.

    • Part 1's loop risk is already live: --fit exits 1 on UNBUDGETED and handler-journal says Exit 1 → cut prose. So the fix must key on the verdict word, not the exit code.
    • Part 2's shape: budget.mjs is the only reader of writing.budgets, and both lookups need a number. A sibling markerRequired list keeps that contract; a per-kind object breaks it.

    Also: the lean gate is clean on main, so checklist item 6's four warnings are gone.

    @sydevs-bot implement starts the work.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  5. added and removed
    bot:working
    on Oct 6, 2026
  6. sydevs-bot commented on Oct 6, 2026

    @sydevs-bot
    ContributorAuthor

    @Ardnived unblocked: every blocker is closed. Say @sydevs-bot implement to start.

    🤖 sydevs dispatcher

  7. Ardnived commented on Oct 6, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  8. added
    bot:working
    and removed
    proposal
    on Oct 6, 2026
  9. moved this from Approved to Done in SYDevelopers Technical Roadmapon Oct 6, 2026
  10. removed
    bot:working
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions