Skip to content

Fail closed when wizard state segments is not a mapping - #128

Merged
cursor[bot] merged 2 commits into
mainfrom
cursor/wizard-state-segments-2ccd
Sep 7, 2026
Merged

cursor[bot] merged 2 commits into
mainfrom
cursor/wizard-state-segments-2ccd

Conversation

@jmjava

@jmjava jmjava commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

Problem

load_state accepts any JSON object. GET /api/segments then does state.get("segments", {}).get(seg_id, {}). A list, string, or per-id non-object under segments raises AttributeError. POST /api/state writes that payload unchanged.

Corrupt JSON / a non-object root still reset to {"segments": {}} so a broken file does not brick the wizard.

Change

When segments is present, it must be a JSON object whose values are objects. Missing / null segments still means {}.

  • GET /api/state and GET /api/segments return 500 with WizardError (not a traceback)
  • POST /api/state returns 400 for a non-object body or invalid segments, and does not write the file

Tests

Local: ruff check src/ tests/ green; pytest tests/ 741 passed, 1 skipped; docgen benchmark meets src/docgen/benchmark_data/baseline.json (no --update-baseline).

  • load_state still resets corrupt JSON
  • list / scalar segments and per-id non-objects raise
  • null segments becomes {}
  • API GET/POST coverage above

Out of scope

  • Changing the corrupt-JSON → empty reset
  • Wizard except Exception around narration_topic_label
Open in Web Open in Cursor 

cursoragent and others added 2 commits September 7, 2026 23:07
GET /api/segments called .get on a list or scalar under
.docgen-state.json segments and raised AttributeError. Require a JSON
object of per-id objects; POST /api/state rejects the same payload.

Co-authored-by: jmjava <jmjava@gmail.com>
Co-authored-by: jmjava <jmjava@gmail.com>
@jmjava
jmjava marked this pull request as ready for review September 7, 2026 23:08
@cursor
cursor Bot merged commit 758f463 into main Sep 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants