Skip to content
PidebugBackend10 files · +2129 −335

Fix duplicate gateway spawning and add extension unit tests in pi-coding-agent (0xKobold)

Session from 0xKobolds on Hugging Face by moikapy · MIT · condensed by Coders Talk

18msession
0interventions
GOAL

Diagnose why multiple WebSocket gateway servers were coming up on session start for the 0xKobold pi-coding-agent framework, then write unit tests covering the extensions directory including plan mode and subagent spawning.

  1. Prompt · +0m
    Investigate why multiple gateways are up when only one should run by default.
  2. Agent did · +0m
    Traced ports 18789-18792 via lsof/ps/pstree, read gateway-extension.ts, pi-config, update/self-update extensions and the subagent spawner to find why several bun processes each opened their own gateway.
  3. Agent did · +1m
    Identified that gateway-extension, update-extension and self-update-extension all fired session_start handlers on every subagent spawn; added hasAttemptedStart flags and KOBOLD_SUBAGENT/PI_SESSION_PARENT env checks to gate startup to the main session only.
  4. Prompt · +10m
    Write unit tests for the src/extensions directory.
  5. Agent did · +10m
    Explored extension files and existing test setup, then wrote a mock ExtensionAPI helper plus new test suites for persona-loader, fileops, gateway, mode-manager and agent/subagent extensions.
  6. Fail · +15m
    gateway.test.ts failed on the gateway:status command test because the handler used console.log instead of sendMessage, so the test's assertions didn't match reality.
  7. Agent did · +15m
    Read the gateway-extension source around the status/broadcast commands, rewrote the test expectations to match the real command output, and got all gateway tests passing.
  8. Fail · +15m
    persona-loader.test.ts failed because PERSONA_DIR is resolved from the real homedir() at module load time, so tests picked up the developer's actual ~/.0xkobold files instead of the isolated test fixtures.
  9. Agent did · +15m
    Reworked persona-loader tests to isolate test directories, renamed TEST_DIR references, and marked several file-content tests as skipped since PERSONA_DIR is cached at module import and can't be mocked without restructuring the extension.
  10. Outcome · +18m
    Extension test suite (mocks, gateway, fileops, persona-loader, mode-manager, agent/subagent) running under bun test with gateway tests fully passing; a handful of persona-loader tests left skipped due to module-level homedir() caching.
VERDICT

I'd start by naming the exact env vars and lifecycle hook I suspect (session_start firing per-subagent) so the agent goes straight to gateway/update/self-update extensions instead of spending a dozen turns on lsof and pstree. The fix that actually did the work was gating those session_start handlers behind a hasAttemptedStart flag and the KOBOLD_SUBAGENT/PI_SESSION_PARENT env check. The test-writing pass was solid but ran into a real limitation I hadn't flagged up front: PERSONA_DIR is resolved from homedir() at module load, so several persona-loader tests had to be skipped rather than truly fixed.

I tried this · 0

Discussion · 0

How Builds work