Home · Developers · Guides · IDE Debugger (DAP)

Workspace

IDE Debugger (DAP)

DAP debugging

Overview

The IDE ships a real Debug Adapter Protocol client so the Monaco editor can debug workspace programs, the same protocol used by VS Code. The built-in adapter is debugpy (python -m debugpy.adapter), giving breakpoint debugging, stepping, stack inspection, and expression evaluation for Python files. Sessions run as local subprocesses managed by the backend; the UI talks to them over REST plus the /ws/debug event channel.

Architecture

Monaco IDE (React)
  │  gutter clicks → POST /api/ide/debug/breakpoints
  │  Run & Debug panel → REST control + /ws/debug events
  ▼
novacoder/api/routes_debug.py        REST surface (/api/ide/debug/*)
novacoder/api/routes_websocket.py    /ws/debug channel (Debug* bus events)
novacoder/dap/session.py             DebugSession, adapter process lifecycle,
                                     breakpoint queue/flush, state machine
novacoder/dap/client.py              DapClient, async Content-Length framing,
                                     seq tracking, events, reverse requests
        │
        ▼
python -m debugpy.adapter  ──launches──▶  debuggee process
  • DapClient implements the wire protocol: 8-byte Content-Length framed JSON messages, monotonically increasing seq for requests and responses (per the DAP spec), adapter event dispatch, and safe handling of adapter reverse requests (e.g. runInTerminal, handshake). All I/O is asyncio, nothing blocks the API event loop.
  • DebugSession owns one adapter subprocess. Breakpoints set before launch are queued, sent during configurationDone, and flushed through an internal path so the "not live" gate can't swallow them. Breakpoints persist across sessions (standard IDE semantics) until the user removes them.
  • Terminated sessions stay inspectable, state, exit_code, and captured output remain available until the next start or stop.

REST API

All routes require the normal API token / session auth and are under the workspace RBAC resource.

Method Route Purpose
GET /api/ide/debug/status Session state, threads, breakpoints, capabilities, debugpy availability
POST /api/ide/debug/start Launch debug session. Body: {path, args?, cwd?}, path is workspace-relative
POST /api/ide/debug/stop Terminate the session and adapter
POST /api/ide/debug/breakpoints Replace a file's breakpoints. Body: {path, lines:[int]}
POST /api/ide/debug/continue Continue. Body: {thread_id?}
POST /api/ide/debug/pause Pause. Body: {thread_id?}
POST /api/ide/debug/next Step over
POST /api/ide/debug/step_in Step into
POST /api/ide/debug/step_out Step out
GET /api/ide/debug/threads List debuggee threads
GET /api/ide/debug/stack Stack trace. Query: thread_id? (defaults to stopped/first thread), levels
GET /api/ide/debug/scopes Scopes for a frame. Query: frame_id (required)
GET /api/ide/debug/variables Variables. Query: variables_reference (required)
POST /api/ide/debug/evaluate Evaluate expression. Body: {expression, frame_id?}
GET /api/ide/debug/output Captured stdout/stderr/console/telemetry. Query: limit

Status state values: idle, starting, running, stopped, terminated, error. The stopped payload carries {thread_id, reason, description, all_threads_stopped}.

WebSocket events, GET /ws/debug

Session operations emit kernel Debug* events bridged to the debug channel (see _EVENT_CHANNEL_MAP in novacoder/api/websocket.py):

Event Payload
DebugSessionStarted {program}
DebugSessionStopped {program} (session/adapter teardown)
DebugStopped stop details, thread_id, reason, location
DebugContinued {thread_id}
DebugBreakpoints updated breakpoint map for a source
DebugBreakpointChanged adapter-verified change for one breakpoint
DebugOutput {category, output} chunk from the debuggee
DebugProcess adapter process metadata (name, pid, …)
DebugExited {exit_code}
DebugTerminated {program, reason?}

The IDE panel subscribes via useEventStream('debug') and invalidates its status/stack/variable queries on any Debug* event, so stops and output appear immediately. Polling remains as a fallback.

UI, Run and Debug panel

Sidebar view 🐞 in the IDE:

  • Controls, ▶ Debug (enabled for *.py active files), ⏸ pause, step over / into / out, ■ stop. State chip shows the live session state.
  • Breakpoints, click the editor glyph margin or line numbers to toggle; verified breakpoints are solid red, pending ones translucent. The panel lists all breakpoints with verified state and removal buttons.
  • Call stack, frames for the stopped thread; clicking a frame opens the file and selects it for variables/evaluate.
  • Variables, scopes (Locals/Globals) with lazily-expandable child variables.
  • Evaluate, arbitrary expression evaluated in the selected frame.
  • Output, debuggee stdout/stderr tail.
  • The current stop location is highlighted in the editor (yellow line + gutter wedge) and the file auto-opens when the debugger stops.
  • Status bar shows debug:<state>.

Dependencies

  • debugpy, required for Python debugging. GET status reports debugpy: false and disables launch when it is absent (pip install debugpy).
  • Adapter capabilities are surfaced verbatim in the status response (conditional breakpoints, setVariable, evaluateForHovers, etc.).

Limitations

  • Single concurrent session (one debuggee at a time), matching the panel UX.
  • Only the debugpy launch config is exposed (program, args, cwd, console=internalConsole). Attach/remote debugging and other language adapters can be added by extending DebugSession's launch request.
  • runInTerminal reverse requests are answered with an error response, debuggee output always goes through the output event channel, not the PTY terminal.

Testing

tests/test_ide_debug_api.py, 26 tests covering status, breakpoint queueing/persistence, launch, stop, and a real debugpy session: breakpoint hit → stack → scopes → variables → evaluate → step → continue → terminate. Offline-safe; real-adapter cases skip when debugpy is unavailable.

  • Editor System, underlying file/editor API
  • Web Interface Code Editor, legacy editor UI
  • VS Code Extension, external editor bridge
  • Report: backups/reports_archive_2026-10-13/26_ide_debugger.md (archived; consolidated into reports/NOVACODER_MASTER_DEVELOPMENT_ROADMAP.md)

Source: wiki/ide-debugger.md · rendered 2026-11-10