workspace.commit: a merge conflict with a few hundred hunks is refused by the control-record encoder instead of truncated
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia da put_report in engine/crates/layerfs-bridge/src/control_merge.rs:212-227 e confronta il suo conteggio degli hunk con lo scan cumulativo usato dai vicini put_lines e put_lww, controllando il limite dei record in layerfs-bridge/src/wire.rs. Aggiungi il test fornito solo encoder tramite l'API pubblica sotto engine/crates/layerfs-bridge/tests/ ed esegui cargo test -p layerfs-bridge --all-targets prima e dopo. Fatto significa che un report di 600 hunk viene codificato entro il limite wire, viene decodificato di nuovo con truncated = true, e l'affermazione della documentazione sui blocks viene corretta oppure lasciata con una decisione annotata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- LayerFS
1.1.0, checkout35d36575c1eb; Rust 1.99.1, macOS arm64 - The bug is still present on
mainandlayerfs_v2_0_0as of 2026-11-15
(engine/crates/layerfs-bridge/src/control_merge.rsis byte-identical to the
checkout above on both branches) - Reproduced on the encoder directly; no daemon, Docker or Store involved
Summary
A Workspace Commit whose Branch head moved returns a Conflict reply carrying every
conflicting hunk. The control wire holds one reply in at most u16::MAX - 16
bytes (layerfs-bridge/src/wire.rs:5-18) and the encoder is supposed to truncate
what does not fit, saying so with truncated (control_merge.rs module docs:
"conflicts and hunk lines are written while they fit and truncated says that some
were left out").
The hunk list is never bounded. put_report counts hunks with
let hunks = conflict.hunks.iter().take_while(|_| fits(out, 64)).count();
(engine/crates/layerfs-bridge/src/control_merge.rs:223). The predicate ignores
its element and out does not change during take_while, so the result is
constant: every hunk is kept whenever any hunk fits. The write loop then emits all
of them, Writer::put returns ControlError("control record limit") once the
record passes the limit, and answer_call
(engine/crates/layerfs-daemon/src/control/serve.rs:97-132) turns that into
ServeCause::Protocol and closes the send half of the connection.
The merge has already run: the conflicted Workspace has marker files installed
("A conflicted Workspace: its local base is the merge with markers",
store/commit_merge.rs). The caller gets a lost connection instead of the conflict
report, and never learns which paths conflicted.
Repro
A unit test on the encoder alone, using only public API, is enough. Drop this in
engine/crates/layerfs-bridge/tests/ and run cargo test -p layerfs-bridge:
use layerfs_bridge::control::{Answer, ConflictReport, Reply};
use layerfs_content::merge::{Conflict, ConflictKind, Hunk};
#[test]
fn large_conflict_report_encodes() {
let hunk = |i: usize| Hunk {
line: i * 4 + 1,
ours: (0..3).map(|k| format!("a{}", "x".repeat(39 - (i + k) % 7))).collect(),
theirs: (0..3).map(|k| format!("b{}", "x".repeat(39 - (i + k) % 7))).collect(),
};
let report = ConflictReport {
head: None,
base: None,
markers: false,
conflicts: vec![Conflict {
path: "/project/generated.config".into(),
kind: ConflictKind::Content,
hunks: (0..600).map(hunk).collect(),
}],
lww: vec![],
written: vec![],
truncated: false,
};
Answer { id: 7, reply: Reply::Conflict(Box::new(report)) }
.encode()
.expect("a valid conflict report must encode");
}
Measured on 35d3657 with the same 40-byte lines, 3 per side:
| hunks | encoded | result |
|---|---|---|
| 20 | 4,890 B | ok |
| 200 | 48,466 B | ok |
| 300 | 64,740 B | ok |
| 400 | — | refused: control record limit |
| 600 | — | refused |
The same happens with the more realistic shape of many files: 60 files × 10
hunks each (600 hunks total) is refused.
Input size is well inside the merge's own bound: MAXIMUM_TEXT_BYTES = 1 MiB
(core/crates/layerfs-content/src/compare/text.rs:12), and 400 hunks × 6 lines × 40 B ≈ 96 KiB of text. There is no cap on conflicts or hunks in
layerfs-content/src/merge.
Root cause
engine/crates/layerfs-bridge/src/control_merge.rs:212-227. Every other bounded
list in this file (put_lines, put_lww, the conflicts list) uses a cumulative
scan and stops at the first entry that does not fit; the hunk count alone uses a
constant predicate.
Impact
- The agent-platform case the project targets — many Agents editing large files
and merging often — produces exactly this shape: a merge conflicting in a few
dozen files, or one large generated file with several hundred conflicting
regions. - The Commit side effects have already happened (markers installed); the call
reports a transport/protocol failure. A retry then hits the marker refusal
instead, so the original conflict report is lost. - The documented contract is truncation, and
conflictsTruncatedis the flag the
SDK already exposes (layerfs-api/src/sandbox/values.rs), so callers are
prepared for a truncated report.
Proposed fix
Replace the constant predicate with the cumulative budget the neighbouring
encoders use:
let hunks = conflict
.hunks
.iter()
.scan(0usize, |size, hunk| {
*size += 8 + lines_len(&hunk.ours) + lines_len(&hunk.theirs);
Some(*size)
})
.take_while(|size| fits(out, *size))
.count();
with lines_len summing each line's clipped length plus its two-byte prefix
(the 8 covers the hunk's line number and both list counts). Result with the
patch, same inputs:
| input | encoded | kept | truncated |
|---|---|---|---|
| 400 / 600 / 1200 hunks | 64,426 B | 266 hunks | true |
| 60 files × 10 hunks | 65,226 B | 261 hunks | true |
cargo test -p layerfs-bridge --all-targets passes with the patch, and the
encoded reply decodes back to a Conflict with truncated = true.
One follow-up to decide with the fix: api/docs/agent.md says "Each conflict
keeps its original blocks count", but once the wire truncates, the SDK's
blocks becomes the kept count on the workspace.commit path (the wire does
not carry the original). Either carry the original count or amend that sentence.
Overlap check
Searched open and closed issues and PRs for conflict, truncat,
control record, hunks, merge, written twice, Workspace capacity.
Two adjacent items, both different defects:
- #355 F-041: the merge report drops its
truncatedflag for the 4,096 written
paths instore-service/src/store/commit_merge.rs. This issue is about the
control encoder refusing an over-limit reply; the flag already exists here. - #517: the bounded diff fallback silently merges away a change over ~1023 lines.
Different layer and different symptom.
No issue or PR mentions put_report, hunk truncation, or control record limit.
Verification standard
For any conflict report, Answer::encode either returns a record within
wire::LIMIT whose decoded truncated flag is true when anything was omitted,
or the input must not be valid. It must not return an error for a report the
merge can produce.
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 110
- Merge medio
- 23h 52m
- PR unite (30g)
- 138
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Ephemeral-AI-Lab/layerfs
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Ephemeral-AI-Lab/layerfs#643 ·
I maintainer di solito rispondono entro 1 giorno
-
`branch.publish` accepts a stale base and overwrites `main` (lost update)Forse già presa @mengmengmengqiang l’ha presa oggi. Apertaapi/calls bug core/history
Ephemeral-AI-Lab/layerfs#691 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
Ephemeral-AI-Lab/layerfs#684 · 10 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
docs
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
Ephemeral-AI-Lab/layerfs#683 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Ephemeral-AI-Lab/layerfs#676 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Ephemeral-AI-Lab/layerfs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
pop-os/cosmic-settings#2296 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
jonathanong/no-mistakes#3431 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Eyevinn/open-live-ingest#36 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno