Repository navigation
Description
Summary
The isolated Headless Edit tool can silently append non-UTF-8 bytes to edited files when the executor adds shell job-control output to stdout.
This was reproduced in the semantic-compact A/B runs behind #1021, but it is independent of semantic compaction. It affects the isolated file-edit transport itself.
Observed behavior
An isolated Edit reads the target using:
base64 < "$target"The executor may append a shell notification such as:
[1]+ Done env MAKA_HARBOR_COMMAND_SCOPE=...
The current reader removes whitespace and passes the entire stdout to Node's permissive Base64 decoder:
const stdout = await execFileCommand(...);
return Buffer.from(stdout.replace(/\s+/g, ''), 'base64');Characters from the job-control notification that belong to the Base64 alphabet are decoded as additional file bytes. In the observed failures, both edited files gained the same 25-byte non-UTF-8 suffix.
Re-encoding the suffix produced:
1+DoneenvMAD8cBEE5H8I4wwA0P9II48
The 1+DoneenvMA prefix directly identifies the contaminating job-control notification.
Reproduction evidence
Two independent sanitize-git-repo cells edited UTF-8 files with the isolated Edit tool and later failed verification with:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 1951
Affected files included:
/app/dclm/ray_processing/ray_cluster.yaml/app/dclm/ray_processing/process.py
One later cell detected and removed the 25-byte suffix during the agent run, but the verifier still observed the same suffix. The initial corruption mechanism is proven; the later reappearance needs focused lifecycle instrumentation.
The passing comparison arms avoided the failure only because they subsequently rewrote the complete files using truncating Python writes. That masked the deterministic Edit corruption.
Root cause
readIsolatedFileBytes treats the executor's complete stdout as an unframed Base64 payload and relies on permissive decoding.
The transport has no boundary, length, checksum, or strict alphabet validation, so unrelated stdout can become file content without producing an error.
Current seam:
packages/headless/src/tools.tsreadIsolatedFileBytesEDIT_READ_BYTES_SCRIPT
Expected behavior
- Isolated
Editmust reproduce the target bytes exactly before applying a replacement. - Any stdout outside the framed payload must be rejected rather than decoded.
- A successful edit must never introduce bytes unrelated to
old_stringandnew_string. - Executor diagnostics and job-control notifications must not share an unframed data channel with file contents.
Suggested fix
Use a framed transport with strict validation, for example:
- emit an explicit payload marker and encoded byte length;
- extract only the framed Base64 payload;
- reject characters outside the canonical Base64 alphabet;
- decode and verify the expected byte length or SHA-256;
- optionally verify the post-write bytes before reporting success.
Do not solve this by merely stripping the currently observed [1]+ Done text; other executor noise would remain capable of corrupting files.
Regression coverage
Add an isolated Edit test whose executor returns:
<valid base64 payload>
[1]+ Done env MAKA_HARBOR_COMMAND_SCOPE=...
Verify that:
- the edit fails closed, or correctly extracts only a framed payload;
- the resulting file contains no trailing bytes;
- shortening and lengthening replacements both preserve all unrelated bytes;
- non-UTF-8 exact edits remain supported without lossy decoding;
- concurrent edits retain the existing per-file serialization guarantees.
Also add an integration-level check through the real Harbor executor boundary so the test does not rely only on a clean mock stdout.
Impact
This can convert a correct model edit into a verifier failure, contaminate benchmark effectiveness results, and make the failure look like model behavior. It should be treated as harness/tooling corruption rather than a semantic-compaction regression.
Activity
Nyvo-io commentedon Jul 16, 2026
I’d like to take this issue.
I checked the current seam and confirmed that this should be fixed as a transport-integrity problem, not by stripping the observed job-control string. My proposed scope is:
base64 < targetstdout contract with a versioned frame that binds the payload length and SHA-256;The read/validation path will fail closed before applying a replacement, and diagnostics will remain separate from file bytes. I’ll also review the write/result boundary for an exact post-write assertion if it can be added without changing the broader executor protocol.
I found no open PR referencing #1111 or an equivalent in-flight fix. Please assign it to me if this scope matches the intended fix.
Astro-Han commentedon Jul 16, 2026
Scope looks right, assigning to you.
One thing I didn't flag in the issue: this blocks the semantic-compact A/B runs behind #1021, and I need to run those today. I'll unblock myself with a throwaway local patch (fail-closed frame extraction only, no PR) and drop it once your fix lands, so there's no time pressure on your side.
If you do end up with a fail-closed version in the next few hours, ping me and I'll review right away and use that for today's runs instead.
Nyvo-io commentedon Jul 16, 2026
@Astro-Han The fail-closed implementation is ready for review in #1147.
The current CI run is fully green: typecheck, test, and e2e all pass. The fix uses an exact versioned frame with byte length and SHA-256 validation, rejects any ambiguous stdout contamination before writing, and verifies the stored bytes with an exact post-write readback. It also includes Harbor executor-boundary and non-UTF-8 regression coverage.