• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

galthran-wq / telegram-scraper-service / 25725867271

12 May 2026 09:30AM UTC coverage: 67.568% (+5.3%) from 62.301%
25725867271

push

github

web-flow
feat: hot-add sessions via StringSession + pool-status endpoint (#6)

* feat: hot-add sessions via StringSession + pool-status endpoint

- SessionPool accepts both legacy .session SQLite files and new
  .stringsession text files (one Telethon StringSession per file)
- Background rescan loop discovers new session files at runtime, so
  operators add accounts without restarting the container
- add_session.py / list_sessions.py / remove_session.py read/write
  sessions_dir directly; stdin-only input keeps the blob out of ps
- /api/pool/status exposes alive/configured counts, per-session
  connected flag, and a ring buffer of recent evictions (with reason)
  for duty-agent monitoring
- retry.py now passes the Telethon exception class name into
  remove_client as the eviction reason

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(session-pool): release lock during connect + immediate rescan via /api/pool/rescan

Review fixes (from code-review pass on PR #6):

- SessionPool.rescan and add_string_session no longer hold _lock across
  the multi-second _connect() I/O. Instead they reserve the candidate
  path in a new _inflight_rescan_paths set under the lock, connect
  outside the lock, then re-acquire to append. get_next() is no longer
  blocked during a rescan storm.

- New POST /api/pool/rescan endpoint. scripts/add_session.py now calls
  it after writing the .stringsession file so the new account joins
  the pool immediately (was previously waiting up to 30s for the
  background rescan tick).

- add_session.py no longer formats the raw exception body into the
  error JSON — only the exception class name. A Telethon parse error
  could otherwise echo a fragment of the StringSession into docker
  logs / Loki.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

139 of 184 new or added lines in 6 files covered. (75.54%)

39 existing lines in 2 files now uncovered.

525 of 777 relevant lines covered (67.57%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/src/api/endpoints/pool.py
1
from fastapi import APIRouter
1✔
2

3
from src.dependencies import get_session_pool
1✔
4
from src.schemas.pool import PoolRescanResponse, PoolStatusResponse
1✔
5

6
router = APIRouter(prefix="/api/pool", tags=["pool"])
1✔
7

8

9
@router.get("/status", response_model=PoolStatusResponse)
1✔
10
async def pool_status() -> PoolStatusResponse:
1✔
11
    pool = await get_session_pool()
1✔
12
    return PoolStatusResponse(**pool.status())
1✔
13

14

15
@router.post("/rescan", response_model=PoolRescanResponse)
1✔
16
async def pool_rescan() -> PoolRescanResponse:
1✔
NEW
17
    pool = await get_session_pool()
×
NEW
18
    added = await pool.rescan()
×
NEW
19
    return PoolRescanResponse(added=added, alive=len(pool._clients))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc