Skip to content

fix(engine): make --write-devices imply --inplace on every path - #7260

Merged
oferchen merged 1 commit into
masterfrom
fix/write-devices-implies-inplace
Aug 12, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/write-devices-implies-inplace

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Upstream

parse_arguments() resolves the inplace write strategy in two adjacent blocks:

if (append_mode)   { if (refused_inplace) {...} inplace = 1; }   /* options.c:2400-2411 */
if (write_devices) { if (refused_inplace) {...} inplace = 1; }   /* options.c:2413-2419 */

Every peer runs that same function, so client and server always agree on the result.

The defect

oc reaches the strategy from two independent places, and each learned only half the rule:

Path --append --write-devices
client config (cli/.../workflow/run.rs) via ServerConfig applied inline
ServerConfig::apply_append_implies_inplace (transfer) applied missing

So a server invoked with --write-devices kept inplace = false and wrote regular files through temp+rename, where upstream writes in place. Confirmed by grep: nothing in transfer or core promotes inplace from write_devices — the only other references are doc comments and the separate write_devices && IS_DEVICE(st.st_mode) device-target branch, which is a different upstream rule (receiver.c).

This is the recurrence class, not a one-off: the --append half was fixed previously, and the sibling option was left behind precisely because the rule had two homes.

Fix

Give the rule one owner. engine already documents itself as owning the strategy the rule selects — "Temp-file write + atomic rename (--inplace bypasses the rename)" (engine/src/lib.rs:33) — so engine::write_strategy::implies_inplace(inplace, append, write_devices) holds it and both front ends call it. cli and transfer already depend on engine, so no new dependency edge is introduced.

The client expression is routed through the shared rule rather than deleted. That distinction matters: a purely local copy never reaches run_server_with_handshake_adopting, so deleting the client site would have silently dropped the promotion for local --write-devices. Verified before changing it.

Verification

  • Red check — dropping write_devices from the rule fails exactly the two tests that pin it: every_input_combination_matches_upstream and write_devices_alone_promotes. Restored and re-run green.
  • The new module carries the full 8-row truth table plus named cases for each option alone and for neither, so the rule is pinned rather than inferred from whichever call site a reader opens first.
  • cargo nextest run --workspace --all-features — 32389 passed, 0 failed.
  • cargo fmt --all -- --check clean; cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings clean.

⚠ Out of scope, flagged not absorbed

Upstream's blocks also raise create_refuse_error(refused_inplace) when a daemon refuses --inplace. oc models no refused_inplace state at all — the daemon refuse options directive is unimplemented. That is materially larger than this fix and belongs in its own change; it is not silently folded in here.

Note on the originating task

The task that prompted this recorded --write-devices as missing the implication outright. That premise was half wrong — the client already had it. Measuring first is what located the real defect (server-side only) and the real cause (one rule, two homes).

Upstream resolves the inplace write strategy in two adjacent blocks of
`parse_arguments()`:

    if (append_mode)   { ...; inplace = 1; }   /* options.c:2400-2411 */
    if (write_devices) { ...; inplace = 1; }   /* options.c:2413-2419 */

Every peer runs that same function, so client and server always agree.

oc reached the strategy from two independent places and each learned only
half the rule. The client config (`cli`) applied the `--write-devices`
implication inline; the `ServerConfig` promotion (`transfer`) applied only
`--append`. A server invoked with `--write-devices` therefore kept
`inplace = false` and wrote regular files through temp+rename where
upstream writes in place. Nothing in `transfer` or `core` promoted
`inplace` from `write_devices` at all - the only other references are doc
comments and the separate `write_devices && IS_DEVICE(st.st_mode)`
device-target branch, which is a different rule (`receiver.c`).

Give the rule one owner. This crate already owns the strategy the rule
selects - "Temp-file write + atomic rename (`--inplace` bypasses the
rename)" - so `engine::write_strategy::implies_inplace` holds it, and both
front ends call it. `cli` and `transfer` already depend on `engine`, so no
new dependency edge is introduced.

The client expression is routed through the shared rule rather than
deleted: a purely local copy never reaches
`run_server_with_handshake_adopting`, so deleting it would have dropped
the promotion for local `--write-devices` entirely.

Verified on Linux with --all-features:

  - Red check: dropping `write_devices` from the rule fails exactly
    `every_input_combination_matches_upstream` and
    `write_devices_alone_promotes`.
  - `cargo nextest run --workspace --all-features`: 32389 passed, 0 failed.
  - fmt clean; `clippy --locked --workspace --all-targets --all-features
    --no-deps -- -D warnings` clean.

Not addressed here, and deliberately left out of scope: upstream's blocks
also raise `create_refuse_error(refused_inplace)` when the daemon refuses
`--inplace`. oc models no `refused_inplace` state at all - the daemon
`refuse options` directive is unimplemented - which is materially larger
than this fix and belongs in its own change.
@github-actions github-actions Bot added the bug Something isn't working label Aug 11, 2026
@oferchen
oferchen merged commit 782f371 into master Aug 12, 2026
66 checks passed
@oferchen
oferchen deleted the fix/write-devices-implies-inplace branch August 13, 2026 10:33
oferchen added a commit that referenced this pull request Aug 24, 2026
Upstream resolves the inplace write strategy in two adjacent blocks of
`parse_arguments()`:

    if (append_mode)   { ...; inplace = 1; }   /* options.c:2400-2411 */
    if (write_devices) { ...; inplace = 1; }   /* options.c:2413-2419 */

Every peer runs that same function, so client and server always agree.

oc reached the strategy from two independent places and each learned only
half the rule. The client config (`cli`) applied the `--write-devices`
implication inline; the `ServerConfig` promotion (`transfer`) applied only
`--append`. A server invoked with `--write-devices` therefore kept
`inplace = false` and wrote regular files through temp+rename where
upstream writes in place. Nothing in `transfer` or `core` promoted
`inplace` from `write_devices` at all - the only other references are doc
comments and the separate `write_devices && IS_DEVICE(st.st_mode)`
device-target branch, which is a different rule (`receiver.c`).

Give the rule one owner. This crate already owns the strategy the rule
selects - "Temp-file write + atomic rename (`--inplace` bypasses the
rename)" - so `engine::write_strategy::implies_inplace` holds it, and both
front ends call it. `cli` and `transfer` already depend on `engine`, so no
new dependency edge is introduced.

The client expression is routed through the shared rule rather than
deleted: a purely local copy never reaches
`run_server_with_handshake_adopting`, so deleting it would have dropped
the promotion for local `--write-devices` entirely.

Verified on Linux with --all-features:

  - Red check: dropping `write_devices` from the rule fails exactly
    `every_input_combination_matches_upstream` and
    `write_devices_alone_promotes`.
  - `cargo nextest run --workspace --all-features`: 32389 passed, 0 failed.
  - fmt clean; `clippy --locked --workspace --all-targets --all-features
    --no-deps -- -D warnings` clean.

Not addressed here, and deliberately left out of scope: upstream's blocks
also raise `create_refuse_error(refused_inplace)` when the daemon refuses
`--inplace`. oc models no `refused_inplace` state at all - the daemon
`refuse options` directive is unimplemented - which is materially larger
than this fix and belongs in its own change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant