Skip to content

fix(participation): detect deleted topics by posting into them; recreate only on thread-gone - #46

Merged
TOMOKI977 merged 5 commits into
mainfrom
fix/participation-topic-check
Sep 29, 2026
Merged

TOMOKI977 merged 5 commits into
mainfrom
fix/participation-topic-check

Conversation

@TOMOKI977

Copy link
Copy Markdown
Contributor

Summary

This fixes a bug in hackathon-participation that the production smoke test surfaced.

The bug: a user deleted a linked topic (topic 262). /hackathon join still replied "Este hackathon ya tiene tema: …/262" with a dead link. The existence check used sendChatAction, and Telegram accepts that call even for a deleted thread, so it could never detect the deletion.

The fix: the bot now checks an existing linked topic by doing the real action, which is posting the analysis into it (post + re-pin via postAnalysisAndLinkTopic).

  • Post succeeds: the topic is live. The bot replies "Este hackathon ya tiene tema: ", and the analysis is re-posted and pinned there.
  • Post fails with thread-gone: this is a 400 whose description matches message thread not found / TOPIC_ID_INVALID / TOPIC_DELETED. The topic is deleted, so the existing path runs: claim, create, link, post/pin, confirm.
  • Any other failure (a closed topic, 403/no rights, another 4xx, 5xx, 429, or something unexpected) is logged as topic-check-failed. The bot replies with the link and does not recreate, so a live topic is never duplicated.

Changes

  • src/adapters/telegram/send-failure.ts: new classifyPublishFailure, which emits thread-gone only for a 400 with a thread-gone description. A 403 with the same wording stays rejected. classifyTelegramFailure is unchanged, so the alert sender behaves as before.
  • src/adapters/telegram/chat-publisher.ts: only post() uses the new classifier. pin, unpin and clearButtons are unchanged.
  • src/domain/errors.ts: adds PublishFailureClass = AlertSendFailureClass | "thread-gone".
  • src/domain/usecases/participate-in-hackathon.ts: only thread-gone recreates.
  • src/domain/usecases/run-hackathon-job.ts: thread-gone is handled like rejected (no retry).
  • ForumTopicManager.probe is removed from the port, the adapter, the fakes and the tests.
  • Docs: proposal.md, design.md and the spec now describe the post-based check and its residual risk. If Telegram's deleted-thread wording differs, the topic is not recreated, which is the safe side, and the smoke test confirms the wording.

Review

  • A first review found a CRITICAL issue: any 4xx was being treated as "deleted", so a closed topic or a 403 could create a duplicate. I corrected it, and a fresh review over all 16 changed paths approved the change.
  • One deferred warning remains: the thread-gone line in run-hackathon-job.ts has no test.

Tests

  • Strict TDD.
  • The full suite passes (1027 tests) and the typecheck is clean.

🤖 Generated with Claude Code

@TOMOKI977
TOMOKI977 merged commit 3452753 into main Sep 29, 2026
2 checks passed
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