Enable concurrent processing of messages across topics#103
Enable concurrent processing of messages across topics#103tschuehly wants to merge 1 commit intoRichardAtCT:mainfrom
Conversation
Store per-update thread state in a dict on the orchestrator instance
instead of setting attributes on telegram.Update (which uses __slots__).
Also whitelist Claude Code internal paths ("projects", "tasks") in
_CLAUDE_INTERNAL_SUBDIRS and allow /tmp/claude-<uid>/ for Task agent
output files to prevent "path outside approved directory" errors.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
RichardAtCT
left a comment
There was a problem hiding this comment.
Great approach — using _update_thread_states keyed by update_id is the right pattern for asyncio concurrency isolation. A few things to address:
Blocking:
-
Rebase needed — conflicts with PRs #96 (monitor.py refactored) and #110 (orchestrator.py). Move
import osto top ofmonitor.pyduring rebase. -
No automated tests — This PR's entire purpose is concurrency safety, so tests are essential. Please add tests for: (a)
_update_thread_statespopulated and cleaned up correctly, (b) two concurrent updates for the same user get isolated state, (c) cleanup still happens if_apply_thread_routing_contextraises after inserting into the dict. -
_persist_thread_statesignature change — Now takesupdateas first arg. Existing testtest_thread_mode_loads_and_persists_thread_statemay break after rebase — verify.
Non-blocking concerns:
force_new_sessionis still read from shareduser_data— a/newin topic A could leak to a concurrent handler in topic B. Pre-existing issue but worth noting.context.user_data["claude_session_id"]is still written back to shared state after each run. The per-update dict shadows it correctly during the handler, but a third concurrent handler could read a stale value from the fallback.- Potential memory leak if exception escapes
_apply_thread_routing_contextafter dict insert but before thetry/finallyin_inject_deps.
The core design is sound — these are fixable issues, not fundamental problems.
|
PR Review Summary
What looks good
Issues / questions
Suggested tests
Verdict — Friday, AI assistant to @RichardAtCT |
RichardAtCT
left a comment
There was a problem hiding this comment.
Thanks for working on concurrent topic processing! A few things need attention:
- Merge conflicts — this PR conflicts with main and needs a rebase
- CI failing — tests are not passing
- No tests — concurrent processing is tricky; please add tests covering the new behavior
- Memory leak risk — the
_update_thread_statesmethod appears to accumulate state without cleanup. Please add bounds/cleanup logic.
Please rebase against current main and address these items. Happy to re-review!
Summary
telegram.Update(which uses__slots__and raisesAttributeError)projectsandtasksto_CLAUDE_INTERNAL_SUBDIRSwhitelist so Claude Code can read its own compressed tool results and task data/tmp/claude-<uid>/paths for Task agent output filesCloses #102
Test plan
~/.claude/plans/)~/.claude/projects/)/tmp/claude-<uid>/)🤖 Generated with Claude Code