Skip to content

fix(typing): guard fireStart against post-close invocation#26325

Merged
ngutman merged 4 commits intoopenclaw:mainfrom
win4r:fix/typing-firestart-guard
Feb 25, 2026
Merged

fix(typing): guard fireStart against post-close invocation#26325
ngutman merged 4 commits intoopenclaw:mainfrom
win4r:fix/typing-firestart-guard

Conversation

@win4r
Copy link

@win4r win4r commented Feb 25, 2026

Problem

createTypingCallbacks guards onReplyStart with the closed flag, but fireStart itself has no such guard. If a keepalive tick is already in-flight when fireStop runs, the async onTick → fireStart callback still completes and calls params.start() (i.e. sendChatAction('typing')) after the reply message has already been delivered.

On Telegram — which has no cancel-typing API — this causes the typing indicator to linger ~5 seconds after the bot's message appears.

Timeline of the race

T=0.0s  keepalive tick fires → fireStart() begins (async, in-flight)
T=0.1s  reply message delivered
T=0.2s  fireStop() → closed=true, keepaliveLoop.stop()
T=0.3s  fireStart() completes → sendChatAction('typing') sent  ← BUG
T=5.3s  Telegram typing indicator finally expires

Fix

Add if (closed) return at the top of fireStart as defense-in-depth:

const fireStart = async () => {
  if (closed) return;  // ← added
  try {
    await params.start();
  } catch (err) {
    params.onStartError(err);
  }
};

This ensures that even an in-flight keepalive tick is suppressed once cleanup has started.

Scope

One-line change in src/channels/typing.ts. No new dependencies, no config changes.

Greptile Summary

Adds defense-in-depth guard to fireStart to prevent race condition where in-flight keepalive ticks send typing indicators after cleanup. This complements the closed flag guard added to onReplyStart in a0fa283, closing the gap for async callbacks that are already executing when fireStop runs.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Single-line defensive guard that directly addresses a documented race condition. The fix follows existing patterns in the codebase (same guard is used in onReplyStart), has clear scope, and introduces no new dependencies or side effects. Existing tests cover the typing lifecycle behavior.
  • No files require special attention

Last reviewed commit: bf6240f

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@win4r
Copy link
Author

win4r commented Feb 25, 2026

CI is all green now. This is a minimal one-line defense-in-depth fix for the typing race condition — would appreciate a review when you get a chance. @steipete @ngutman

@ngutman ngutman self-assigned this Feb 25, 2026
Ubuntu and others added 4 commits February 25, 2026 14:39
The existing `closed` flag in `createTypingCallbacks` guards
`onReplyStart` but not `fireStart` itself. If a keepalive tick is
already in-flight when `fireStop` sets `closed = true` and calls
`keepaliveLoop.stop()`, the running `onTick → fireStart` callback
still completes and sends a stale `sendChatAction('typing')` after
the reply message has been delivered.

On Telegram (which has no cancel-typing API), this causes the typing
indicator to linger ~5 seconds after the bot's message appears.

Add a `closed` early-return in `fireStart` as defense-in-depth so
that even an in-flight tick is suppressed once cleanup has started.
@ngutman ngutman force-pushed the fix/typing-firestart-guard branch from 2c724e8 to f2cf7d6 Compare February 25, 2026 12:49
@ngutman ngutman merged commit 3607b73 into openclaw:main Feb 25, 2026
@ngutman
Copy link
Contributor

ngutman commented Feb 25, 2026

Landed via temp rebase onto main.

  • Gate: pnpm check && pnpm build && OPENCLAW_TEST_PROFILE=low OPENCLAW_TEST_SERIAL_GATEWAY=1 pnpm test
  • Land commit: f2cf7d6
  • Merge commit: 3607b73

Thanks @win4r!

akropp pushed a commit to akropp/openclaw that referenced this pull request Feb 25, 2026
Jackson3195 pushed a commit to Jackson3195/openclaw-with-a-personal-touch that referenced this pull request Feb 25, 2026
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
execute008 pushed a commit to execute008/openclaw that referenced this pull request Feb 27, 2026
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…nks @win4r)

(cherry picked from commit 3607b73)

# Conflicts:
#	CHANGELOG.md
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…nks @win4r)

(cherry picked from commit 3607b73)

# Conflicts:
#	CHANGELOG.md
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
thebenjaminlee pushed a commit to escape-velocity-ventures/openclaw that referenced this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants