Skip to content

#751 Commit staged revert before sending a prompt on v2 - #757

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/751-commit-staged-revert-v2
Oct 20, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/751-commit-staged-revert-v2

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • On v2 servers a revert is only staged. Both apps now call POST /api/session/{id}/revert/commit (no body) before sending the next prompt while a revert is pending. This matches the web app (packages/app/src/composer/submit.ts) and the TUI, which also commit only for prompts, not slash commands.
  • The protocol difference stays behind the remotes. SessionRepository.commitRevert defaults to a no-op returning true because v1 applies the revert itself on the next prompt. V2SessionRemote calls the new commitRevertV2 / commitRevertV2(id:) API, and ProtocolSelectedSessionRemote and DefaultSessionRepository delegate to it.
  • Composer: sendPrompt takes a beforePrompt hook that runs before the prompt request. The Session Chat view model wires it to commands.commitPendingRevert, which commits only when a revert boundary is pending.
  • If the commit fails, the send fails the same way a rejected prompt does. The prompt is not sent, the draft is restored, the error shows in the snackbar, and the revert chip stays. SessionError now maps to the same user-facing send messages as MessageError/CommandError.

Checks

  • Android: :app:assembleDebug and :app:assembleDebugAndroidTest pass. SessionChatViewModelTest (191) and SessionProtocolRepositoryTest (40) pass with 0 failures. Main source sets are ktlint-clean. The test source set has only existing violations, none on changed lines.
  • iOS: SessionChatViewModelTests and SessionProtocolRepositoryTests pass (220 tests) on a dedicated iPhone 17 / iOS 26.5 simulator. On the first run, sendPrompt_postSendReloadMatchingUser_dropsOptimistic failed once (no revert involved) and passed unchanged on the rerun.
  • New tests on both platforms:
    • send with a staged revert commits before the prompt
    • send without a revert makes no commit call
    • a failed commit leaves the prompt unsent and shows the error
    • v2 posts /api/session/{id}/revert/commit without a body
    • v1 sends no request
  • Real v2 server (scenario harness, opencode dev bc5ebf00a4), Android app on an emulator: revert "Turn 2", edit, send. Trace from /harness/history:
POST /api/session/<session>/revert/stage  -> 200
server session.revert.staged
POST /api/session/<session>/revert/commit -> 204
server session.revert.committed
POST /api/session/<session>/prompt        -> 200
Revert staged (chip, composer restored)After send: old turn 2 removed, edited prompt ran

(The missing underscore in "Turn 2edited" comes from adb text input.)

Issue

Risks / Follow-ups

  • iOS was not checked live against the v2 harness. Simulator UI access was not granted during the run, so iOS coverage is the unit tests above. v1 was not checked live either: its remote makes no request, and a test covers that.
  • If the commit succeeds but the prompt then fails, the server has already committed the revert. The revert chip clears when the session.revert.committed echo arrives, as it would in the web app.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.

On v2 servers a revert is staged and needs an explicit commit. Both apps
now call POST /api/session/{id}/revert/commit before sending the next
prompt while a revert is pending, matching the web app and TUI. v1
applies the revert itself on the next prompt, so its remote commits
nothing. A failed commit fails the send like a rejected prompt: the
draft is restored, the error shows, and the prompt is not sent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko merged commit ea16f2f into main Oct 20, 2026
@ivanfenenko
ivanfenenko deleted the fix/751-commit-staged-revert-v2 branch October 20, 2026 16:18
ivanfenenko added a commit that referenced this pull request Oct 20, 2026
Resolve SessionProtocolRepositoryTest: keep #757's commitRevert tests and
#758's v2 archive tests (which replace the old v2 archive 404 test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Commit staged revert on OpenCode 2.x

1 participant