Skip to content

E12: Content-hash anchored edits (hashline concept) for edit_file tool #24

Closed

Description

@ajianaz

What

When Tole gets an edit_file tool, adopt the hashline concept: every edit hunk is anchored to a content hash of the file, so stale anchors are rejected before they corrupt code.

Why

Adopted from oh-my-pi's hashline package (MIT). The classic edit-by-LLM failure mode: model recalls file content from stale context, patch applies to a changed file, silent corruption. Hashline binds each patch to a 4-hex content hash recorded at read time; on apply, the live file's hash must match or the patch is refused + session-aware recovery offered.

Design sketch

  • read_file (E7) returns content hash alongside content → model quotes it in edit_file(path, old_hash, ranges, new_text)
  • edit_file verifies live hash == quoted hash before applying
  • Mismatch → structured error telling the model to re-read (this is the loop-guard-compatible recovery path)
  • No new deps: simple content hash (std hasher) is enough at our scale

Acceptance criteria

  • edit_file refuses when quoted hash ≠ live hash
  • Matching hash applies cleanly, returns new hash
  • Model-facing error message instructs re-read
  • Depends on E7 (read-only file tools) landing first
  • Tier A tests: stale-anchor refusal, fresh-anchor apply, post-edit hash chaining
  • cargo clippy clean, ACs validated one-by-one

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. ajianaz commented on Aug 27, 2026

    @ajianaz
    ContributorAuthor

    Un-parking: E7 tools are merged and E4.5 tool-calling is live-proven, so the edit_file era starts now. Two design decisions vs the original sketch (both strictly better, still zero new deps):

    1. 16-hex std hasher (DefaultHasher) instead of 4-hex — better collision resistance, still no new dependencies. Hash lifetime is a single session so cross-version hasher stability is irrelevant.
    2. old_text -> new_text replacement instead of line ranges — anchors on content, not line numbers (line numbers rot when the model's context is stale; exact text match is the same evidence as the hash anchor). old_text must match exactly once; 0 or 2+ matches are actionable errors.

    The model-facing stale-anchor error instructs a re-read, which is the loop-guard-compatible recovery path.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions