Skip to content

fix(acp): Optimistic user messages and PATH fix for macOS#50

Merged
wilcorrea merged 3 commits intomainfrom
fix/optimistic-user-messages
Mar 9, 2026
Merged

fix(acp): Optimistic user messages and PATH fix for macOS#50
wilcorrea merged 3 commits intomainfrom
fix/optimistic-user-messages

Conversation

@wilcorrea
Copy link
Copy Markdown
Contributor

@wilcorrea wilcorrea commented Mar 9, 2026

Summary

  • Optimistic user messages: User messages now appear immediately in chat instead of relying solely on the acp:user-message-saved Tauri event (which could be lost or delayed). When the backend event arrives, the optimistic message is replaced in-place to preserve chronological order.
  • PATH enrichment on macOS: GUI apps launched from Finder/Dock inherit a minimal PATH, causing node (and copilot/claude binaries) not to be found (exit code 127). Added fix-path-env crate from tauri-apps to source the user's login shell PATH at startup.

Test plan

  • Send a message via chat input → message appears immediately
  • Click "Solicitar Alterações" in plan review → feedback message appears in chat
  • Reload session → messages loaded from DB without duplicates
  • Assistant messages still appear correctly after end_turn
  • Launch app from Finder (not terminal) on macOS → Copilot/Claude connection works
  • npm test passes (115 tests)

Summary by CodeRabbit

Release Notes

  • New Features

    • Messages now display instantly when sent, automatically syncing once confirmed by the server.
  • Bug Fixes

    • Improved environment path initialization for enhanced application reliability and stability.

User messages sent via `sendPrompt` did not appear in the chat history
because the frontend relied entirely on the `acp:user-message-saved`
Tauri event. If the event was lost or delayed, the message never showed.

- Add `addOptimisticUserMessage` to `useSessionMessages` that immediately
  appends a user message with a temp `optimistic-` prefixed ID
- Replace optimistic message with persisted version when the backend
  event arrives (dedup by content match)
- Call optimistic add in `sendPrompt` before backend invoke, skip for
  slash commands
The previous approach removed the optimistic message and appended the
persisted version at the end of the array, which broke chronological
order when assistant messages had already been added after it.
Now uses `findIndex` + in-place replacement to keep the message at
its correct position in the chat history.
GUI apps on macOS inherit a minimal PATH that doesn't include
Homebrew, nvm, or fnm paths. This caused `node` not to be found
when spawning copilot/claude binaries (exit code 127).

Add `fix-path-env` crate from tauri-apps which sources the user's
login shell PATH at startup, fixing all 7 spawn points at once.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 9, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request introduces optimistic message handling to the Tauri application. It adds a path environment fix dependency, applies environment corrections at startup, and implements optimistic user message creation that reconciles with persisted messages when they arrive from the server.

Changes

Cohort / File(s) Summary
Path Environment Setup
apps/tauri/src-tauri/Cargo.toml, apps/tauri/src-tauri/src/lib.rs
Added fix-path-env dependency and applied fix_path_env::fix() calls at application startup to initialize environment variables before Tauri initialization.
Optimistic Message Handling
apps/tauri/src/components/ActiveSessionView.tsx, apps/tauri/src/hooks/useSessionMessages.ts
Implemented optimistic message recording in sendPrompt that immediately adds user messages to state. Added addOptimisticUserMessage() hook method with reconciliation logic to replace optimistic entries when persisted messages arrive.

Sequence Diagram

sequenceDiagram
    participant User
    participant ActiveSessionView
    participant useSessionMessages
    participant MessageState as Message State
    participant Server

    User->>ActiveSessionView: Type & submit message
    ActiveSessionView->>useSessionMessages: addOptimisticUserMessage(text)
    useSessionMessages->>MessageState: Add optimistic message<br/>(id: "optimistic-*")
    MessageState-->>ActiveSessionView: Update UI immediately
    ActiveSessionView-->>User: Display message in chat
    
    par Send to Server
        ActiveSessionView->>Server: POST message
    and Wait for Response
        Server-->>useSessionMessages: Persisted message arrives<br/>(real id, content)
    end
    
    useSessionMessages->>MessageState: Find & replace matching<br/>optimistic message
    MessageState-->>User: Update with persisted message ID
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Hoppy paths and messages bright,
Optimistic flows take flight,
Users see their words appear,
While reconciliation draws near,
Quick as carrots, fast and right! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically summarizes the two main changes: optimistic user messages and a PATH fix for macOS.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/optimistic-user-messages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wilcorrea wilcorrea merged commit 21cff37 into main Mar 9, 2026
1 check was pending
@wilcorrea wilcorrea deleted the fix/optimistic-user-messages branch March 9, 2026 20: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