Skip to content

fix: abort button works while prompt is running + CODEX_PATH_OVERRIDE support#7

Open
roy3003 wants to merge 2 commits into
benedict2310:mainfrom
roy3003:fix/abort-and-codex-path-override
Open

fix: abort button works while prompt is running + CODEX_PATH_OVERRIDE support#7
roy3003 wants to merge 2 commits into
benedict2310:mainfrom
roy3003:fix/abort-and-codex-path-override

Conversation

@roy3003

@roy3003 roy3003 commented May 14, 2026

Copy link
Copy Markdown

Problem

Two bugs found while running TeleCodex in production:

1. Abort button does nothing during a long prompt

Root cause: grammY processes Telegram updates sequentially (one at a time). While a prompt handler is running (which can take minutes), the Abort button's callback query sits in the queue and expires after 30 seconds before it ever gets processed. The log showed:

Telegram bot error: Call to 'answerCallbackQuery' failed! (400: Bad Request: query is too old and response timeout expired or query ID is invalid)

A secondary issue: the handler called await ctx.answerCallbackQuery() before session.abort(), so if the query was already expired, the await would throw and abort would never execute.

2. CODEX_PATH_OVERRIDE env var was wired up in config but never passed to the Codex SDK constructor

The env var was read and stored on TeleCodexConfig but resetCodexClient() didn't pass codexPathOverride to new Codex({...}), so the override had no effect.

Fix

Abort fix (bot.ts):

  • All prompt call sites (text / retry / voice / photo / document) now use a startPromptTask() fire-and-forget wrapper. The handler returns immediately, freeing the grammY update queue so Abort callbacks are processed concurrently with the running prompt.
  • codex_abort callback handler now calls session.abort() first, then answers the callback query with .catch(() => {}) so an already-expired query ID never blocks the abort.

CODEX_PATH_OVERRIDE fix (codex-session.ts):

  • Pass codexPathOverride to the Codex constructor in resetCodexClient().

Test plan

  • Send a long-running prompt, press ⏹ Abort — response stops immediately
  • Set CODEX_PATH_OVERRIDE=/usr/local/bin/codex — SDK uses the specified binary

🤖 Generated with Claude Code

Alex Lee and others added 2 commits May 15, 2026 02:55
Allows pointing the SDK at an externally-installed codex binary instead
of the one bundled with the npm package, useful when the local CLI
version differs from the SDK's bundled copy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Root cause: grammY processes updates sequentially, so the Abort button's
callback query was queued behind the running prompt handler and expired
(>30 s) before being processed.

Two changes:
1. All prompt call sites (text/retry/voice/photo/document) now use
   startPromptTask(), a fire-and-forget wrapper that returns immediately
   so the grammY update queue is unblocked and Abort callbacks are
   processed concurrently.
2. codex_abort callback handler now calls session.abort() first, then
   answers the callback query with .catch(() => {}) so an already-expired
   query ID never prevents the abort from executing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant