Skip to content

sync-models: removeJsoncPath silently deletes a trailing comment on the removed member's closing line #4387

Closed

Description

@dezren39

Problem

bin/sync-models.mjs edits opencode.jsonc as text specifically so comments survive: "comment-preserving JSONC edits. The file is edited as text, one member at a time, so every byte outside the edited span (comments included) is kept" (bin/sync-models.mjs:283-284). The removal path breaks that contract for one comment position: a // comment trailing the removed member on its value's closing line is silently deleted with the member.

removeJsoncPath (bin/sync-models.mjs:406-424) deletes the span from the member's line start through the end of the line its value ends on: it advances end past the value, spaces, and at most one comma (:419-421), then cuts to the next newline (:421-422). Anything between that comma and the newline — typically a trailing comment explaining the entry — is inside the deleted span. The function's own doc comment (:404-405) only promises "Comments on other lines are kept", which is exactly the gap: the sibling inserter setJsoncMember goes out of its way to insert "after the last value, so any comma or comment that followed it stays put", so the editor's intent is to preserve trailing comments; removal is the asymmetric path.

Removals are not rare: the one production caller is the policy reconciliation in run() — every model a provider policy disallows is removed through removeJsoncPath (the antigravity-direct policy in bin/sync-models.policy.json keeps five families, so any other discovered/existing model entry is removed on the next sync). A hand-written note on such a model's closing line (why it was pinned, when its quota resets, why it must not come back) disappears with no warning, no diff summary mention, and the output still parses — the loss is silent.

Evidence (verified this run, main aebaa7f)

Verbatim-extraction probe on the laptop (~/git/fleet/probe-2026-11-02-laneA-removecomment/, source md5 5834afc1a18fd9f1a22c4e44d3fadb0f, identical on sandbox and laptop clones) — the same extraction method as bin/sync-models.test.mjs. Input models object:

"kept-model": { "name": "Kept" },
"old-model": {
  "name": "Old"
}, // retired 2026-10-30: argon quota gone
// standalone note about the next model
"other-model": { "name": "Other" }

removeJsoncPath(config, ['provider','antigravity-direct','models','old-model']) produced output where:

  • trailing comment survives: false — // retired 2026-10-30: argon quota gone is gone;
  • standalone comment survives: true, kept-model/other-model intact, old-model removed, output still parses (parseJsoncTree accepts it);
  • control (removing kept-model, which has no trailing comment) is clean and leaves the old-model trailing comment untouched — the loss is specific to the removed member's own closing line.

Why it matters

The whole reason sync-models edits JSONC as text instead of round-tripping JSON is that opencode.jsonc is a hand-maintained file whose comments carry operational knowledge. A sync that silently eats a comment on exactly the entries it deletes — the entries someone most likely annotated with why they are special — erodes trust in running the sync at all, and the information is unrecoverable once the file is written (the .backup keeps one generation only).

Acceptance criteria

  • Removing a member whose value's closing line carries a trailing // comment (after the comma, or after the value when it is the last member) preserves that comment in the output (e.g. re-homed onto its own line or the following line) — or, if preservation is judged impossible, the removal refuses with a named error in the same style as the existing shares-a-line refusal instead of deleting silently.
  • A comment between the value and the comma ("x": {…} /* note */,) is likewise not silently dropped.
  • Standalone comments on their own lines, comments inside the removed member's own span, and all existing behavior are unchanged; the post-edit parseJsoncTree/parseJsonc re-parse in run() still passes.
  • Tests in bin/sync-models.test.mjs style (verbatim extraction) cover: trailing comment after comma, trailing comment on a last member with no comma, comment before the comma, and the no-comment control.

Dedup / related

Checked open + closed issues for removeJsoncPath and sync-models comment handling (2026-11-02): #704 (closed) fixed the parseJsonc reader; #3430 covers provider-catalog-sync's stripJsonc (a different script); #2832 covers wrong-shaped-config TypeErrors in run()/the tree editor; #1799 covers limit/variant reconciliation. None covers comment loss in removeJsoncPath.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    app/sync-modelsbin/sync-models.mjs model catalog sync
    effort/xsTrivial: expected under 30 minutes of work
    on Nov 2, 2026
  2. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-a)
    • Session / ID: new-issue-creator-code-a run 2026-11-02 08:05 CST
    • Found via: filed this run
    • Task: Triage the removeJsoncPath trailing-comment loss in bin/sync-models.mjs and route the preservation fix.
    • Expectation: effort/xs — done when removals no longer silently delete a trailing comment on the removed member's closing line (preserved or explicitly refused), with extraction-style tests.
    • Links: evidence probe on the laptop: ~/git/fleet/probe-2026-11-02-laneA-removecomment/ (verbatim extraction @aebaa7f85, sync-models.mjs md5 5834afc1)
  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 2, 2026
  4. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. 14 remaining items

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  7. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: picked_up
    task: 6422 (repo-health-code-pilot, repo-worker-code, lane code-d)
    state: in-progress — resumed from existing PR
    artifact: PR #4582 OPEN at c471704 on branch queue/6422-4387-preserve-jsonc-comments — implements the accepted reject-with-named-error option (JsoncCommentRemovalError) for inline comments on a removed member line; 4 new comment-placement regressions + controls. Codex review at head: completed, no findings. No held/user-owned/do-not-merge labels on issue #4387 or PR #4582.
    next: verify tests on the laptop worktree at this head, rebase if main moved, merge under standing merge authority.

  8. added a commit that references this issue on Nov 2, 2026
  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: done
    task: 6422 (repo-health-code-pilot, repo-worker-code, lane code-d)
    state: done — fixed and merged
    artifact: PR #4582 MERGED as 5bf164b (head 2a83952 after clean rebase). Fix verified on main: bin/sync-models.mjs:439 — removeJsoncPath throws the named JsoncCommentRemovalError when an inline comment sits on the removed member line (after comma, after last-member value, between value and comma, or before a next-line comma), instead of silently deleting it; comment-free removal and standalone comments unchanged.
    verified: node --test bin/sync-models.test.mjs — 16 passed, 0 failed on the laptop at the merged head (4 new comment-placement regressions + controls). Codex review at head 2a83952: completed, no findings. Sole pending check at merge was the basic OpenCode metered-provider guard, queued in the known Actions runner backlog; merged per standing merge authority.
    Closing #4387 as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/sync-modelsbin/sync-models.mjs model catalog synceffort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions