Implement periodic text streaming for Telegram message updates#27
Draft
maksyms wants to merge 3 commits intoNachoSEO:mainfrom
Draft
Implement periodic text streaming for Telegram message updates#27maksyms wants to merge 3 commits intoNachoSEO:mainfrom
maksyms wants to merge 3 commits intoNachoSEO:mainfrom
Conversation
When switching projects via /project, setWorkingDirectory() preserved the Claude Agent SDK session ID from the previous project. The subsequent call to clearConversation() only cleared the chatSessionIds map in agent.ts, but sendToAgent() falls back to session.claudeSessionId — which still held the stale ID. This caused the Agent SDK to attempt resuming a session created for a different cwd, resulting in error_during_execution on the first message after every project switch. The second message would work because the error handler cleared the stale session. Fix: clear claudeSessionId in setWorkingDirectory() when the directory actually changes, since the Agent SDK session is bound to the original cwd and cannot be resumed with a different one. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Streaming mode previously accumulated text in memory but never showed it to the user during generation, making it identical to wait mode. Now a 3-second periodic timer edits the placeholder message with accumulated plain text as Claude generates it. Final delivery remains formatted MarkdownV2. Tool operations (terminal UI) interleave naturally — tool status takes priority when active. Key changes: - New flushTextStream() method with sliding window for long content - Cursor indicator while generating - Shared rate limit between text streaming and terminal UI - Timer cleanup in finishStreaming() and cancelStreaming() - Lowered edit throttle from 10s to 3s (TEXT_STREAM_INTERVAL_MS) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nal message Two bugs introduced by the incremental text streaming commit: 1. Spinner frozen: flushTextStream() delegated to flushTerminalUpdate() every 3s but never advanced spinnerIndex, so the Braille spinner showed the same frame indefinitely. Now spinnerIndex is incremented each time flushTextStream() delegates, so the spinner cycles with every timer tick. 2. Truncated status as final message: flushTextStream() is async and could race with finishStreaming() — an in-flight flush could overwrite the final formatted response (or vice versa) leaving the "Searching web … disc…" status line as the last visible message. Fixed by setting state.finishing = true before any async work in finishStreaming(), which causes concurrent flushTextStream() calls to bail out immediately. Also raised truncateUrl() default maxLen from 40 → 60 chars so search queries are less aggressively clipped in the status line. https://claude.ai/code/session_01DVUNnHodU7bpSyqAycc48A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the message streaming mechanism to use a periodic timer-based approach for flushing accumulated text to Telegram, replacing the previous throttling logic. This improves responsiveness and provides more consistent updates during long-running operations.
Key Changes
textStreamIntervaltoStreamStatethat triggersflushTextStream()every 3 seconds (configurable viaTEXT_STREAM_INTERVAL_MS)flushTextStream()method: Periodically sends accumulated text content to Telegram with a cursor indicator, handling both plain text and terminal UI modeslastUpdatetolastEditMsfor claritylastEditedContentto track what was last sent to avoid redundant editsfinishingflag to prevent race conditions during cleanuprateLimitedUntilchecksfinishStreaming()and error handlersflushTerminalUpdate()instead of sending plain textImplementation Details
startStreaming()is called and runs independently of message editsupdateStream()and flushed by the timer, decoupling accumulation from transmissionfinishingflag ensures in-flight timer callbacks bail out gracefully during shutdownhttps://claude.ai/code/session_01DVUNnHodU7bpSyqAycc48A