Skip to content

deferredwork: next_seq scans prose, so a DW-<n> token in a note steers id allocation #327

Description

@pbean

Summary

next_seq allocates the next DW id by scanning \bDW-(\d+)\b over the whole ledger file,
prose included (deferredwork.py:274-282). So a DW-<n> token anywhere in a note, reason or
summary steers orchestrator id allocation.

Reproduced:

mark_done(ledger, "DW-1", "2026-06-11", "fixed, see DW-99999")
append_entry(ledger, title="next", ...)   # -> "DW-100000"

The intervening id space is burned permanently — the ledger is append-only and next_seq's
docstring is explicit that a number is never reused.

Why it matters more after #305

Pre-existing and unchanged by #305: before that fix, an injected phantom ### DW-99: heading fed
DW_ID_RE identically. But #305's sanitizer preserves the token as prose rather than removing
it, so this is now the documented steady state rather than a corruption artifact.

deferred-work-format.md:25 also instructs LLM writers to number "by scanning the file for the
highest existing number", so a dev or migration session replicates the jump rather than correcting
it.

Fix shape

Derive next_seq from HEADING_RE matches (real entry headings) rather than a bare token scan,
keeping a floor so an id is never reused even if a heading is later edited away. The sweep numbering
check in validate_migration should keep passing.

Found during the #305 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:deferred-workdeferred-work.md ledger and sweepbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions