queue.enqueue() blocks until the item is fully processed, so emitting
message:queued after awaiting it caused the event to fire only after AI
finishes — showing the Telegram message after the AI response.
Fix: generate turnId upfront, emit message:queued synchronously before
the await, then pass the pre-generated turnId into enqueuePrompt so that
message:processing later shares the same turnId.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adapters that don't explicitly set routing.sourceAdapterId (e.g. Telegram)
were silently dropping the message:queued EventBus emission, preventing SSE
clients from seeing cross-adapter input messages.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SSE /events stream now receives input messages from external adapters (Telegram, Discord)
with full metadata and queue lifecycle state so app can display conversation history
and accurate typing indicators.
- Add message:queued EventBus event emitted in core.handleMessage() after enqueue
(skipped for sse/api sources — app already knows its own messages)
- Add message:processing EventBus event emitted via session-bridge turn_started listener
- Generate turnId at enqueue time so both events share the same ID for client pairing
- Pass pre-generated turnId through queue → createTurnContext() to avoid ID mismatch
- SSEManager subscribes to both new events and filters them by sessionId
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update tunnel service to log detailed error messages when the OpenACP tunnel fails and falls back to Cloudflare.
- Enhance the main server logic to only warn about tunnel failures if the fallback is not in use, providing clearer feedback on tunnel status.
- Ensure fallback URLs are logged for better visibility during tunnel transitions.
- Emit agent:event on EventBus even when shouldForward()=false so /events SSE
stream receives all agent events regardless of which adapter owns the bridge
- Add SessionFactory.getOrResumeById() to resume historical sessions directly
by session ID without needing channelId+threadId lookup
- Expose OpenACPCore.getOrResumeSessionById() and use it in POST prompt route
so the app can send prompts to sessions that are in storage but not yet live
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- session-bridge: only register onPermissionRequest on primary bridge (guard via __bridgeId);
secondary bridges forward permission UI via session event listener; disconnect only clears
handler if this bridge owns it; emit permission_request after setPending for correct ordering
- session-factory: lazyResume predicate checks both topicId and threadId for non-Telegram adapters
- core: createSession and adoptSession now write platforms field alongside legacy platform field
so lazy resume can find sessions on non-Telegram adapters
- sessions route: remove as-any casts for attachAdapter/detachAdapter (OpenACPCore has these methods)
- sessions schema: add sourceAdapterId and responseAdapterId to PromptBodySchema; prompt handler
reads routing fields from validated body instead of raw request.body as any
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace listSessions() with listAllSessions() in the GET /sessions route
handler so it returns both live and historical sessions with the full
SessionSummary shape (isLive, lastActiveAt, channelId). Update all
affected test mocks to use the new API.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds the SessionSummary interface and listAllSessions() method that merges
live in-memory session data with historical store records, supporting
channelId filtering and graceful fallback when no store is configured.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Change bridges Map key from sessionId to composite "adapterId:sessionId"
- Add bridgeKey() and getSessionBridgeKeys() helpers
- Update createBridge() to accept optional adapterId param and use composite key
- Update createSession/connectSessionBridge to pass explicit channelId as adapterId
- Update handleMessage to forward message.routing to enqueuePrompt
- Add attachAdapter() to create a secondary bridge on a new adapter+thread
- Add detachAdapter() to cleanly disconnect a non-primary adapter
- Add buildPlatformsFromSession() helper for persisting multi-adapter state
- Fix AgentSwitchHandler to look up bridges using composite key
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add adapterId field and shouldForward() method to SessionBridge so that
turn events are routed only to the matching adapter while system events
broadcast to all attached bridges; silent turns (responseAdapterId=null)
suppress all turn events. Backward-compatible: null activeTurnContext
forwards everything as before.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Re-export TurnRouting from types.ts (public API)
- Add routing?: TurnRouting field to IncomingMessage interface
- Update PromptQueue to carry routing metadata with each queued item
- Processor now receives (text, attachments, routing) parameters
- Update tests to account for new routing parameter
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Create TurnContext module for multi-adapter session routing, decoupling sessions
from adapters. Provides event classification to route system events to all adapters
and turn events only to the response adapter.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sessions become global with per-session multi-bridge architecture.
Any adapter can attach/detach from sessions via explicit action.
Turn-based response routing with sealed TurnContext per event.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Persist acpState, clientOverrides, currentPromptCount, and agentSwitchHistory
during graceful shutdown so state changes within the debounce window are not
lost on restart.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Refactor category commands (/mode, /model, /thought) and bypass_permissions to
call session.setConfigOption() instead of agentInstance.setConfigOption() directly,
ensuring middleware hooks and configOptions updates are handled consistently.
Update tests to mock session.setConfigOption() instead of agentInstance.setConfigOption().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The config_option_update handler in SessionBridge was calling
persistAcpState() synchronously before updateConfigOptions() (which runs
async middleware) could complete, potentially persisting stale state.
Chain persistAcpState() in the resolved .then() callback instead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The commands_update buffer listener was only registered in the constructor,
so after switchAgent() replaced agentInstance, events from the new agent
were silently dropped. Extracted wireCommandsBuffer() and call it in both
the constructor and at the end of switchAgent().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Updated the `setConfigOption` method in the `Session` class to optimistically update the current value for select options when legacy agents return empty configOptions.
- Introduced a new method `applySpawnResponse` in the `Session` class to handle both native and legacy configOptions formats.
- Improved error logging in the `setConfigOption` method for better debugging.
- Added tests to ensure correct behavior for legacy fallback scenarios in the `Session` class and `AgentInstance` methods.
This change improves compatibility with legacy agents and enhances the overall robustness of session configuration management.
The lazy-resume flow failed after server restart because topicId was
written in a separate debounced patchRecord call (2-second window).
If the server restarted before that debounce fired, the on-disk record
had platform:{} with no topicId, so findByPlatform returned null and
the session could not be resumed.
Fix: add threadId? to handleNewSession and createSessionWithContext
options so callers can pass the Telegram topic ID at creation time.
createSession already includes platform.topicId in its initial
patchRecord({ immediate: true }) call, so the topicId is flushed to
disk atomically — no separate patchRecord needed.
Updated callers:
- telegram/commands/new-session.ts: 3 call sites
- telegram/commands/resume.ts: createSessionWithContext path
- core/assistant/assistant-manager.ts: pass threadId to createSession
Added regression tests documenting both the broken pattern (debounced
write loses topicId on crash) and the fixed pattern (included in
initial immediate save).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Added a new test to verify that allowedPaths can override ignore patterns for paths within the current working directory, ensuring proper access control for file uploads.
- Updated the path-guard logic to clarify that allowedPaths take precedence over ignore patterns.
- Simplified the plugin configuration logic for the Telegram channel by removing unnecessary mapping, directly importing the plugin when the channelId matches.