From 1e381ef30b144d927958176db1ccb4e442e54e16 Mon Sep 17 00:00:00 2001 From: Wen Date: Wed, 14 Oct 2026 14:32:03 -0300 Subject: [PATCH 1/5] fix(videodb): load the project .env from the working directory in ws_listener A bare load_dotenv() calls find_dotenv() without usecwd, which searches upward from the calling script's directory (skills/videodb/scripts), not from the project the user is in. A VIDEO_DB_API_KEY saved in the project .env, as the skill documents, was never read, so the listener failed with an authentication error. Use load_dotenv(find_dotenv(usecwd=True)). The Quick Start started the listener with `python scripts/ws_listener.py`, which does not resolve from the project directory on a plugin install. Point it at "${CLAUDE_SKILL_DIR}/scripts/ws_listener.py". Also stop the immediate reconnect loop when the server accepts and then closes the socket: a close now counts as a failed attempt with backoff, and the retry budget resets only after an event is received. Signed-off-by: Wen --- skills/videodb/SKILL.md | 4 +++- skills/videodb/scripts/ws_listener.py | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/skills/videodb/SKILL.md b/skills/videodb/SKILL.md index e1290296a..77f97be19 100644 --- a/skills/videodb/SKILL.md +++ b/skills/videodb/SKILL.md @@ -305,11 +305,13 @@ Use `ws_listener.py` to capture WebSocket events during recording sessions. Desk #### Quick Start 1. **Choose state dir**: `STATE_DIR="${VIDEODB_EVENTS_DIR:-$HOME/.local/state/videodb}"` -2. **Start listener**: `VIDEODB_EVENTS_DIR="$STATE_DIR" python scripts/ws_listener.py --clear "$STATE_DIR" &` +2. **Start listener** from the project directory, so it reads the project's `.env`: `VIDEODB_EVENTS_DIR="$STATE_DIR" python "${CLAUDE_SKILL_DIR}/scripts/ws_listener.py" --clear "$STATE_DIR" &` 3. **Get WebSocket ID**: `cat "$STATE_DIR/videodb_ws_id"` 4. **Run capture code** (see reference/capture.md for the full workflow) 5. **Events written to**: `$STATE_DIR/videodb_events.jsonl` +`scripts/ws_listener.py` in the reference files is relative to this skill's directory (`${CLAUDE_SKILL_DIR}`), not to the project. + Use `--clear` whenever you start a fresh capture run so stale transcript and visual events do not leak into the new session. #### Query Events diff --git a/skills/videodb/scripts/ws_listener.py b/skills/videodb/scripts/ws_listener.py index 0ec201056..3d96dc3cd 100644 --- a/skills/videodb/scripts/ws_listener.py +++ b/skills/videodb/scripts/ws_listener.py @@ -35,8 +35,9 @@ import contextlib from datetime import datetime, timezone from pathlib import Path -from dotenv import load_dotenv -load_dotenv() +from dotenv import find_dotenv, load_dotenv +# Search from the working directory (the user's project), not this script's dir. +load_dotenv(find_dotenv(usecwd=True)) import videodb from videodb.exceptions import AuthenticationError @@ -191,15 +192,21 @@ async def listen_with_retry(): print(f"WS_ID={ws_id}", flush=True) log(f"Connected (ws_id={ws_id})") - retry_count = 0 - backoff = INITIAL_BACKOFF - receiver = ws.receive().__aiter__() while True: try: msg = await anext(receiver) except StopAsyncIteration: + # Counts as a failed attempt, so a server that accepts and then + # closes at once is retried with backoff, not in a tight loop. + retry_count += 1 log("Connection closed by server") + if retry_count >= MAX_RETRIES: + log(f"Max retries ({MAX_RETRIES}) exceeded, exiting") + return + log(f"Reconnecting in {backoff}s (attempt {retry_count}/{MAX_RETRIES})...") + await asyncio.sleep(backoff) + backoff = min(backoff * 2, MAX_BACKOFF) break except asyncio.CancelledError: log("Shutdown requested") @@ -222,6 +229,9 @@ async def listen_with_retry(): backoff = min(backoff * 2, MAX_BACKOFF) break + # Only a connection that delivers events resets the retry budget. + retry_count = 0 + backoff = INITIAL_BACKOFF append_event(msg) channel = msg.get("channel", msg.get("event", "unknown")) text = msg.get("data", {}).get("text", "") From 5a34568cdf9795b556eff3b949996e1f01452aa2 Mon Sep 17 00:00:00 2001 From: Wen Date: Wed, 14 Oct 2026 16:48:08 -0300 Subject: [PATCH 2/5] test(videodb): cover ws_listener .env lookup and reconnect budget Signed-off-by: Wen --- tests/test_videodb_ws_listener.py | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/test_videodb_ws_listener.py diff --git a/tests/test_videodb_ws_listener.py b/tests/test_videodb_ws_listener.py new file mode 100644 index 000000000..925286b1d --- /dev/null +++ b/tests/test_videodb_ws_listener.py @@ -0,0 +1,89 @@ +"""Regression tests for skills/videodb/scripts/ws_listener.py. + +`dotenv` and `videodb` are stubbed, so neither package nor a network is needed. +""" +import asyncio +import importlib.util +import sys +import types +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parent.parent / "skills" / "videodb" / "scripts" / "ws_listener.py" + + +class FakeWebSocket: + def __init__(self, events): + self.connection_id = "ws-test" + self._events = events + + async def receive(self): + for event in self._events: + yield event + + +def load_listener(monkeypatch, tmp_path, connections): + """Import ws_listener with stubs; each connect() serves the next event list.""" + dotenv_calls = [] + dotenv = types.ModuleType("dotenv") + dotenv.find_dotenv = lambda **kwargs: dotenv_calls.append(("find", kwargs)) or "/project/.env" + dotenv.load_dotenv = lambda *args, **kwargs: dotenv_calls.append(("load", args)) or True + + remaining = list(connections) + + class Wrapper: + async def connect(self): + if not remaining: + raise AssertionError("listener kept reconnecting after its retry budget") + return FakeWebSocket(remaining.pop(0)) + + class Conn: + def connect_websocket(self): + return Wrapper() + + videodb = types.ModuleType("videodb") + videodb.connect = Conn + exceptions = types.ModuleType("videodb.exceptions") + exceptions.AuthenticationError = type("AuthenticationError", (Exception,), {}) + videodb.exceptions = exceptions + + monkeypatch.setitem(sys.modules, "dotenv", dotenv) + monkeypatch.setitem(sys.modules, "videodb", videodb) + monkeypatch.setitem(sys.modules, "videodb.exceptions", exceptions) + monkeypatch.setattr(sys, "argv", [str(SCRIPT), str(tmp_path)]) + + spec = importlib.util.spec_from_file_location("ws_listener_under_test", SCRIPT) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + sleeps = [] + + async def fake_sleep(seconds): + sleeps.append(seconds) + + monkeypatch.setattr(module.asyncio, "sleep", fake_sleep) + return module, dotenv_calls, sleeps, remaining + + +def test_loads_dotenv_found_from_the_working_directory(monkeypatch, tmp_path): + _, dotenv_calls, _, _ = load_listener(monkeypatch, tmp_path, []) + assert ("find", {"usecwd": True}) in dotenv_calls + assert ("load", ("/project/.env",)) in dotenv_calls + + +def test_eventless_closes_back_off_and_stop(monkeypatch, tmp_path): + module, _, sleeps, remaining = load_listener(monkeypatch, tmp_path, [[]] * 20) + asyncio.run(module.listen_with_retry()) + assert len(remaining) == 20 - module.MAX_RETRIES + assert sleeps == [1, 2, 4, 8, 16, 32, 60, 60, 60] + + +def test_an_event_resets_the_retry_budget(monkeypatch, tmp_path): + event = {"channel": "transcript", "data": {"text": "hi"}} + connections = [[], [event]] + [[]] * 20 + module, _, sleeps, _ = load_listener(monkeypatch, tmp_path, connections) + asyncio.run(module.listen_with_retry()) + # First close backs off 1s; the event resets backoff, so the next close waits 1s again. + assert sleeps[:3] == [1, 1, 2] + assert len(sleeps) == 1 + module.MAX_RETRIES - 1 + assert (tmp_path / "videodb_events.jsonl").read_text().count("transcript") == 1 + From ab917e010a282ee55b24d08cb6177463b6763f93 Mon Sep 17 00:00:00 2001 From: Wen Date: Wed, 14 Oct 2026 16:48:09 -0300 Subject: [PATCH 3/5] docs(videodb): say where the listener lives on hosts without CLAUDE_SKILL_DIR Signed-off-by: Wen --- skills/videodb/SKILL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/skills/videodb/SKILL.md b/skills/videodb/SKILL.md index 77f97be19..7f0278315 100644 --- a/skills/videodb/SKILL.md +++ b/skills/videodb/SKILL.md @@ -311,6 +311,7 @@ Use `ws_listener.py` to capture WebSocket events during recording sessions. Desk 5. **Events written to**: `$STATE_DIR/videodb_events.jsonl` `scripts/ws_listener.py` in the reference files is relative to this skill's directory (`${CLAUDE_SKILL_DIR}`), not to the project. +Claude Code fills in `${CLAUDE_SKILL_DIR}`. Other hosts leave it empty, so replace it with the directory this skill is installed in (for Codex, `~/.codex/skills/videodb`). Use `--clear` whenever you start a fresh capture run so stale transcript and visual events do not leak into the new session. From 1bf9c21e773f053649a121b759f7cd2966b11b4a Mon Sep 17 00:00:00 2001 From: Wen Date: Mon, 19 Oct 2026 07:25:01 -0300 Subject: [PATCH 4/5] docs(videodb): use $HOME for the Codex skill path inside the quoted command --- skills/videodb/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skills/videodb/SKILL.md b/skills/videodb/SKILL.md index 7f0278315..6137a6934 100644 --- a/skills/videodb/SKILL.md +++ b/skills/videodb/SKILL.md @@ -311,7 +311,7 @@ Use `ws_listener.py` to capture WebSocket events during recording sessions. Desk 5. **Events written to**: `$STATE_DIR/videodb_events.jsonl` `scripts/ws_listener.py` in the reference files is relative to this skill's directory (`${CLAUDE_SKILL_DIR}`), not to the project. -Claude Code fills in `${CLAUDE_SKILL_DIR}`. Other hosts leave it empty, so replace it with the directory this skill is installed in (for Codex, `~/.codex/skills/videodb`). +Claude Code fills in `${CLAUDE_SKILL_DIR}`. Other hosts leave it empty, so replace it with the directory this skill is installed in (for Codex, `$HOME/.codex/skills/videodb`; `~` does not expand inside the quotes). Use `--clear` whenever you start a fresh capture run so stale transcript and visual events do not leak into the new session. From b423a183b50debbe4746fb82d5c1e1637314850c Mon Sep 17 00:00:00 2001 From: Wen Date: Tue, 27 Oct 2026 16:52:36 -0300 Subject: [PATCH 5/5] chore(context-packs): refresh skill-triggers registry digest --- manifests/context-packs/skill-triggers@1.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 34be199f4..d39c31ac7 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "846ac8826dd91e81cd838c2b55d7be536af427eb453efa127501f891e5778ff8", + "registryDigest": "06d5a5ec702e020e83b099c5137264921607768e19c76dd20a0de8d20acc8f85", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [