OpenSpec icon indicating copy to clipboard operation
OpenSpec copied to clipboard

validate <change> --strict does not check the length of MODIFIED requirements, so an overlong one fails only after archive

Open HengYangDS opened this issue 3 weeks ago • 3 comments

What you were trying to do

Archive a finished change whose spec delta rewrites an existing requirement (## MODIFIED Requirements), with openspec validate <change> --strict as the gate before archiving.

What happened

openspec validate <change> --strict passes when a MODIFIED requirement's new text is longer than 500 characters. The limit is enforced only on the main spec after archive, so the overlong requirement is found after the change has been archived:

$ openspec validate grow-note --strict
Change 'grow-note' is valid
exit 0
$ openspec archive grow-note --yes
Specs updated successfully.
Change 'grow-note' archived as '2026-11-08-grow-note'.
$ openspec validate --all --strict
✗ spec/notes
  ⚠ [WARNING] requirements[0]: Requirement text is very long (>500 characters). Move examples and edge cases into scenarios, or split it into separate requirements that each state one behavior.
Totals: 0 passed, 1 failed (1 items)
Details: openspec validate notes --type spec
exit 1

#2020 (closing #1976) made validate <change> --strict fail on an overlong ADDED requirement, so that "a change fails --strict at exactly the length its main spec would after archive". It leaves MODIFIED unchecked because "its text is the existing requirement, which the instruction says to keep whole" (src/core/validation/validator.ts, the comment above the ADDED length check). That holds when a MODIFIED block repeats the current text, but a MODIFIED block replaces the whole requirement with the author's new text, and that text can grow past the limit. We hit this in a real change: a MODIFIED requirement grew from 463 to 661 characters, validate <change> --strict passed, and the failure surfaced only when our archive step validated the merged specs strictly.

What you expected instead

openspec validate <change> --strict fails on a MODIFIED requirement whose new text exceeds the limit, as it does for ADDED, so the change fails before archive rather than its main spec after.

To keep #2020's intent for requirements that are already over the limit and are only being kept whole, the warning could apply when the MODIFIED text exceeds the limit and is longer than the requirement it replaces in the main spec. options.mainSpecsDir is already read for the scenario-loss check, so the current text is at hand.

Minimal steps to reproduce

  1. Create openspec/specs/notes/spec.md:

    # notes Specification
    
    ## Purpose
    
    Store each note with its author and keep it for later reading by the team.
    
    ## Requirements
    
    ### Requirement: Stored notes
    
    The service SHALL store each note with its author and the time it was written.
    
    #### Scenario: A stored note
    
    - **WHEN** a note is written
    - **THEN** it is stored with its author and time
    
  2. Create a change openspec/changes/grow-note/ with a proposal.md (Why, What Changes, Impact), a tasks.md, and specs/notes/spec.md that has ## MODIFIED Requirements, the same ### Requirement: Stored notes header and scenario, and requirement text of 670 characters: the first sentence above followed by four repetitions of "It SHALL also keep every earlier version of the note, in order, with the author and time of each version, so a reader can see how the note changed."

  3. Run openspec validate grow-note --strict (exit 0), openspec archive grow-note --yes, then openspec validate --all --strict (exit 1, the output above).

OpenSpec version

1.16.0. The ADDED-only length check and its comment are unchanged on main as of 2026-11-08.

Coding agent and model

Claude Code, Claude Opus 5.5. The agent wrote this report and ran the reproduction; the output above is from that run, with OpenSpec's own binary.

OS and Node version

macOS 27.2, Node 26.13.0

HengYangDS avatar Nov 07 '26 17:11 HengYangDS

Confirmed independently with the official 1.16.0 binary, using the trimmed requirement description length:

Replacement Strict change validation Archive Strict canonical validation
MODIFIED, 500 characters Pass Pass Pass
MODIFIED, 501 characters Pass Pass Fail
ADDED, 501 characters Fail Not run Not run

A 670-character requirement left unchanged, or shortened to 550, already fails canonical strict validation before archive. Those cases need an explicit policy decision; the new 501-character replacement is a separate pre-archive validation gap.

This also connects to #2069: validate the resulting canonical content before writing it or moving the change. That would catch this failure without shortening accepted wording automatically. Happy to test the agreed behavior on the same boundary cases.

Retested the same four fixtures with the official 1.16.1 and 1.17.0 binaries. Results are unchanged: MODIFIED at 501 still passes validation and archive, then fails canonical strict validation.

November 14: the official Homebrew 2.0.0 binary gives the same results on all four fixtures (10 CLI calls). The 501-character MODIFIED block still validates and archives, then fails strict canonical validation. The verified fix above has not reached this release.

November 18: I checked the official 2.1.0 npm archive against its registry integrity hash. Its shipped dist/core/validation/validator.js and dist/core/archive.js are byte-for-byte identical to the Homebrew 2.0.0 installation tested above. The tagged validator still applies the length check only to ADDED requirements. This release does not include 7306b92. I did not execute 2.1.0 or change the installed CLI.

HengYangDS avatar Nov 08 '26 03:11 HengYangDS

I pushed a fix and tests on my fork: https://github.com/DrMkdaddy/OpenSpec/tree/fix/validate-modified-length

Feel free to cherry-pick 7306b92 or ping me if you want a PR.

risingpresage avatar Nov 13 '26 01:11 risingpresage

Thanks, @DrMkdaddy. I tested 7306b92 on macOS on November 13: the native build and all 69 validation tests passed, and the three growth regressions failed on the parent validator. The original CLI fixtures also passed: 500-character replacements validate and archive cleanly; 501-character replacements fail before archive.

The fix is now in #2265 with your authorship preserved. All three changed file blobs match the tested commit. I reviewed 7597cf6 and its passing CI and approved the PR. It covers the reported growth gap while preserving unchanged or shortened legacy text and renamed requirements. The existing-overlong-spec policy remains separate; the containing stable release still needs verification.

HengYangDS avatar Nov 13 '26 01:11 HengYangDS