Repository navigation
Description
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 goneis gone;standalone comment survives: true,kept-model/other-modelintact,old-modelremoved, output still parses (parseJsoncTreeaccepts it);- control (removing
kept-model, which has no trailing comment) is clean and leaves theold-modeltrailing 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/parseJsoncre-parse inrun()still passes. - Tests in
bin/sync-models.test.mjsstyle (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
dezren39 commentedon Nov 2, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked up
14 remaining items
dezren39 commentedon Nov 2, 2026
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.
Merge pull request #4582 from developing-today/queue/6422-4387-preser…
dezren39 commentedon Nov 2, 2026
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.