Skip to content

fix: Telegram /cancel command + forum topic sync for new projects - #69

Merged
Lexus2016 merged 2 commits into
mainfrom
fix/telegram-commands-and-topic-sync
Aug 25, 2026
Merged

Lexus2016 merged 2 commits into
mainfrom
fix/telegram-commands-and-topic-sync

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Fixes

  1. /cancel did nothing. _setCommands() advertised it in Telegram's native slash menu, but _handleCommand's switch had no matching case, so it fell through to "Unknown command". Added the handler: clears pending attachments and returns the user to their active session dialog, or the main menu if none.

  2. Forum topics didn't appear for projects added after /connect. Topics were only created reactively (on first chat activity) or once during the initial /connect sweep. A project added later via the Studio UI never got a topic until (if ever) some activity happened to trigger the fallback path. Added TelegramBot#notifyProjectAdded(), called from server.js right after POST /api/projects persists a new project (both the local and remote-SSH branches), and a public TelegramBotForum#ensureProjectTopic() (check-then-create, idempotent) that it delegates to.

Review

Went through 3 independent parallel checks before this PR: a correctness pass, a regression/convention pass (flagged missing test coverage, since closed — see below), and an independent second opinion via Consilium (codex/gpt-5.6-terra), which flagged a theoretical TOCTOU race in ensureProjectTopic under concurrent calls for the same workdir. Accepted as a non-issue for now: it needs two simultaneous POST /api/projects calls for the same workdir from a single-user UI, and INSERT OR REPLACE on thread_id means the worst case is a harmless duplicate row, not corruption.

Tests

Added 8 new assertions to test/telegram-behaviour.test.js (3 for /cancel, 5 for notifyProjectAdded: creation, idempotency, empty-workdir no-op). Also fixed a pre-existing test-harness leak found while writing these: a mock override in an earlier block never restored bot._callApi, silently breaking createForumTopic for every test after it.

telegram-behaviour.test.js: 63/63 passing
telegram-format.test.js: 38/38 passing

/cancel was advertised in the native Telegram command menu (_setCommands)
but had no case in the private-chat command switch, so it fell through to
"unknown command". Added _cmdCancel: clears pending attachments and lands
on the dialog overview (if a session is active) or the main menu.

Forum-mode project topics only synced on the initial /connect sweep, or
reactively when session activity happened to reference a workdir. A
project added afterward with no chat yet never got a topic. Added
ensureProjectTopic() (check-then-create, idempotent) to
TelegramBotForum, refactored _syncProjectTopics to use it, and wired
TelegramBot#notifyProjectAdded to fan out to every connected forum right
after POST /api/projects registers a project.
Adds coverage for both fixes in fc4fd21:
- /cancel clears pending attachments and lands on a sane screen instead
  of falling through to the "unknown command" reply.
- notifyProjectAdded creates exactly one topic per connected forum,
  is idempotent on repeat calls, and no-ops on an empty workdir.

Also fixes a pre-existing test-harness leak: the media-attachment block
(forum attachments land in the forum-scoped store) overwrote bot._callApi
with a mock that had no createForumTopic branch and never restored the
original afterward, so every test running after it silently got {} back
from createForumTopic instead of a message_thread_id -- surfaced as a
"cannot bind SQLite parameter 1" error swallowed by notifyProjectAdded's
own catch/warn. The new tests are what exposed it; unrelated to fc4fd21's
application code.
@Lexus2016
Lexus2016 merged commit 7a8b370 into main Aug 25, 2026
2 checks passed
@Lexus2016
Lexus2016 deleted the fix/telegram-commands-and-topic-sync branch August 25, 2026 09:22
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