Repository navigation
Description
Problem
#248 prevents a partial read_file response from masquerading as a complete file, but write_file still accepts only path/content and opens an existing target with truncation. A caller can accidentally replace an entire file based on a bounded prefix, or overwrite a file that changed after it was read. #250 proposes targeted patch edits with expected-version checks; the current whole-file replacement operation needs its own safety contract while it remains available.
Proposed contract
Add a precondition for replacement of an existing file. A normal whole-file replacement should require evidence that the caller has the complete intended prior version, bound to a revision that is checked at commit time. An incomplete/truncated read, missing revision, or stale revision must not authorize implicit replacement. A new-file write should use create-only semantics. If an explicit force-replace capability is needed for automation, make it a separate, conspicuous user-authorized operation with clear audit output; do not let a legacy caller silently take that path.
Define the exact revision source and concurrency guarantee together with the read-continuation issue. Never truncate the existing file before validating the precondition. Stage data and replace atomically where supported, or document and handle the platform-specific failure mode. Preserve workspace path, symlink, file-type, and size protections. Propagate the contract through the canonical tool registry/protocol and relevant local/hosted consumers; plan compatibility so older callers receive a clear rejection or safe migration path rather than losing their data. For files larger than a bounded read, guide the caller toward #250's patch interface or an explicit authorized replacement flow.
Acceptance
- An ordinary replacement after a complete, current read succeeds and reports the prior/new revision or equivalent audit metadata.
- A truncated/partial read, omitted precondition, stale revision, same-size intervening edit, or atomic path replacement cannot result in a successful blind whole-file overwrite.
- New-file creation cannot overwrite a file created between decision and write; errors leave the existing content intact.
- A failed precondition or write/I/O error does not truncate or partially replace the old content. Tests include empty files, binary/unsupported content, multibyte text, permission errors, and platform-specific rename behavior.
- Existing workspace/path checks, symlink protections, and bounded-memory behavior remain intact; the write path does not read the entire old file merely to check a revision.
- Registry, protocol, local and hosted paths have one documented precondition contract, and migration tests show the behavior of legacy callers.
Priority: P1. Safety follow-up to #248; complements #250's patch-edit work and the read-revision contract in #268.
Activity
AetherAI3 commentedon Oct 6, 2026
Implemented and merged:
7971fea:write_filecreates new paths exclusively. Existing-file replacement requires the digest-backedexpected_revisionand executor-scopedreplace_tokenfrom one complete byte-moderead_fileresult. Content is staged and synced before a bounded revision recheck and same-directory rename. Successful replacement reports prior/new revisions. Legacy, partial, stale, cross-session, binary, and oversized replacements fail safely; larger files are directed topatch_file.4913d99: hosted model schema and prompt expose the same read/write contract. Older coding hosts requestingwrite_filewithout the new capability flag get an explicit 409 upgrade error. The synthetic doctor create/read probe remains available.Verification:
git diff --checkpassed.aethercloud-releasespreview passed; theaether-cloudpreview was still pending when PR #1934 merged. The focused hosted tests above verified the affected route and model schema.The documented concurrency guarantee covers host-serialized calls and detects path/content changes through the final pre-rename check. A non-cooperating external writer can still change the path in the interval between that check and rename; strict serializability against such writers requires an external workspace lock. Rename failures on filesystems or Windows sharing modes leave the old file intact.