OpenSpec icon indicating copy to clipboard operation
OpenSpec copied to clipboard

Cannot rename a scenario — `MODIFIED` reads a rename as a dropped scenario and blocks archive

Open RawanS opened this issue 3 months ago • 7 comments

Summary

A MODIFIED requirement must reproduce every scenario the current spec has, or validate errors and archive aborts. That guard is right for accidental omissions, but it makes an ordinary refinement impossible: renaming a scenario heading while keeping the requirement. There is no scenario-level operator, and no way to mark an omission deliberate.

Reproduced on 1.8.0 and 1.9.0.

Reproduction

mkdir openspec-repro && cd openspec-repro
openspec init --tools none
mkdir -p openspec/specs/parking openspec/changes/add-permit-check/specs/parking

openspec/specs/parking/spec.md:

# parking Specification

## Purpose

Vehicle entry rules for a car park.

## Requirements

### Requirement: Full car park refuses entry
The system SHALL refuse entry when no bay is free.

#### Scenario: Car arrives at a full car park
- **WHEN** a car arrives and no bay is free
- **THEN** entry is refused

openspec/changes/add-permit-check/.openspec.yaml:

schema: spec-driven
created: 2026-01-01

openspec/changes/add-permit-check/proposal.md:

## Why
Permit holders should keep a reserved bay even when the car park is full.

## What Changes
- Refusal now depends on whether the driver holds a permit.

openspec/changes/add-permit-check/tasks.md:

## 1. Permit check
- [ ] 1.1 Read the permit before refusing entry.

openspec/changes/add-permit-check/specs/parking/spec.md — the original scenario is renamed to say what it now covers, and a second scenario is added for the new branch:

## MODIFIED Requirements

### Requirement: Full car park refuses entry
The system SHALL refuse entry when no bay is free, unless the driver holds a permit.

#### Scenario: Car without a permit arrives at a full car park
- **WHEN** a car arrives, no bay is free, and the driver holds no permit
- **THEN** entry is refused

#### Scenario: Car with a permit arrives at a full car park
- **WHEN** a car arrives, no bay is free, and the driver holds a permit
- **THEN** entry is allowed into the reserved bay

Actual result

$ openspec validate add-permit-check
Change 'add-permit-check' has issues
✗ [ERROR] parking/spec.md: MODIFIED "Full car park refuses entry" omits scenario(s) the current spec still
  has: "Car arrives at a full car park". Copy them into the MODIFIED block (a MODIFIED requirement replaces
  the whole block, so archive refuses to drop them).

$ openspec archive add-permit-check --yes
  parking: update
parking MODIFIED failed for header "### Requirement: Full car park refuses entry" - current spec contains
scenario(s) not present in the modified block: "Car arrives at a full car park". Refresh the change spec
before archiving to avoid dropping scenarios.
Aborted. No files were changed.

Note this is not --strict only — plain validate reports it as an error, and archive refuses.

Expected result

The change archives, leaving the requirement with the two permit-aware scenarios. Car arrives at a full car park was not dropped; it was renamed to Car without a permit arrives at a full car park.

Workarounds tried

Approach Result
Keep the new heading validate errors, archive aborts (above)
## REMOVED + ## ADDED the same requirement ✗ [ERROR] Requirement present in both ADDED and REMOVED: "Full car park refuses entry"
## RENAMED Requirements FROM:/TO: applies to requirement headings only — does not reach scenarios
Keep the old heading over the new body Works, but the spec keeps a heading that no longer describes the scenario
archive --no-validate Works, but disables every other check for the whole change
Re-add the old heading as a third scenario Leaves a scenario whose precondition is now unreachable, contradicting a sibling

Why it matters

Where a project ties each scenario to the test that pins it by quoting the heading as the test name, the heading is the traceability key rather than decoration — so being unable to rename one forces a choice between an inaccurate spec and archiving with validation off.

It also bites hardest in the case the guard exists to protect. When a delta is authored before another change merges, the author never saw the scenario now being compared against, so the "omission" is not a decision they made — but the only way through is still to hand-reconcile headings.

Suggested fix

Either would resolve it:

  1. A scenario-level rename, mirroring the requirement-level syntax already in the format:

    ## MODIFIED Requirements
    
    ### Requirement: Full car park refuses entry
    
    - RENAMED SCENARIO FROM: `#### Scenario: Car arrives at a full car park`
    - RENAMED SCENARIO TO: `#### Scenario: Car without a permit arrives at a full car park`
    
  2. An explicit deliberate-omission marker, so intent is stated and the guard still catches accidents:

    ### Requirement: Full car park refuses entry
    **Drops scenarios**: Car arrives at a full car park — superseded by the two permit-aware scenarios below.
    

Option 1 preserves the rename as a rename rather than a drop plus an add, which is what keeps test traceability intact.

RawanS avatar Aug 19 '26 08:08 RawanS

Reproduced on main. The guard is findMissingCurrentScenarios (src/core/parsers/requirement-blocks.ts:341), which compares scenario names, so a rename reads as a drop and both validate and archive refuse it:

parking MODIFIED failed for header "### Requirement: Full car park refuses entry" - current spec contains scenario(s) not present in the modified block: "Car arrives at a full car park"

Worth being explicit about why this is awkward to fix loosely: that guard exists to close a silent data-loss class (#1246), and four merged PRs have since hardened it — multiplicity-aware counting so a duplicated name can't mask a real loss (#1391, #1252), fence-awareness so a #### Scenario: inside an example block isn't counted (#1475), and counting every level-4 header rather than only #### Scenario: (#1521). Anything that infers "these two scenarios look similar, probably a rename" reopens exactly what those closed. The omission has to be declared, not guessed.

The smallest declaration that fits the existing format is an explicit operator, reusing the FROM:/TO: parser that ## RENAMED Requirements already has (requirement-blocks.ts:304-325):

## MODIFIED Requirements

### Requirement: Full car park refuses entry
The system SHALL refuse entry when no bay is free, unless the driver holds a permit.

#### RENAMED Scenario
- FROM: `#### Scenario: Car arrives at a full car park`
- TO: `#### Scenario: Car without a permit arrives at a full car park`

#### Scenario: Car without a permit arrives at a full car park
- **WHEN** a car without a permit arrives and no bay is free
- **THEN** entry is refused

findMissingCurrentScenarios then treats the FROM name as accounted for, because the delta says so, and everything it currently catches it still catches — an undeclared omission is still a loss.

The part that needs a decision before anyone writes it: scenarios have no identity in the data model at all (ScenarioSchema is { rawText }, no name field), so this introduces the first operator that names one. That's a format decision, not a bug fix, which is why I'm asking rather than opening a PR. Two questions:

  1. Is an explicit scenario-level operator the direction, or would you rather scenario renames stay out of the delta format and be handled some other way (a --allow-scenario-rename escape, or leaving it to archive --no-validate)?
  2. If it is the direction, should it also cover REMOVED Scenario — deliberately dropping a scenario is the same "declare the omission" problem, and it's the other half of why people reach for --no-validate today.

If there's appetite for it I'm happy to implement, and to write it as a delta against the delta-format spec so the format change is itself reviewed as a change.

ryandemelo avatar Aug 19 '26 12:08 ryandemelo

Corroborating this from a repo that has been using OpenSpec heavily, with some numbers on how often it bites and — more usefully for weighing the fix — how often the omission was actually deliberate.

Method. Replayed the MODIFIED-versus-current-spec comparison across every archived change in our repo: 75 changes carrying a MODIFIED block, 116 delta capability files, each compared against the ratified spec as it stood immediately before that change synced (reconstructed from git). The comparison is name-keyed and multiplicity-aware, matching findMissingCurrentScenarios.

Incidence. Under 1.9.0's comparison, 29 of 75 archived changes (39%) would be blocked — 99 findings in total. Every one is a correct detection: the scenario really is in the current spec and really is absent from the MODIFIED block. There is no false-detection problem here.

Intent. That is the part worth weighing. I hand-classified the 26 findings where the scenario carried no stable id (our repo prefixes most scenario headings with a [cap-NNN] id, so this subset is the one that behaves like a plain OpenSpec project):

Class n Omission was
Superseded — replaced by differently-titled scenarios covering the same ground 9 intended
Deliberate deletion — the behaviour was removed 7 intended
Real loss, caught by a human reading the delta at archive time 4 accidental
Real loss, shipped and restored by a later change 2 accidental
Stale base — delta authored before another change added the scenario 4 neither

16 of 26 (62%) were intended. So the guard currently blocks roughly three intended omissions for every two it should stop.

But the guard is earning its keep. The 4 "caught by hand" cases are ones where a human noticed the omission during archive and restored the scenarios manually — the archive commit for one says so explicitly: "The MODIFIED block would have silently deleted four ratified scenarios… The tell was in the delta's own prose." Those are exactly what the guard automates. Two more shipped as real losses and had to be repaired by a later change. Please don't weaken detection — the ask is only for a way to state intent.

Intent is not recoverable from structure. One change in our corpus produced 6 findings against a single requirement in a single MODIFIED block — 2 were renames, 4 were accidents. Identical in scenario count, heading, and id presence. Only the scenario content separates them, and only to a reader. I tried to build an objective proxy over all 26 and it failed for this reason. That is the argument for the author declaring it rather than the tool inferring it.

On the two suggested fixes: option 2 (the deliberate-omission marker) covers strictly more ground than option 1. A scenario-level rename handles the 9 supersessions but not the 7 deliberate deletions, and not the stale-base case at all. It also would not help projects that renumber scenario ids — in ours, an id lives inside the heading, so changing [cap-001] to [cap-042] with identical prose reads as a drop. One change renumbered 14 in a single pass.

The stale-base class deserves emphasis — the issue mentions it, and it is the one an omission marker genuinely cannot fix. Two of our changes were authored the same day against a spec that did not yet contain the other's scenario; neither author ever saw what they were "omitting". Blocking is correct there. Whatever shape the marker takes, it would be good if that case stayed distinguishable from a declared removal, since the remedy differs — reconcile against the current base, rather than declare intent.

Happy to share the replay script or the per-change breakdown if either is useful.

johnmcarbajal avatar Aug 20 '26 00:08 johnmcarbajal

One small addition to the reporting side, orthogonal to the format question.

When the guard fires, the message names the scenarios the MODIFIED block omits — the shape quoted in #1482 is:

✗ [ERROR] widgets/spec.md: MODIFIED "Widget state" omits scenario(s) the current
  spec still has: "Existing scenario".

Reporting the added scenarios alongside the missing ones would let a reader separate a rename from a truncation at a glance, without opening either file. live 2 → delta 4, +3 is almost certainly a widening; live 5 → delta 2, +0 is almost certainly a loss. Neither is proof — the thread already establishes that intent isn't recoverable from structure — but it's the first thing a person checks after the guard fires, and it's free to print.

It also helps the case @johnmcarbajal raises, where one MODIFIED block produced 6 findings against a single requirement, 2 renames and 4 accidents. A count won't separate those. It will tell you immediately that the block added 2, which is the fact that sends you looking.

My own data is thin and I'd rather say so than dress it up. One 7-change chain, 6 MODIFIED blocks. A local script flagged 2 items, and only one is on-topic here — a scenario renamed in place to widen its scope. The other was our script's own bug: a requirement rename declared in a sibling ## RENAMED Requirements block that we failed to resolve first. That's an argument for resolving declared renames before comparing, which the existing implementation already does at the requirement level; it says nothing about your scenario-level case.

So: one data point corroborating the rename friction, and no view on whether the operator or the omission marker is the right shape. The reporting change stands on its own either way.

crisradu75 avatar Aug 27 '26 13:08 crisradu75

@crisradu75 — took the reporting half up in #1809, since it stands on its own and needs nothing from the format question here.

It prints the counts you described plus the names the block introduces, and archive prints the same sentence so the two commands cannot report different numbers for the same block. Kept it explicitly conclusion-free: the guard fires on exactly the inputs it did before, the exit code is unchanged, and it draws no inference from the counts, for the reason @johnmcarbajal's six-findings example above makes unarguable.

Your +3 versus +0 framing is the one a reader actually uses, so it is worth being clear what it does and does not buy: it will not tell anyone whether an omission was intended, but it does say which file to open first. That seemed worth shipping separately from the operator, which is still a maintainer call.

The format question on this issue is untouched.

ryandemelo avatar Sep 07 '26 01:09 ryandemelo

Opened a proposal answering Q1 with a concrete spelling, and leaving Q2 open as its own question: #1843 (implementation written and tested, held on a separate branch per CONTRIBUTING's format-change process pending your call on the format). The design doc there also explains why the #### RENAMED Scenario heading suggested above can't work, given how parseScenarioBlocks counts headers.

brettheap avatar Sep 11 '26 02:09 brettheap

Another case for Q2, a deliberate removal rather than a rename (OpenSpec 1.13.2). A requirement narrowed: "report a problem from the Help menu or from a failed app" became "from the Help menu". Its scenario "Report a problem from a failed app" no longer describes anything. validate refused the MODIFIED block until it carried the scenario again, so we kept the title and rewrote it to point at another capability. The spec now holds a scenario that exists only to satisfy the check. A REMOVED SCENARIO: declaration, parallel to #1843's rename, would cover it.

TabishB avatar Oct 14 '26 11:10 TabishB

Still affected on 1.14.3: MODIFIED allows adding scenarios and editing bodies, but blocks intentional renames/deletions.

My workaround is manually applying all deltas to the main specs, then running openspec archive <change-name> --skip-specs.

Explicit rename and removal declarations would preserve accidental-loss protection without bypassing the merge workflow.

Q-back avatar Oct 26 '26 11:10 Q-back