Skip to content

feat(ws-support): cp websocket runtime support with browser chat#475

Open
sskmlm wants to merge 27 commits into
mpfaffenberger:mainfrom
sskmlm:feature/puppy-desk-migration
Open

feat(ws-support): cp websocket runtime support with browser chat#475
sskmlm wants to merge 27 commits into
mpfaffenberger:mainfrom
sskmlm:feature/puppy-desk-migration

Conversation

@sskmlm

@sskmlm sskmlm commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary
───────
• add websocket streaming support for Code Puppy via a local API/server runtime
• enable chatting with Code Puppy from the browser while Code Puppy runs locally as the server
• add modular websocket/session handling, persistence, and recovery flows for streamed chat execution
• preserve legacy CLI session resume behavior while separating browser/server concerns into the API runtime

What changed
────────────
Local API/server runtime
• add the API app/bootstrap under code_puppy.api, including main entrypoint, app wiring, routers, and protocol/config endpoints
• add DB/session infrastructure for chat history, backfill, message utilities, SQL loading, and session context management
• add backend logging setup and model error normalization support
• add permission/session binding enforcement for API operations

WebSocket streaming
• add modular websocket handling under code_puppy.api.ws
• add runtime/session managers, chat turn lifecycle helpers, response frame adaptation, background saves, and stream draining
• add one-shot resume recovery with sqlite reload for failed resumed sessions
• improve tool lifecycle and event adapter handling during streamed/browser-based execution

Browser chat support
• refresh chat.html for browser-based chat flows and session recovery UX
• support browser ask_user_question responses
• harden config/schema and XSS-related template behavior

Reliability fixes
• dedupe duplicate Codex input item IDs before API requests
• add BaseAgent session/model compatibility helpers
• fix emitter/session-id wiring and avoid cwd history corruption
• keep legacy CLI session resume unchanged while browser/server support is added alongside it

Why
───
This branch adds websocket streaming support for Code Puppy so it can run locally as a server and be used from a browser chat UI. It also closes several session recovery, browser interaction, and streamed execution gaps that showed up while building that flow.

@sskmlm sskmlm force-pushed the feature/puppy-desk-migration branch 2 times, most recently from 9f5fe3b to f440ebd Compare June 13, 2026 18:13
sskmlm and others added 26 commits June 15, 2026 14:32
load_plugin_callbacks() returns dict with 'builtin' and 'user' keys
but not always 'external'. Use .get() with default to avoid KeyError.
Root cause analysis for missing tool call streaming:
- ContextVar bridge (current_emitter_session_id) never wired
- Pre-existing gap from original puppy-desk branch
- Events tagged session_id=None, dropped by session-filtered subscriber
- b1_streaming_used stays False, GUGI gets no tool lifecycle frames

Also documents: stale sender session_id, session switch sync,
executor shutdown cosmetic error.

Execution plan: P0 ContextVar fix, P1 sender sync, future extraction targets.
P0 — Tool call streaming was broken because the emitter ContextVar
(current_emitter_session_id) was never set. Events emitted by
register_callbacks had session_id=None, which session-filtered
subscribers dropped. Now set/reset around the agent run window.

P1 — WebSocketSender.session_id was stale after session generation
and session switching. Added setter property and synced at all 3
assignment sites (new session, switch-to-new, switch-to-existing).

Pre-existing gap — original feature/puppy-desk also never set the
ContextVar. Not a Phase 3 regression.

Test results: 4095 passed, 29 skipped (3 pre-existing failures excluded)
Aligns chat_handler.py import order and removes extra blank lines
in test files so ws/ layer is byte-identical across both repos.
Improve the desk chat template with wireframe-inspired message and tool-call rendering, including safer markdown/tool-card handling and collapsed tool call payloads.

Strengthen resumed-session recovery, session CWD handling, permission auto-approval behavior, SQL query loading, and command runner cleanup coverage.

Validation: node --check /tmp/chat_inline_pr_handoff_check.js; ruff check targeted files; pytest -q --no-cov targeted tests (11 passed).
@sskmlm sskmlm force-pushed the feature/puppy-desk-migration branch from 1fdcecc to e65d6c3 Compare June 15, 2026 19:32
@sskmlm sskmlm changed the title Feature/puppy desk migration feat(ws-support): cp websocket runtime support with browser chat Jun 15, 2026
@sskmlm sskmlm marked this pull request as ready for review June 15, 2026 19:43
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