Skip to content

mac: accept the compiler's help.replacement shape, so a suggested fix stops killing the preview frame - #488

Merged
GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/help-replacement-wire-shape
Sep 15, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/help-replacement-wire-shape

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

The bug

The compiler nests a suggested fix's range inside source, reusing the labels[].source shape so a fix can name a file other than the diagnostic's own (crates/compiler/src/diagnostics.rs):

"help": {"message": "did you mean \alpha?",
         "replacement": {"source": {"start_byte": 5, "end_byte": 11, "path": "main.tex"},
                         "text": "\alpha"}}

Both Swift decoders required a flat start_byte/end_byte on replacement and parsed source for its path only, throwing the range away:

  • FastJSON.swift:364 — throw error("replacement missing start_byte")
  • RuntimeV1.swift — startByte = try c.decode(Int.self, forKey: .startByte)

Why it is worse than a missing fix

PreviewControllerClient tries FastJSON and falls back to the reference decoder. Both throw, so the update becomes .protocolViolation("preview update: ...") and the entire preview frame is discarded — pages and diagnostics together, not just the fix. Any document whose compile produced a did-you-mean would lose its preview update.

This is the Tab-to-apply-fix path.

Why it survived on main

Nothing has ever emitted the flat shape. The compiler is the only producer of help.replacement and its own unit tests assert the nested spelling; Swift's tests used hand-written flat fixtures. Each side was self-consistent, so only a cross-boundary test could see the disagreement — and those tests XCTSkip unless the Rust binaries are built and pointed at by env var:

default `swift test`:  1234 tests, 137 skipped,  3 failures
with the binaries:     1234 tests,  12 skipped, 18 failures

Five of those failures are this bug. The contract never specified help.replacement at all, which is the root cause.

The fix

Both decoders take the range from source when the flat pair is absent. The flat pair still wins when both are present, so testHelpReplacementDecodesBareOrWithPath and every existing expectation are unchanged. A replacement with no range in either place is still rejected — and now only the replacement, per the contract rule added here.

docs/contracts/runtime-v1.md now specifies the shape, the UTF-8/zero-based/end-exclusive offsets, the precedence rule, and that a consumer must reject an unusable replacement alone rather than the enclosing frame.

Tests

  • testHelpReplacementAcceptsTheCompilersNestedSourceRange — the exact bytes diagnostics.rs asserts it writes.
  • testNestedReplacementRangeDecodesIdenticallyInBothDecoders — FastJSON and the reference decoder agree on that frame.
  • testFlatReplacementOffsetsWinOverNestedOnes, testReplacementWithNoRangeAtAllIsRejected.

Gated on mac-m1max-a with the Rust binaries wired in.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)

…ling the frame

The compiler nests a suggested fix's range inside `source`, reusing
`labels[].source` so a fix can name another file:

  "replacement":{"source":{"start_byte":5,"end_byte":11,"path":"main.tex"},
                 "text":"\\alpha"}

Both Swift decoders required a flat `start_byte`/`end_byte` on `replacement`
and read `source` for its path only, so both threw on every diagnostic that
carried a fix. PreviewControllerClient tries FastJSON and falls back to the
reference decoder; with both failing, the update became
`.protocolViolation("preview update: ...")` and the *whole* preview frame was
dropped -- pages and diagnostics together, not just the fix.

Nothing has ever emitted the flat shape. The compiler is the only producer of
`help.replacement`, and its own tests assert the nested spelling. Swift's tests
used hand-written flat fixtures, so each side passed alone and only a
cross-boundary test could see the disagreement -- and those tests skip unless
the Rust binaries are built and pointed at by env var, which is why this sat on
main. With them wired up, five tests fail on this.

Both decoders now take the range from `source` when the flat pair is absent;
the flat pair still wins when both appear, so existing expectations hold. The
contract had never specified `help.replacement` at all, which is the root cause;
it now does, including the precedence rule.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
@GoKubar
GoKubar merged commit cdb0358 into main Sep 15, 2026
21 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
…#490)

The step read

  run: swift test 2>&1 | tee swift-test.log | grep -vE '^\s*$' | tail -n 400

A `run:` step's default shell is `bash -e`, and a pipeline's exit status is its
LAST command's. `tail` always succeeds, so the step returned 0 no matter how
many tests failed. `bash -e -c 'false | tee /dev/null | tail -n1'` exits 0;
with `set -o pipefail` it exits 1.

The mac job has therefore been reporting success over real failures. Gating
main on `mac-m1max-a` with the helpers wired in finds 7 failing tests that CI
called green (capture acceptance 2, multi-file navigation 2, real-compiler
spans 1, output bounds 2).

`scripts/ci/build-helpers.sh | tee -a "$GITHUB_ENV"` has the same hole, in
both ci.yml and release.yml, and it compounds: a failed helper build is hidden
by `tee`, the FLASHTEX_* lines never reach the environment, and the ~126 tests
that drive real binaries then XCTSkip. The job goes green having tested none of
the Rust/Swift boundary -- which is how the `help.replacement` contract break
(#488) survived.

The iPad job already wraps both of its piped `xcodebuild` steps in
`set -o pipefail`; these three were the ones that missed it.

Expect the mac job to go red until those 7 are fixed. That is the point.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
@GoKubar
GoKubar deleted the agent/kabir-claude/help-replacement-wire-shape branch September 16, 2026 04:17
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.

1 participant