Skip to content

fix(agent): restore session view before tools and reject recording drift - #205

Closed
vinceblock99 wants to merge 3 commits into
devfrom
fix/session-resume-view-safety
Closed

vinceblock99 wants to merge 3 commits into
devfrom
fix/session-resume-view-safety

Conversation

@vinceblock99

@vinceblock99 vinceblock99 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Resuming an OpenCode conversation after its working directory switched views could leave tools on the wrong view until Stop. Recording then treated files absent from that other view as deletions. Materialization also logged individual file-write failures while returning success, so a matching view pointer did not establish that file restoration had completed.

Prepare the session view before returning from same-ID SessionStart and before each TurnStart. Preserve pending work when switching would overwrite it. Propagate per-file materialization errors from the repository instead of counting them as successful skips; retain the successful files' index/conflict information and report the failure.

Persist a target-view completion marker before an agent restore, verify the resulting working copy, and clear the marker only after completion. Failed/interrupted restores block tools, Stop, recording, and new/fallback sessions in that canonical working copy, including after restart. Explicit repair followed by resuming the original session verifies completion and clears the marker. A successfully rendered graph conflict is valid output: it remains visible and tools can resolve it. The repository continues to refuse recording unresolved markers.

Unscoped recording also checks effective change/dependency closures before status and after acquiring a writer. Different closures are rejected instead of repairing the pointer at Stop; equivalent closures still permit fresh forks. Validated explicit manifests retain scoped behavior once preparation is complete, and sandbox working copies remain separate.

Why the pending marker exists

The existing deferred-TREE alignment marker is cleared after TREE/pointer publication, before filesystem materialization finishes. It cannot identify a later file-write failure. The new marker spans the agent's complete restore/verification interval and contains only a target view. It is operational completion state, not a file-ownership map, saved file snapshot, or source of graph history. The code comment now states that purpose directly.

Validation

  • Eight focused regressions pass: view preparation before tools, pending-work preservation/retry, record-time mismatch rejection, intentional deletion, failed write/restart/bypass protection, interrupted cleanup, resolving a successfully materialized graph conflict, and propagating a materializer file-write error. Original failures were reproduced before their fixes.
  • Full atomic-agent suite: 1,358 unit + 2 integration + 31 doctests pass; 9 doctests ignored.
  • Full atomic-repository suite: 946 tests pass; 86 existing tests/doctests ignored.
  • CLI session/error suites: 15 pass. Production-library Clippy with -D warnings passes. An additional --all-targets Clippy run hits five pre-existing test-only lints in two unchanged files (merge_property_tests.rs and integrations/install.rs); those files are identical to base.
  • Real OpenCode 1.18.31 + rollback plugin code 052bca3 + the candidate CLI + GPT-5 mini: four isolated scenarios pass, with 10 successfully recorded turns. Covered normal resume, build/Atomic-mode controls, existing edits, process restart, new-session handoff, shell-created vault memory, failed write/restart/explicit repair/continuation, and a real graph conflict restored and resolved by an Atomic agent.
  • The two deliberately failed restore attempts did not record. Successful resume/recovery changes contain only the requested edit and no unintended FileDel. The conflict case's first status tool succeeds and shows the conflict before resolution; both sides survive the recorded resolution.
  • Assertions check tool states, hook exit codes, file contents, marker states, change hunks and recorded hashes. git diff --check passes.

Scope

Keep Draft pending CI/review of this update. This does not redesign deferred TREE/path resolution, repair historical deletions, migrate old explicit-file ownership sessions, or certify concurrent writers sharing a working directory. On incomplete restoration, resolve filesystem obstructions, restore expected files and preserve other edits, then retry the original session; do not delete the marker to bypass verification. Healthy same-view edits remain allowed.

@vinceblock99
vinceblock99 marked this pull request as draft September 20, 2026 23:29
@graywolf336
graywolf336 deleted the fix/session-resume-view-safety branch October 14, 2026 18:48
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