Skip to content

Guard the lanes seed routes against non-object JSON bodies - #997

Merged
brettheap merged 1 commit into
mainfrom
fix/768-lanes-seed-json-body-guard
Sep 12, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/768-lanes-seed-json-body-guard

Conversation

@brettheap

@brettheap brettheap commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-2 (openXfactory-2)

What: _handle_dtn_seed and _handle_staging_seed in
scripts/ideation_dashboard/serve_openxfactory_lanes.py now refuse a
None or non-dict parsed body with a clean 400 invalid_body /
JSON_OBJECT_BODY_REQUIRED payload, instead of either raising
AttributeError on body.get(...) (a valid JSON list/string/number/bool
body) or silently return-ing with no HTTP response at all (a malformed
or empty body, which _read_json_body() also collapses to None).

Why: pre-existing defect recorded on #768 (found by Copilot's review
of #761, confirmed pre-existing on main): both routes are loopback-gated
human-console write routes, so the blast radius was the local console
hanging or crashing its own request thread rather than the hosted plane,
but a request that gets no response at all is still a bug worth a clean
refusal.

How: the single if body is None: return guard at each site is
replaced with if body is None or not isinstance(body, dict): that
answers 400 with the same invalid_body / JSON_OBJECT_BODY_REQUIRED
shape _handle_refresh_action already uses a few lines below in this same
file — no new idiom, no accepted body shape changed.

Verified:

  • python3 -m pytest -q tests/ideation-dashboard/test_shared_identity.py tests/ideation-dashboard/test_staging_seed.py tests/ideation-dashboard/test_serve_column_split.py — 45 passed
  • python3 -m pytest -q tests -k 'lanes or serve_openxfactory or shared_identity or staging_seed' — 33 passed, 2 skipped
  • New tests per site: array body, scalar/bool body, malformed JSON, plus the existing happy-path wire tests continue to pass unchanged
  • python3 scripts/doc-health.py --single-repo . — New regressions vs previous report: 0
  • OPENSPEC_TELEMETRY=0 openspec validate --all --strict — Totals: 100 passed, 2 failed (same known pre-existing failures as origin/main: disposition-codexfactory-declared-renames, disposition-codexfactory-floor-relocation-retitle)
  • git diff origin/main --stat — only the server module and its two test files

refs #768

🤖 Generated with Claude Code

Summary by Sourcery

Reject invalid JSON request bodies consistently on the DTN and staging seed routes.

Bug Fixes:

  • Return a clear 400 invalid_body response when the DTN seed and staging seed routes receive empty, malformed, or non-object JSON bodies instead of crashing or leaving requests unanswered.

Tests:

  • Add wire-level coverage for non-object and malformed JSON bodies on both seed routes.

_handle_dtn_seed and _handle_staging_seed in
serve_openxfactory_lanes.py called body.get(...) on whatever
_read_json_body() returned without checking its shape. A JSON list,
string, number or bool body parses fine but has no .get, so it raised
AttributeError in the request thread and the client got no HTTP
response at all; a malformed or empty body collapsed to the same
_read_json_body() None sentinel and hit an early `return` with no
response either.

Both handlers now refuse a None or non-dict body with the same 400
invalid_body / JSON_OBJECT_BODY_REQUIRED payload _handle_refresh_action
already uses in this file, so no accepted shape changes and no route
in this module can leave a request hanging with no response.

refs #768

Lane: openxfactory-2
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 12, 2026 02:19
@sourcery-ai

sourcery-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR hardens the loopback-gated DTN and staging seed handlers by requiring JSON object bodies and returning the established structured 400 error instead of hanging or raising on invalid input. New end-to-end tests cover all relevant non-object and malformed-body cases while confirming the existing happy paths remain intact.

Sequence diagram for guarded seed route body validation

sequenceDiagram
    participant Client
    participant SeedHandler
    participant JSONReader

    Client->>SeedHandler: _handle_dtn_seed() or _handle_staging_seed()
    SeedHandler->>JSONReader: _read_json_body()
    JSONReader-->>SeedHandler: body
    alt body is None or not a dict
        SeedHandler->>Client: _send_json(400, invalid_body, JSON_OBJECT_BODY_REQUIRED)
    else body is a dict
        SeedHandler->>SeedHandler: body.get(project_id)
        SeedHandler-->>Client: Continue existing seed handling
    end
Loading

File-Level Changes

Change Details Files
Make both lane seed endpoints consistently reject absent, malformed, and non-object request bodies with a structured 400 response before accessing object fields.
  • Extend body validation to require a parsed dictionary.
  • Return the existing invalid_body / JSON_OBJECT_BODY_REQUIRED response shape for every rejected body.
  • Preserve existing accepted object-body behavior and route flow.
scripts/ideation_dashboard/serve_openxfactory_lanes.py
Add wire-level coverage for invalid JSON body shapes on both seed routes.
  • Test array, string, number, and boolean bodies.
  • Test malformed JSON independently from valid non-object JSON.
  • Assert HTTP 400 and the shared error payload on both endpoints.
tests/ideation-dashboard/test_shared_identity.py
tests/ideation-dashboard/test_staging_seed.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

All reviewed changes are covered and no unresolved blocking issues were identified.

Pull request overview

This pull request makes the DTN and staging seed routes reject invalid JSON bodies with consistent 400 invalid_body responses.

Changes:

  • Added object-body validation to both seed handlers.
  • Added wire-level tests for malformed and non-object payloads.
File summaries
File Summary
tests/ideation-dashboard/test_staging_seed.py Tests staging seed refusals.
tests/ideation-dashboard/test_shared_identity.py Tests DTN seed refusals.
scripts/ideation_dashboard/serve_openxfactory_lanes.py Validates seed request bodies.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sonarqubecloud

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap
brettheap merged commit 75484b6 into main Sep 12, 2026
13 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-2 (openXfactory-2)
LANDED — lane openxfactory-2 (openXfactory-2), 2026-09-12T14:58:34Z, PR #997 → 75484b6 (no Rule 6 window)
Brett Heap ${WORD_WHEN:-2026-09-11, in session, multi-choice SELECTION}, verbatim: "Land all when green and thread-free, in order". --squash --admin at head e0b1967 (code-owner review cannot clear on a self-authored PR; admin merge on his word, B2 pattern).

brettheap added a commit that referenced this pull request Sep 12, 2026
origin/main moved five commits ahead of this branch's fork point,
three of which touch files this PR also declares edits on:

- #995 (9e43f3d, ASK-7 window): four declared lines on the cli.py and
  serve.py rows of docs/opendox-carve-manifest.yaml, plus the four
  scripts/tests files that quote the running "862" declared-line total
  (carve_lines.py, validate-carve-manifest.py, verify-carve-arrival.py,
  tests/carve_manifest/test_carve_manifest.py).
- #984 (a1ef886): carve tooling/admissions hardening unrelated to the
  five rows this PR touches.
- #997, #996, #999: no overlap with this PR's files.

Conflict resolution, keeping both sides:

- docs/opendox-carve-manifest.yaml: the header comment block now
  carries the ASK-7 window's paragraph (landed first, 2026-09-11) ahead
  of the § 3.4 SLICE-S3 paragraph (2026-09-12), in landing order. The
  S3 paragraph's own arithmetic is untouched (it was already stated as
  a DELTA — "+40 over two rows" — precisely so a later-landing sibling
  act would not need to rewrite it); only its framing of the ASK-7
  window changed from "is in flight" to "already moved the running
  total to 866", since this merge is the event that makes ASK-7's
  landing a fact rather than a future one. The four ASK-7 row edits
  (cli.py:834, serve.py:155/725/1338) and the two S3 row edits
  (app.js's 37 lines, test_bullseye_widget.py's 3 lines) are all kept.
- scripts/carve_lines.py, scripts/validate-carve-manifest.py,
  scripts/verify-carve-arrival.py: each had a single docstring line
  citing the running declared-line total — "866" from main (ASK-7),
  "902" from this branch (which assumed the pre-ASK-7 base of 862).
  Corrected to 906 in all three: 866 (post-ASK-7) + 40 (this act's
  own delta) = 906, matching the pinned test assertion.
- tests/carve_manifest/test_carve_manifest.py: merged both narrative
  additions to test_the_real_manifest_carries_the_ruled_q_l7_amendment
  in landing order (ASK-7 then S3), corrected the final aggregate
  assertion from this branch's stale (902, 151) to (906, 151), kept
  main's per-row pinned ASK-7 checks (cli_row/serve_row) verbatim, and
  fixed their comment's citation of the aggregate from (866, 150) to
  (906, 151) to match the corrected assert two lines above. Also fixed
  a second, non-conflicting docstring in
  test_the_line_count_is_exactly_the_expression_the_validator_carried
  that still read "902".

A pre-existing defect, unrelated to the conflict, found while
resolving: the test_bullseye_widget.py row's two edits (already on
this branch's HEAD before any merge, commit 6843a25) had a blank line
splicing them apart, which left the `adapter calls` edit's `note:` key
duplicated with the `path constants` edit's original note — YAML
silently keeps the last of a duplicate key, so the S3 note was
silently discarded and the wrong note landed on the wrong edit.
Confirmed with a duplicate-key-aware loader before and after. Fixed by
restoring each edit's own note; a full-document duplicate-key scan
afterward finds none remaining anywhere in the manifest.

Verified after resolution:
- python3 scripts/validate-carve-manifest.py: OK, 456 rows, 168
  moved_verbatim / 150 moved_with_declared_edit / 138 not_moved.
- python3 scripts/verify-carve-arrival.py --destination opendox_code
  --phase B against openDox-code PR #14's head (09b42f5b): DECLARED
  src/opendox/web/app.js, DECLARED tests/test_bullseye_widget.py, 0
  refusals (three newly-created files admitted ad hoc for this local
  check only: src/opendox/view_extension.py,
  src/opendox/web/views/view_extension.js, tests/test_view_registry.py
  — the governed admissions-file entries for those belong to the
  pin-bump PR that follows #14's own landing, not this row-annotation
  PR). The one "unapplied" declared-edit row the summary counts is
  scripts/ideation_dashboard/doxbench_scope_types.py, an unrelated
  pre-existing row (successor #838, open at the carve) — not S3.
- pytest tests/carve_arrival tests/carve_manifest tests/carve_conformance -q:
  269 passed (121 + 110 + 38).

Lane: openxfactory-4-opendox-extraction
Refs #656

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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