Skip to content

Typing indicator stuck after d5f08897 - race condition in typing controller #264

@cash-echo-bot

Description

@cash-echo-bot

Symptom

After commit d5f0889 ("fix: stop typing after dispatcher idle"), the typing indicator stays on indefinitely and never clears.

Root Cause Analysis

In src/auto-reply/reply/typing.ts, the ensureStart() function resets the completion flags:

const ensureStart = async () => {
  if (!active) {
    active = true;
    runComplete = false;   // <-- Resets flag
    dispatchIdle = false;  // <-- Resets flag
  }
  if (started) return;
  started = true;
  await triggerTyping();
};

The maybeStopOnIdle() function only calls cleanup() when BOTH runComplete AND dispatchIdle are true:

const maybeStopOnIdle = () => {
  if (!active) return;
  if (runComplete && dispatchIdle) cleanup();
};

Race Condition

If the agent run completes quickly (before any output triggers typing):

  1. Agent finishes → markRunComplete() sets runComplete = true
  2. Agent returns output → reply dispatcher starts delivering
  3. Delivery triggers startTypingOnText()ensureStart() runs
  4. ensureStart() sets runComplete = false (because !active is true)
  5. Typing interval starts
  6. markDispatchIdle() is called → maybeStopOnIdle() checks flags
  7. runComplete is now false → cleanup never happens
  8. Typing continues forever

Suggested Fix

Don't reset the completion flags in ensureStart(). The flags should only be set to false on initial construction or after a full cleanup():

const ensureStart = async () => {
  if (!active) {
    active = true;
    // Don't reset runComplete/dispatchIdle here
  }
  if (started) return;
  started = true;
  await triggerTyping();
};

Or track completion state separately from the "should stop" decision.

Environment

  • Commit: d5f0889
  • Surface: Discord (likely affects all surfaces)

Workaround

Revert to parent commit or apply the suggested fix above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions