Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

refactor(gemini): Improve ACP architecture, session stability and history deduplication#132

Merged
bra1nDump merged 3 commits intoslopus:mainfrom
Scoteezy:feat/acp-integration
Jan 16, 2026
Merged

refactor(gemini): Improve ACP architecture, session stability and history deduplication#132
bra1nDump merged 3 commits intoslopus:mainfrom
Scoteezy:feat/acp-integration

Conversation

@Scoteezy
Copy link
Contributor

Summary

This PR improves the Gemini/ACP backend architecture with better code organization, session stability fixes, and conversation history deduplication.

Changes

ACP Architecture Refactoring

  • Extract session update handlers into separate module (sessionUpdateHandlers.ts)
  • Reduces AcpBackend.ts from ~1350 to ~900 lines
  • Add retry logic for ACP init/newSession (3 attempts with exponential backoff)
  • Move timeouts to configurable constants (GEMINI_TIMEOUTS)

Session Stability

  • Add session swap synchronization during message processing
  • Queue pending swaps and apply between processing cycles
  • Prevents race conditions when switching devices rapidly

Model Resolution

  • Refactor createGeminiBackend to return GeminiBackendResult
  • Single source of truth for resolved model and source
  • Remove duplicate model resolution logic from runGemini.ts

History Deduplication

  • Add duplicate detection in ConversationHistory
  • Skip identical user/assistant messages
  • Prevents history inflation from retries or reconnects

Tool Detection Improvements

  • Rewrite tool name detection in GeminiTransport
  • Add ExtendedToolPattern with inputFields and emptyInputDefault
  • Add logging for unknown tool patterns

Scoteezy and others added 3 commits January 14, 2026 14:03
- Extract session update handlers into separate module (sessionUpdateHandlers.ts)
  - handleAgentMessageChunk, handleToolCallUpdate, handleToolCall, etc.
  - Reduces AcpBackend.ts from ~1350 to ~900 lines

- Add retry logic for ACP init/newSession operations
  - 3 attempts with exponential backoff (1s, 2s, 4s)
  - Improves reliability on slow starts

- Move timeouts to configurable constants
  - Add getIdleTimeout() to TransportHandler interface
  - Export GEMINI_TIMEOUTS from GeminiTransport
  - DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_TOOL_CALL_TIMEOUT_MS

- Improve tool name detection in GeminiTransport
  - ExtendedToolPattern with inputFields and emptyInputDefault
  - Remove fragile context-based heuristics
  - Cleaner, more declarative pattern matching

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@bra1nDump bra1nDump merged commit 6bebc6b into slopus:main Jan 16, 2026
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants