Skip to content

fix(agent): align record_turn detection view with the record view - #94

Merged
vinceblock99 merged 2 commits into
devfrom
fix/record-turn-view-mismatch
Jul 1, 2026
Merged

vinceblock99 merged 2 commits into
devfrom
fix/record-turn-view-mismatch

Conversation

@vinceblock99

@vinceblock99 vinceblock99 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes a record_turn() view mismatch bug.

Before this PR, record_turn() could detect file changes using one view, but record the change onto a different session view.

That could make Atomic think there was no change and return EmptyTurn, even though files changed.

Why

I found this while validating the Sherpa/noname ACP integration.

The normal hook lifecycle usually sets the view correctly first, but direct callers and fallback paths should still be safe. record_turn() should be internally consistent: it should detect changes on the same view it records to.

Testing

Added regression tests for direct record_turn() callers using a session view.

Verified with:

  • cargo fmt --check
  • cargo clippy -p atomic-agent -p atomic-repository
  • cargo test -p atomic-agent --test record_view_mismatch_regression
  • cargo test -p atomic-repository repository::tests::view_tests

record_turn detected changes via status() against the repo's current_view
but applied them to session.view_name. The real agent hook flow switches
current_view at session start, so production is unaffected — but direct
callers that bypass session start (the noname ACP→TurnOrchestrator bridge,
tests) leave detection on `dev` while apply targets the session view. A turn
whose net effect is invisible from `dev` (deleting the last file recorded on
the session view) then early-returns EmptyTurn and silently drops the turn.

Fix: align detection with the record view in two places —
- before the first status() on the read-only handle, in memory only via the
  new Repository::set_current_view_in_memory (no txn/lock/disk write, so the
  read-only anti-hang fast path is preserved);
- on the write handle, the persisting set_current_view now tolerates
  ViewNotFound (first turn) but propagates DB/write failures as RecordFailed
  instead of swallowing all errors.

record()'s filter/apply already used session.view_name, so provenance and
attestation landing are unchanged; attestation coverage improves because
turns 2..N stop being skipped. Sole production caller (turn.rs) is a no-op in
the real flow. Adds modify + delete-only regression tests (the delete-only
case is what actually reproduces the bug). Documents a known adjacent
racy-mtime hazard in the no-hash status fast path, left unfixed by design.
@vinceblock99
vinceblock99 merged commit 0e94d90 into dev Jul 1, 2026
8 checks passed
@vinceblock99
vinceblock99 deleted the fix/record-turn-view-mismatch branch August 12, 2026 13:15
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.

1 participant