Skip to content

Harden stale edit diagnostics and prompt lessons - #23

Closed
nvdorman wants to merge 2 commits into
enowdev:mainfrom
nvdorman:fix/stale-edit-diagnostics
Closed

Harden stale edit diagnostics and prompt lessons#23
nvdorman wants to merge 2 commits into
enowdev:mainfrom
nvdorman:fix/stale-edit-diagnostics

Conversation

@nvdorman

Copy link
Copy Markdown
Contributor

Summary

  • diagnose ambiguous edit_file matches with current line numbers
  • surface bounded near-miss context and mixed NUMBER| prefix errors for stale edits
  • require fresh, exact, unique edit context in the system prompt
  • filter malformed and duplicate learned lessons before prompt injection

Evidence

Database review found 50 edit_file failures: 41 stale/not-found old_string values and 6 ambiguous matches. Read and grep failures were invalid paths, offsets, or regex inputs rather than silent file corruption.

Tests

  • GOCACHE=/tmp/antares-go-cache GOPROXY=off GOSUMDB=off go test ./internal/tools ./internal/agent
  • GOCACHE=/tmp/antares-go-cache GOPROXY=off GOSUMDB=off go test -race ./internal/tools

enowdev pushed a commit that referenced this pull request Aug 12, 2026
…savers

The test asserted a guarantee the handler never made. handleModelSet saves
in a detached goroutine, so twenty overlapping switches land on disk in any
order; demanding that "model-19" specifically won the race failed whenever
the scheduler finished the savers out of order. It reproduced reliably at
GOMAXPROCS=2 and was the sole red check on PRs #23 and #24.

Two changes:

  - Assert what IS ordered (the in-memory pointer swap must show the last
    switch) and only that SOME save landed, not which one.
  - Use a manual temp dir and drain the savers before removing it. The
    detached goroutines outlive the test body, so t.TempDir's RemoveAll was
    racing them into "directory not empty" — the failure the deleted
    mid-test os.Remove was papering over.

Stress: 40x at GOMAXPROCS=2 green (was ~5 failures in 30), and 10x under
-race. Runtime drops from 48s to 3s.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
enowdev pushed a commit that referenced this pull request Aug 12, 2026
…ob boundary

Merges nvdorman's fix/edit-file-vps-tools. Supersedes PR #23, whose
changes are wholly contained here.

Reviewed and verified locally:
  - the byte-range splice genuinely fixes the wrong-occurrence corruption
  - configureProcessGroup preserves sandbox SysProcAttr (call ordering checked)
  - the grep/glob boundary change matches read_file's existing resolveRead;
    it is not a widening, only a consistency fix
  - majority fileEOL detection and verbatim-first matching are both correct

Follow-up fixes for four defects found in review land in the next commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@enowdev

enowdev commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Superseded by #24, which is now merged.

Every change here — internal/agent/learn.go, learn_test.go, prompt.go, internal/tools/file.go, and file_edit_regression_test.go — is contained in #24, which additionally carries the shell process-group kill, the grep/glob read boundary, and the read_file rune-split fix. Merging both would only have produced a conflict to resolve with no different end state, so this one is closed rather than merged.

The work is in main; thanks for it. Closing as superseded, not rejected.

@enowdev enowdev closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants