Skip to content

fix(architecture): map-landscape reads a reformatted record as empty, exit 0 #4640

Closed

Description

@kyle-sexton

Problem

The map-landscape record format is one repository object and one edge object per line. This is
documented and deliberate: landscape-record.sh:31-51 says it keeps the file diffable and parseable
without a JSON library.

The readers check only that "schema_version": 1 appears somewhere in the file, then match repository
lines with /^[[:space:]]*\{"name":/. That match appears at render-landscape.sh:154 (version check)
and render-landscape.sh:325, :597, :634, :648 (line matching), and at landscape-record.sh:357
and :362 in the drift path.

A record that is valid JSON but formatted differently (compacted to one line, or pretty-printed with
one key per line) therefore passes the version check and matches no repository line. The two readers
then fail as follows:

  • Renderer: writes an empty landscape and exits 0. It prints thin=yes, so the skill's Thin result remedy (added in feat(architecture): map-landscape reports a thin landscape and names the richer view #4559) tells the user they picked the wrong tool, when the actual problem is
    a record the reader cannot parse. The header metadata also falls back to unknown.
  • Drift check: reports every repository and edge as added. It adds a "NOT COMPARABLE ... posture
    mismatch" note instead of saying the committed record could not be parsed.

This only affects records that were hand-written or reformatted. Records produced by the collector
always have the expected layout. Still, a committed landscape.json that someone reformats is a
realistic way to hit it.

Evidence

Verified this pass, in a scratchpad sandbox on main a6ba321:

  1. Created a copy of docs/architecture/landscape.json with all newlines removed (tr -d '\n').
  2. Rendered the original copy with render-landscape.sh --record <file> --out <dir>. Output:
    landscape: internal=13 external=94 drawn_systems=18 edges=108 drawn_edges=18 unresolved_edges=0 thin=no.
  3. Rendered the single-line copy the same way. Output: landscape: internal=0 external=0 drawn_systems=0 edges=0 drawn_edges=0 unresolved_edges=0 thin=yes, exit 0. landscape.md contains an empty
    C4Context block, and its header reads "Generated on unknown from unknown".
  4. Not tested: a pretty-printed record with one key per line. It is inferred to fail the same way,
    because no line in it would start with {"name":.
  5. Ran landscape-record.sh --drift-against <single-line copy> .. It reported "added repository:
    claude-code-plugins" plus every edge as "added edge", under a posture-mismatch note. The exit code was
    not captured cleanly: the output was piped to head, so the observed 141 is SIGPIPE. That the drift
    check exits 3 is inferred from the script's exit contract (landscape-record.sh:72).

Proposed approach

Keep the line-oriented format; it is a deliberate choice. Make both readers refuse a record they cannot
parse, instead of reading it as empty:

  • In render-landscape.sh and in the --drift-against path of landscape-record.sh, after the
    schema_version check, check that the "repositories": [ and "edges": [ arrays either close on
    the same line (empty arrays) or are followed by object lines of the expected shape.
  • A record that declares entries but matches no repository line fails with exit 1 and a message such
    as "record is not in the one-object-per-line layout landscape-record.sh writes; regenerate it". This
    reuses the existing "unreadable record" exit code.

Alternative: normalize any valid JSON into the line layout before parsing. Rejected, because it needs a
JSON parser, and the scripts' portability rule forbids jq and python (render-landscape.sh:59).

Files:

  • plugins/architecture/skills/map-landscape/scripts/render-landscape.sh, landscape-record.sh, and
    their .test.sh files
  • SKILL.md, if the report wording changes
  • plugins/architecture/.claude-plugin/plugin.json (patch bump) and CHANGELOG.md

Acceptance criteria

  • render-landscape.sh given a single-line record exits non-zero with a message naming the layout
    problem, and writes no artifacts.
  • render-landscape.sh given a pretty-printed record (one key per line) behaves the same way.
  • landscape-record.sh --drift-against given either shape exits 1 with the same kind of message and
    prints no added or removed lines.
  • A record with genuinely empty repositories and edges arrays still renders, with thin=yes
    and exit 0.
  • New cases in render-landscape.test.sh and landscape-record.test.sh fail before the fix and
    pass after it. The existing cases stay green.

Constraints and gotchas

Context

Source: side finding recorded in the progress note of local handoff item
20260907-094157-architecture-mapping-skill-family-epic.md (retired with it). Found after PR #4559.
Sibling leftover from the same slice: #4554. The planned map-dependencies graph schema should avoid the
same failure mode (see that issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-ready

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions