Skip to content

[bug] Guard write_file against stale or incomplete reads #269

Closed

Description

@AetherAI3

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

  1. added
    bug
    on Oct 5, 2026
  2. AetherAI3 commented on Oct 6, 2026

    @AetherAI3
    OwnerAuthor

    Implemented and merged:

    • Aether-Agent PR #294, merge commit 7971fea: write_file creates new paths exclusively. Existing-file replacement requires the digest-backed expected_revision and executor-scoped replace_token from one complete byte-mode read_file result. 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 to patch_file.
    • AETHER-CLOUD PR #1934, merge commit 4913d99: hosted model schema and prompt expose the same read/write contract. Older coding hosts requesting write_file without the new capability flag get an explicit 409 upgrade error. The synthetic doctor create/read probe remains available.

    Verification:

    • Aether-Agent: fresh exact branch checkout on Linux with Node 24, build and focused suite: 93 tests, 92 passed, 1 expected permission-mode skip. Windows build and focused suite after updating to current main: 43 tests, 42 passed, 1 expected platform skip. Cases include empty files, multibyte text, partial and line reads, stale same-size edits, atomic path swaps, a swap during staging, racing create, binary/large targets, symlinks, and staging/rename I/O failures.
    • AETHER-CLOUD: focused route, tool-schema, and engine suite: 67 passed; Python syntax compilation and git diff --check passed.
    • GitHub Actions checks on Agent PR fix: guard write_file replacements with complete-read proof #294 could not start. GitHub's annotation says: “The job was not started because your account is locked due to a billing issue.” The independent Windows and Linux runs above are the executable evidence; this was not a test assertion failure.
    • The hosted aethercloud-releases preview passed; the aether-cloud preview 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugspec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions