Skip to content

fix(core): Production hardening — Bridge security, MV3 keep-alive, async resilience & token-efficient profiles - #1

Open
Ali-Rashidi-80 wants to merge 3 commits into
IrMaho:masterfrom
Ali-Rashidi-80:fix/security-and-production-hardening
Open

Ali-Rashidi-80 wants to merge 3 commits into
IrMaho:masterfrom
Ali-Rashidi-80:fix/security-and-production-hardening

Conversation

@Ali-Rashidi-80

@Ali-Rashidi-80 Ali-Rashidi-80 commented Sep 12, 2026

Copy link
Copy Markdown

🚀 TeleDOM Production Hardening, Architectural Resilience & Full Ecosystem QA


🇬🇧 English Section

📌 Executive Summary & Architectural Audit

TeleDOM is an exceptionally ambitious and technically impressive framework. Delivering 350 agentic tools, temporal DOM forensic journaling, and bidirectional Chrome extension telemetry in a single unified system is a tremendous achievement.

However, deep hostile and adversarial QA auditing identified production bottlenecks and stability gaps:

  1. Bridge Server Exposure (:3847): Unrestricted CORS (*) and missing origin checks on WebSocket upgrades allowed third-party websites to hijack the local bridge.
  2. Chrome Manifest V3 Idle Death: Chrome terminates background Service Workers after ~30 seconds of inactivity; standard timers (setInterval) inside the worker cannot keep it alive.
  3. Multi-Tab Socket Storms & Races: Injecting redundant WebSocket instances per tab caused connection storms and concurrent execution race conditions.
  4. LLM Context Window Explosion (~40,000 Tokens): Exposing 350 schemas simultaneously consumed ~40k tokens before user input.
  5. Silent Catches & Blocking I/O: Synchronous filesystem calls (fs.readFileSync) blocked the Node.js event loop during high-frequency captures, with silent catch {} blocks masking failures.
  6. Python SDK & CI Pipeline Gaps: Missing strict automated linting/typing matrices for Python 3.10–3.12 and dual-OS (Ubuntu/Windows) workflows.

This PR systematically resolves all hurdles with zero regressions and 100% backward compatibility.


💡 What This PR Delivers (Key Upgrades)

  • 🔒 Enterprise Bridge Security: CORS strictly locked to chrome-extension://* and localhost. Added optional bearer auth (TELEDOM_BRIDGE_TOKEN) and handshake origin validation.
  • 🛡️ Chrome MV3 Keep-Alive: Periodic 24s alarm heartbeat (chrome.alarms) in service-worker.ts with graceful handling for DevTools (F12) CDP collisions.
  • Up to 94% Token Reduction: Added TELEDOM_PROFILE:
    • minimal (22 tools, ~2,400 tokens) — Ultra-lean, blazing fast for standard agents.
    • core (42 tools, ~4,800 tokens) — Recommended for full autonomous navigation.
    • forensics (74 tools) & full (350 tools, default) — Full capability preserved.
  • 🏎️ Non-Blocking Async Engine: FileStorageProvider converted 100% to fs.promises. Silent swallows eliminated; disk errors provide explicit diagnostic warnings.
  • 🐍 Python SDK QA & Strict Typing: Full formatting & linting configurations ([tool.black], [tool.isort], [tool.ruff], [tool.mypy]). Tested on Python 3.10, 3.11, and 3.12 with zero errors.
  • 🔄 Cross-Platform CI Matrix (.github/workflows/ci.yml): Automated matrix jobs testing Node 18/20/22 and Python 3.10/3.11/3.12 across both Ubuntu and Windows.
  • 🎨 Futuristic 3D Branding & Modern Bilingual Docs: High-fidelity 3D holographic DOM cube logo (assets/teledom_3d_logo.png), detailed paradigm comparison tables, and fully modernized English & Persian guides (README.md & README_FA.md).

🧪 Full Verification & Test Certification Evidence

  • Build: Vite Client, Standalone Extension IIFE, Server SSR, and tsc --noEmit passed with 0 errors.
  • Vitest Unit Suite: 36 test files, 320 / 320 passed (100%).
  • MCP Operational Certification: 350 / 350 tools passed and CERTIFIED via stdio JSON-RPC.
  • Python SDK QA:
    • ruff check sdk/python: All checks passed (0 errors).
    • mypy sdk/python: Success: no issues found in 7 source files.
    • test_sdk.py: 17 / 17 passed (100%).


🇮🇷 بخش فارسی (یادداشت ارزیابی و بررسی فنی برای سازنده محترم)

💬 یادداشت ارزیابی تیم مهندسی:

سلام و خداقوت بابت زحمات ارزشمندی که برای توسعه TeleDOM کشیدی!
ایده معماری پروژه، ارائه هم‌زمان ۳۵۰ ابزار MCP، تایم‌لاین رویدادهای زمانی DOM و تلفیق آن با اکستنشن کروم کاری فوق‌العاده نوآورانه و تحسین‌برانگیز است.

هدف از این پول‌ریکوئست (PR)، تثبیت این دستاورد بزرگ و تبدیل TeleDOM به یک پلتفرم در کلاس جهانی (Enterprise-Grade & Production-Ready) است. در بررسی‌های فنی و استرس‌تست‌های صورت گرفته، چند گلوگاه زیرساختی اساسی برطرف، پایپ‌لاین CI مدرن‌سازی، و اکوسیستم پایتون و مستندات پروژه به استاندارد طلایی اوپن‌سورس ارتقا داده شد.


🛠️ دستاوردهای اصلی این پول‌ریکوئست (چرا مرج این PR حیاتی است؟):

  1. امنیتی‌سازی کامل سرور محلی (Bridge Server روی پورت ۳۸۴۷):
    • محدودسازی CORS فقط به اکستنشن کروم و لوکال‌هاست، اعتبارسنجی Origin در وب‌سوکت و افزودن توکن اختیاری (TELEDOM_BRIDGE_TOKEN) جهت جلوگیری از دسترسی صفحات مخرب وب به مرورگر کاربر.
  2. پایداری دائمی افزونه کروم در Manifest V3 (حل خاموشی پس از ۳۰ ثانیه):
    • افزودن پالس منظم ۲۴ ثانیه‌ای با chrome.alarms برای زنده نگه‌داشتن Service Worker در کروم و رفع قطعی‌های میانه کار با ایجنت‌ها.
  3. بهینه‌سازی تا ۹۴٪ مصرف توکن برای مدل‌های زبانی (TELEDOM_PROFILE):
    • ایجاد پروفایل‌های سریع و کم‌هزینه (minimal با ۲۲ ابزار و ~۲,۴۰۰ توکن، core با ۴۲ ابزار و ~۴,۸۰۰ توکن) در کنار حفظ حالت پیش‌فرض کامل ۳۵۰ ابزار بدون هیچ‌گونه حذف یا تغییر در قابلیت‌ها.
  4. موتور غیرمسدودکننده (Async I/O) و رفع خطاهای خاموش:
    • تبدیل تمامی عملیات خواندن/نوشتن تاریخچه به fs.promises غیرمسدودکننده و حذف تمامی بلوک‌های catch {} خاموش به همراه هشدارهای تشخیصی شفاف.
  5. ارتقای کامل اکوسیستم پایتون (Python SDK QA):
    • پیکربندی و اجرای موفق تست‌های Ruff، Mypy، Black و Isort در pyproject.toml و پاس شدن ۱۰۰٪ تست‌های آزمون SDK.
  6. ماتریس تست گیت‌هاب اکشنز (CI/CD):
    • پشتیبانی از اجرای هم‌زمان روی ابونتو و ویندوز برای نود ۱۸ تا ۲۲ و پایتون ۳.۱۰ تا ۳.۱۲.
  7. برندینگ سه‌بعدی و مستندسازی جامع دو زبانه:
    • افزودن لوگوی سه‌بعدی هولوگرافیک پروژه، جداول مقایسه پارادایم با Playwright/Puppeteer، و مدرن‌سازی کامل README.md و README_FA.md.

🛡️ تضمین سلامت پروژه (Zero Regressions):

  • بیلد کامل و کامپایل TypeScript: ۰ خطا.
  • تست‌های واحد (Vitest): ۳۲۰ از ۳۲۰ تست پاس شد (۱۰۰٪).
  • تست عملیاتی ۳۵۰ ابزار: ۳۵۰ از ۳۵۰ پاس شد (دارای نشان رسمی CERTIFIED).
  • تست‌های پایتون: ۱۷ از ۱۷ پاس شد (۰ خطای لینت و سیستم انواع).

با احترام تقدیم به شما برای پیشرفت هرچه بیشتر جامعه اوپن‌سورس! 🤝

Ali Rashidi added 2 commits September 12, 2026 10:53
…orms and add tool profiles

- Security: Lock down CORS on bridge server (:3847) to trusted origins (chrome-extension:// and localhost), add optional TELEDOM_BRIDGE_TOKEN auth for mutating endpoints (/api/mcp/tool, /api/tabs/close), and reject untrusted cross-origin WebSockets.
- MV3 Resilience: Add 'alarms' permission and periodic alarm keep-alive to prevent Service Worker idle termination after 30 seconds.
- Socket Storm Fix: Remove direct WebSocket instantiation in content-script; route all commands cleanly through Service Worker via chrome.tabs.sendMessage to prevent multi-tab broadcast race conditions.
- Token Optimization: Introduce TELEDOM_PROFILE ('minimal', 'core', 'forensics', 'full') slashing context overhead from ~40,000 tokens to ~2,500-4,800 tokens for lean agent setups.
- Async I/O: Convert synchronous fs.*Sync calls in FileStorageProvider to non-blocking fs.promises.* to prevent Node.js event loop lag during high-frequency DOM mutation recordings.
- DevTools Parity: Provide graceful error message when Chrome DevTools (F12) is already open on a tab during CDP attach.
@Ali-Rashidi-80
Ali-Rashidi-80 force-pushed the fix/security-and-production-hardening branch 7 times, most recently from 1e711d2 to d0b65af Compare September 12, 2026 11:00
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