vhqtvnandvhqtvn ff35f40b43 fix: resilient reconnect — preserve state on fetch fail, pause when offline (#1308)
* fix: preserve state when reconnect-time fetches fail

Several client API methods swallowed fetch/SDK errors and returned an
empty value (`[]`, `{}`), which was indistinguishable from a successful
"server says nothing here" response. Reconnect resync paths trusted that
empty result as authoritative and deleted local state — so after a
network blip (sleep/wake, wifi reconnect, tunnel switch), the UI could
show:

- sessions stuck on the "running" indicator (status never cleared)
- pending permission prompts disappearing from the UI
- pending question prompts disappearing from the UI

and only a page reload would recover. A related case: `listAgents`
silently returning `[]` defeated the 3-attempt retry loop in
`useAgentsStore` because the loop never saw an error.

The systematic fix:

- `getSessionStatusForDirectory` now returns `null` on fetch failure
  (vs the previous `{}`); the reconnect resync treats only a non-null
  response as authoritative — candidates missing from the response are
  written as `{type: "idle"}`, candidates after a failure are left
  untouched.
- `listPendingPermissions`, `listPendingQuestions`, and `listAgents`
  now throw on SDK/network failure. The pre-existing outer try/catch
  blocks in `resyncBlockingRequestsForDirectory` and the retry loop in
  `useAgentsStore` were already in the right shape — they just never
  fired because no exception was thrown. A small `formatSdkError`
  helper renders the SDK `{data, error}` shape into the thrown message.
- `permissionStore.setSessionAutoAccept` catches the new throw and
  falls back to whatever sync-store snapshots provide; the next SSE
  event or reconnect resync will catch up anything missed.

AGENTS.md gets a new "Distinguish fetch failure from empty success"
subsection documenting the principle (throw vs `T | null` patterns,
when to pick which, the retry-loop trap) so this doesn't regress.

Adds 3 regression tests covering the resync paths: existing
questions/permissions are preserved when the corresponding `list*`
method throws, and a permission-fetch failure does not block the
question block from running (verifies per-block try/catch isolation).

* fix: pause reconnect loop when offline or hidden

The SSE/WebSocket reconnect loop retried indefinitely with no awareness
of whether the browser was online or whether the tab was even visible.
Three issues compounded:

- No `online`/`offline` event handling. With a foreground tab on a dead
  network, we'd hit the server every ~5s forever, and on network
  recovery we'd wait up to ~5s for the next probe instead of reacting
  to the `online` event.
- No visibility awareness. A backgrounded PWA on a flaky link kept
  probing at the same rate as a foreground tab. The browser does
  throttle hidden-tab timers, but the intent wasn't expressed in code.
- The "exponential backoff" math
  `min(5000, max(retryDelayMs, 250) * (failures <= 1 ? 1 : 2))`
  re-initialized `retryDelayMs` to 250 every iteration, so the cap of
  5s was never reached — we waited 500ms forever after the second
  failure. Not actually exponential.

Now:

- `online` event aborts the current attempt (if disconnected) and
  cuts inter-attempt waits short. `offline` event aborts so the loop
  enters the slow-probe path immediately.
- `computeRetryDelay` returns the long cap (60s) when `navigator.onLine`
  is false or the tab is hidden; the short cap (5s) when foreground +
  online. The `online` event is the expected recovery path; the 60s cap
  is a fallback for browsers that miss the event.
- Real exponential growth: `BASE * 2^min(failures-1, 8)`, clamped.
- New `waitForRetry` helper interrupts on `online`,
  visibility-becomes-visible, and abort signal — so visibility/network
  recovery doesn't wait out the rest of the current sleep.

AGENTS.md gets a "Reconnect-loop pacing" subsection alongside the
fetch-failure rule, since they're the same family of resilience
concerns.

One regression test: simulates offline + failed first attempt + `online`
event after the failure; verifies the next attempt fires within seconds
instead of waiting the full 60s offline cap.

* fix: long-cap backoff for permanent 4xx server errors

Before this commit the reconnect loop didn't distinguish HTTP error
types. A stuck-path client (wrong URL after server upgrade) or an
expired-auth client (stale token) would hit the server at the normal
5-second cap forever — ~12 reqs/min, indefinitely, with no path to
recovery besides the user reloading.

Now the catch block extracts an HTTP status (looking on `error.status`
and `error.response.status` — the SDK exposes both depending on the
code path) and overrides the backoff:

- 4xx other than 408/429 → use the long cap (60s) immediately.
  Blind retries won't fix wrong path / bad auth / forbidden, so don't
  pound the server. waitForRetry's `online` / visibility-visible
  interrupters still apply — when an operator fixes the server-side
  config and the client comes back to foreground, recovery is prompt.
- 408 (Request Timeout) and 429 (Too Many Requests) → normal
  exponential path. Those are retryable in spirit.
- 5xx / network / unknown → normal exponential path. Unchanged.

AGENTS.md gets a new bullet under "Reconnect-loop pacing" covering
this — the rule fits naturally alongside the existing `navigator.onLine`
and visibility signals.

Two regression tests:
- A 404-throwing SDK doesn't fire a second attempt within 250ms (proves
  we left the exponential path). After `online` interrupts the wait,
  subsequent attempts fire promptly — proves the override doesn't break
  recovery once the underlying problem is fixed.
- A 429-throwing SDK recovers within 2s — proves 429 still hits the
  fast exponential path and isn't caught by the permanent-error branch.

---------

Co-authored-by: vhqtvn <8930337+vhqtvn@users.noreply.github.com>
2026-05-18 17:47:20 +03:00
2026-05-18 01:01:31 +03:00
2025-12-07 19:32:53 +02:00
2025-12-07 19:32:53 +02:00
2026-05-18 01:01:31 +03:00
2025-12-07 19:32:53 +02:00
2025-12-07 19:32:53 +02:00
2025-12-07 19:32:53 +02:00
2025-12-07 19:32:53 +02:00
2026-05-18 01:01:31 +03:00
2025-12-07 19:32:53 +02:00
2026-05-06 23:17:23 +03:00
2025-12-07 19:32:53 +02:00
2025-12-07 19:32:53 +02:00

OpenChamber

GitHub stars GitHub release Created with OpenCode Discord Support the project

OpenCode, everywhere. Desktop. Browser. Phone.

A rich interface for OpenCode. Review diffs, manage agents, run dev servers, and keep the big picture while your AI codes.

OpenChamber Chat

More screenshots

Tool Output Settings Diff View VS Code Extension

PWA Chat PWA Diff

Why use OpenChamber?

  • Cross-device continuity: Start in TUI, continue on tablet/phone, return to terminal - same session
  • Remote access: Use OpenCode from anywhere via browser
  • Familiarity: A visual alternative for developers who prefer GUI workflows

Features

Core (all app versions)

  • Branchable chat timeline with /undo, /redo, and one-click forks from earlier turns
  • Smart tool UIs for diffs, file operations, permissions, and long-running task progress
  • Voice mode with speech input and read-aloud responses for hands-free workflows
  • Multi-agent runs from one prompt with isolated worktrees for safe side-by-side comparisons
  • Git workflows in-app: identities, commits, PR creation, checks, and merge actions
  • GitHub-native workflows: start sessions from issues and pull requests with context already attached
  • Plan/Build mode with a dedicated plan view for drafting and iterating implementation steps
  • Inline comment drafts on diffs, files, and plans that can be sent back to the agent
  • Context visibility tools (token/cost breakdowns, raw message inspection, and activity summaries)
  • Integrated terminal with per-directory sessions and stable performance on heavy output
  • Built-in skills catalog and local skill management for reusable automation workflows

Web / PWA

  • Provider-aware tunnel access model with Cloudflare quick, managed-remote, and managed-local modes
  • One-scan onboarding with tunnel QR + password URL helpers
  • Mobile-first experience: optimized chat controls, keyboard-safe layouts, and attachment-friendly UI
  • Background notifications plus reliable cross-tab session activity tracking
  • Built-in self-update + restart flow that keeps your server settings intact

Desktop (macOS)

  • Native macOS menu integration with polished app actions and deep-link handling
  • Multi-window support for parallel project/session workflows
  • "Open In" shortcuts for Finder, Terminal, and your preferred editor
  • Fast switching between local and remote instances
  • Workspace-first startup flow with directory picker and steadier window restore behavior

VS Code Extension

  • Editor-native workflow: open files directly from tool output and keep sessions beside your code
  • Agent Manager for parallel multi-model runs from a single prompt
  • Right-click actions to add context, explain selections, and improve code in-place
  • In-extension settings, responsive layout, and theme mapping that matches your editor
  • Hardened runtime lifecycle and health checks for faster startup and fewer stuck reconnect states

Custom Themes

  • Use it from anywhere - Cloudflare tunnel with QR code onboarding. Scan, connect, code from your couch.
  • Branchable chat timeline - Undo, redo, fork from any turn. Explore different approaches without losing your place.
  • GitHub-native workflows - Start sessions from issues and PRs with context already attached. Review checks, merge - all in-app.
  • Project Actions - Run dev servers, configure SSH port forwarding, open remote URLs locally. Your project commands, one click away.
  • Connect to remote machines - Desktop app connects to remote OpenChamber instances over SSH, with dedicated lifecycle and UX flows.

Quick Start

Prerequisite: OpenCode CLI installed.

Desktop (macOS)

Download from Releases.

VS Code

Install from Marketplace or search "OpenChamber" in Extensions.

CLI (Web + PWA)

requires Node.js 20+

curl -fsSL https://raw.githubusercontent.com/btriapitsyn/openchamber/main/scripts/install.sh | bash
openchamber --ui-password be-creative-here
Advanced CLI options
openchamber --port 8080              # Custom port
openchamber --ui-password secret     # Password-protect UI
openchamber tunnel help              # Tunnel lifecycle commands
openchamber tunnel providers         # Show provider capabilities
openchamber tunnel profile add --provider cloudflare --mode managed-remote --name prod-main --hostname app.example.com --token <token>
openchamber tunnel start --profile prod-main
openchamber tunnel start --provider cloudflare --mode quick --qr
openchamber tunnel start --provider cloudflare --mode managed-local --config ~/.cloudflared/config.yml
openchamber tunnel status --all      # Show tunnel state across instances
openchamber tunnel stop --port 3000  # Stop tunnel only (server stays running)
openchamber logs                     # Follow latest instance logs
OPENCODE_PORT=4096 OPENCODE_SKIP_START=true openchamber                    # Connect to external OpenCode server
OPENCODE_HOST=https://myhost:4096 OPENCODE_SKIP_START=true openchamber  # Connect via custom host/HTTPS
openchamber stop                     # Stop server
openchamber update                   # Update to latest

Connect to an existing OpenCode server:

OPENCODE_PORT=4096 OPENCODE_SKIP_START=true openchamber
OPENCODE_HOST=https://myhost:4096 OPENCODE_SKIP_START=true openchamber

Bind managed OpenCode server to all interfaces (use only on trusted networks):

OPENCHAMBER_OPENCODE_HOSTNAME=0.0.0.0 openchamber --port 3000
systemd service (VPN / LAN access)

Run OpenChamber and OpenCode as separate persistent services — useful when you want to access your dev machine over a VPN (e.g. Tailscale) or LAN without a Cloudflare tunnel.

How it works:

  • OpenCode runs as its own service, binding only to localhost.
  • OpenChamber connects to it via OPENCODE_HOST and --host 0.0.0.0 makes it reachable on your VPN IP.
  • --foreground keeps the CLI process alive so systemd can track and restart it.

~/.config/systemd/user/opencode.service

[Unit]
Description=OpenCode Server

[Service]
Type=simple
ExecStart=opencode serve --port 4095
Environment="PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/YOU/.local/bin:/home/YOU/.npm-global/bin:/usr/local/bin:/usr/bin:/bin"
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

Why set PATH and SSH_AUTH_SOCK? systemd user services start with a minimal environment — no shell profile is sourced. Without an explicit PATH, OpenCode won't find tools installed via Homebrew, npm, or ~/.local/bin. Without SSH_AUTH_SOCK, git operations over SSH (push, pull, clone) will fail because the agent socket isn't inherited. Adjust the PATH to match your own tool installation paths. %t expands to $XDG_RUNTIME_DIR (e.g. /run/user/1000), where most SSH agents write their socket.

~/.config/systemd/user/openchamber.service

[Unit]
Description=OpenChamber Web Server
After=opencode.service

[Service]
Type=simple
ExecStart=openchamber serve --port 3000 --host 0.0.0.0 --ui-password your-password --foreground
Environment="OPENCODE_HOST=http://localhost:4095"
Environment="OPENCODE_SKIP_START=true"
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now opencode openchamber

OpenChamber will be reachable at http://<your-vpn-hostname>:3000 from any device on your VPN.

Note: --host 0.0.0.0 is required to listen on all interfaces. The default bind address is 127.0.0.1 (localhost only). Use --host <ip> or OPENCHAMBER_HOST=<ip> to bind to a specific interface instead.

Docker
docker compose up -d

Available at http://localhost:3000.

UI Password:

environment:
  UI_PASSWORD: your_secure_password

Cloudflare Tunnel (optional):

environment:
  OPENCHAMBER_TUNNEL_MODE: quick # quick | managed-remote | managed-local
  OPENCHAMBER_TUNNEL_PROVIDER: cloudflare

For managed-remote mode, provide:

environment:
  OPENCHAMBER_TUNNEL_MODE: managed-remote
  OPENCHAMBER_TUNNEL_HOSTNAME: app.example.com
  OPENCHAMBER_TUNNEL_TOKEN: <token>

For managed-local mode, optionally provide:

environment:
  OPENCHAMBER_TUNNEL_MODE: managed-local
  OPENCHAMBER_TUNNEL_CONFIG: /home/openchamber/.cloudflared/config.yml

Managed-local path note: OPENCHAMBER_TUNNEL_CONFIG must point to a path inside the container user home (/home/openchamber/...). If your Cloudflare config references a credentials JSON file, that file path must also be accessible inside the container (mount with volumes).

Reverse proxy notes

  • For a complete reverse proxy setup guide, see docs/REVERSE_PROXY.md.
  • Website docs source lives at packages/docs/content/docs/reverse-proxy.mdx.

Tunnel behavior notes

  • OpenChamber supports one active tunnel per running instance (port).
  • Starting a tunnel with a different mode/provider on the same instance replaces the current tunnel.
  • Replacing or stopping a tunnel revokes existing connect links and invalidates remote tunnel sessions for that instance.
  • Connect links are one-time tokens; generating a new link revokes the previous unused link.

Data Directory Permission Note: The data/ directory is mounted into the container for persistent storage (config, sessions, SSH keys, workspaces). Before running, ensure the directory exists and has proper permissions:

mkdir -p data/openchamber data/opencode/share data/opencode/config data/ssh
chown -R 1000:1000 data/

SSH/Git: If git push/pull fails, run ssh -T git@github.com in terminal.

Features

Chat & Interaction
  • Branchable chat timeline with /undo, /redo, and one-click forks from any turn
  • Multi-agent runs from one prompt with isolated worktrees for safe side-by-side comparisons
  • Voice mode with speech input and read-aloud responses for hands-free workflows
  • Plan/Build mode with a dedicated plan view for drafting and iterating steps
  • Inline comment drafts on diffs, files, and plans - send feedback back to the agent
  • Shell mode via leading ! with inline output
  • Share messages as images
  • Mermaid diagrams render inline with copy/download actions
  • Smart tool UIs for diffs, file operations, permissions, and task progress
Git & GitHub
  • Full Git sidebar with staging, commits, push/pull, branch management, and rebase/merge flows
  • PR creation with AI-generated descriptions, status checks, and merge actions
  • Start sessions from GitHub issues and pull requests with context baked in
  • Multi-remote push and fork-aware PR creation
  • Worktree integration: isolated sessions per branch, merge back with conflict handling
  • Git identities, gitmoji support, and multi-account GitHub auth
Files, Diff & Terminal
  • Workspace file browser with inline editing, syntax highlighting, and markdown preview
  • Beautiful diff viewer with stacked/inline modes, lazy loading for large changesets
  • Integrated terminal with per-directory sessions, tabbed interface, and stable heavy-output performance
  • Clickable file paths in messages - jump to exact line locations
  • File-type icons across all views for faster visual scanning
Web / PWA
  • Cloudflare tunnel with quick, managed-remote, and managed-local modes, secure one-time connect links, and QR onboarding
  • Mobile-first: optimized chat controls, keyboard-safe layouts, drag-to-reorder projects
  • Background notifications and cross-tab session tracking
  • Self-update + restart flow that keeps your server settings intact
  • Installable as PWA with project-aware naming
Desktop (macOS)
  • Connect to remote OpenChamber instances over SSH with dedicated lifecycle flows
  • Project Actions: run dev servers, SSH port forwarding, open remote URLs locally
  • Multi-window support for parallel project workflows
  • "Open In" shortcuts for Finder, Terminal, and your preferred editor
  • Fast switching between local and remote instances
  • Native macOS menu, deep-link handling, and polished startup
VS Code Extension
  • Editor-native: open files from tool output, keep sessions beside your code
  • Agent Manager for parallel multi-model runs from a single prompt
  • Right-click actions: add context, explain selections, improve code in-place
  • Session editor panel, responsive layout, and theme mapping to your editor
  • Edit-style tool results open directly in focused diff views
Customization
  • 18+ built-in themes with light/dark variants
  • Custom themes via JSON files in ~/.config/openchamber/themes/ - hot reload, no restart
  • Configurable keyboard shortcuts for chat, panels, and services
  • Font size, spacing, corner radius, and layout controls
  • Customizable project icons with upload and automatic favicon discovery
  • Skills catalog and local skill management for reusable automation

Read the Guide: Custom Themes

Context & Productivity
  • Token usage, cost breakdowns, and raw message inspection panel
  • Usage quota tracking across multiple providers with pace/prediction indicators
  • Favorite model cycling via keyboard shortcuts
  • Session folders and subfolders with drag-to-reorder
  • Persistent project notes and todos per project
  • Draft persistence per session with expanded focus mode for longer prompts

Roadmap

Active development. Here's what's being worked on or planned:

  • Windows and Linux desktop apps
  • Mobile app with remote instance and laptop connectivity
  • More built-in tunneling options
  • Kanban board for multi-agent management - keeping the human in the loop and in control
  • Custom OpenCode plugins/tools built-in catalog
  • Linear integration
  • Built-in browser for running dev apps with agent integration

Acknowledgments

Independent project, not affiliated with the OpenCode team.

Special thanks to:

  • OpenCode - For the excellent API and extensible architecture.
  • Flexoki - Beautiful color scheme by Steph Ango.
  • Pierre - Fast, beautiful diff viewer with syntax highlighting.
  • Tauri - Desktop application framework.
  • Ghostty-web - Great implementation of a Ghostty web renderer.
  • David Hill - Who inspired me to release this without overthinking.
  • My wife, who - with zero AI background - sat down with the app for the first time and built the firework celebration that plays on every successful push.
  • Every contributor who shaped this project with their PRs, ideas, and attention to detail.

Contributing

See CONTRIBUTING.md for development setup and guidelines.

Docs source lives in packages/docs.

License

MIT

S
Description
No description provided
Readme MIT
82 MiB
Languages
TypeScript 74.8%
JavaScript 19.8%
MDX 4.7%
CSS 0.4%
HTML 0.1%
Other 0.1%