Skip to content

fix: tunnel reconnection stability and manual pairing reliability#2

Open
comlibmb wants to merge 4 commits into
Forkoff-app:mainfrom
comlibmb:main
Open

fix: tunnel reconnection stability and manual pairing reliability#2
comlibmb wants to merge 4 commits into
Forkoff-app:mainfrom
comlibmb:main

Conversation

@comlibmb
Copy link
Copy Markdown

@comlibmb comlibmb commented May 4, 2026

Summary

Multiple fixes for tunnel reconnection stability when using cloudflared quick tunnels.

Changes

  1. Tunnel Notifier (src/tunnel-notifier.ts)

    • Normalize tunnel URL to wss:// format before storing in Supabase
    • Add 5-retry with exponential backoff for Supabase upsert failures
    • Preserve existing pairing_code on tunnel restart (don't overwrite to null)
  2. Session Preservation (src/index.ts, src/tools/claude-process.ts)

    • Distinguish graceful disconnect vs network interruption
    • Network interruption: keep taken-over sessions for 5 min TTL
    • Cancel TTL timer when mobile reconnects
  3. Environment Variables (src/tunnel-notifier.ts, src/index.ts)

    • Move Supabase credentials from hardcoded to env vars (FORKOFF_SUPABASE_URL, FORKOFF_SUPABASE_ANON_KEY)
    • Add dotenv for .env file loading
    • Add .env.example template

Bug Fixes

  • Tunnel restart caused pairing_code to be cleared from Supabase, breaking manual pairing
  • Network interruption immediately cleared all sessions, requiring re-take-over on reconnect
  • Supabase update failures with no retry caused mobile to never learn new tunnel URL

Test Plan

  • Kill cloudflared → CLI restarts tunnel → mobile auto-reconnects
  • Manual pairing code works after tunnel restart
  • Sessions preserved after brief disconnect
  • E2EE re-established after reconnect

comlibmb and others added 4 commits May 4, 2026 13:04
- Add TunnelNotifier with URL format normalization (wss://) and 5x retry with exponential backoff
- Preserve pairing_code in Supabase during tunnel restarts (don't overwrite with null)
- Distinguish graceful disconnect from network interruption (keep sessions 5min TTL)
- Add session TTL mechanism: clearAllTakenOver runs on timeout, cancelSessionTTL on reconnect
- Add connected event listener to cancel session TTL when mobile reconnects

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded Supabase URL and anon key with FORKOFF_SUPABASE_URL
and FORKOFF_SUPABASE_ANON_KEY environment variables.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add dotenv to load .env file
- Import dotenv/config in entry point
- Supabase URL/key no longer hardcoded in source

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Users who put phone away for 10-15 minutes should not lose taken-over sessions.
Previous 5-minute TTL was too short for real-world usage.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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