Skip to content

feat(debug): unified provider/usage debug CLI and GUI tab - #74

Closed
Wibias wants to merge 4 commits into
lidge-jun:mainfrom
Wibias:feat/debug-provider-gui
Closed

Wibias wants to merge 4 commits into
lidge-jun:mainfrom
Wibias:feat/debug-provider-gui

Conversation

@Wibias

@Wibias Wibias commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a unified debug system for provider transport diagnostics and usage extraction, with matching CLI commands, management API endpoints, and a dedicated GUI tab.

Changes

CLI

  • ocx debug provider on|off|status|reset|logs [-f]
  • ocx debug usage on|off|status|reset|logs [-f]
  • Runtime toggles on the running proxy (no restart required)

Server API

  • GET/PUT /api/debug — provider + usage flags with runtime overrides
  • GET /api/debug/logs — in-memory provider diagnostic buffer ([ocx:…] lines)
  • GET /api/debug/usage-logs — tail of ~/.opencodex/usage-debug.jsonl

GUI

  • New sidebar tab /#debug
  • Provider debug + Usage extraction toggles (sync with CLI via polling)
  • Refresh + Follow controls for live log viewing
  • Debug controls removed from /#logs (request logs only)

Internals

  • src/lib/debug-settings.ts, src/lib/debug-log-buffer.ts
  • Generic debugProviderDiagnostic(adapter, event, details) for all providers
  • Legacy env: OCX_DEBUG=1 and OCX_DEBUG_FRAMES=1 still enable provider debug

Testing

  • bun test tests/debug.test.ts tests/debug-settings.test.ts

Dependencies

Standalone debug-only PR (single commit). Can merge independently of #73; if both land around the same time, merge #73 first to reduce overlap on shared adapter wiring.

Add ocx debug provider|usage subcommands, runtime /api/debug toggles, in-memory provider log buffer with /api/debug/logs, usage JSONL tail via /api/debug/usage-logs, and a dedicated /#debug page with refresh/follow. Remove debug controls from the request Logs page.
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks for the solid end-to-end debug direction — a unified provider/usage debug surface across CLI + GUI is something this project needs. Requesting changes before merge:

  1. Compile blocker. src/server/index.ts re-exports httpStatusForRequestLogTerminal and httpStatusFromTerminalError, but src/server/request-log.ts at this PR head only exports httpStatusForTerminalStatus — bun x tsc --noEmit should fail as-is.
  2. Log polling cursor loses lines. src/lib/debug-log-buffer.ts uses Date.now() + entry.at > since, and gui/src/pages/Debug.tsx stores only the last timestamp — bursts within the same millisecond after a fetch get skipped permanently. A monotonic sequence/id cursor fixes this.
  3. Sensitive surface needs HTTP-level tests. /api/debug, /api/debug/logs, /api/debug/usage-logs can expose request/usage samples; please add management-API integration tests covering auth/CORS, PUT validation, limits, and redaction through the actual endpoint (the library-level tests don't protect the wire surface).
  4. Design nit: ocx debug usage logs tails the local JSONL directly while provider logs go through the live proxy API — that drifts when the running proxy has a different OPENCODEX_HOME/service env. Routing both through the API would be consistent.

Decision: request changes. No conflicts with current dev (verified), so once the blocker + cursor fix land this should go in smoothly. If you'd rather split backend/CLI/GUI into stacked PRs for easier review, that also works.

Wibias added 2 commits July 9, 2026 04:21
- Remove stale request-log re-exports from server/index.ts (tsc blocker)

- Use monotonic seq cursor for debug log polling (GUI, CLI, API)

- Route ocx debug usage logs through running proxy API

- Add management API integration tests for /api/debug endpoints
@Wibias

Wibias commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@lidge-jun Is it okay like that?

lidge-jun added a commit that referenced this pull request Jul 9, 2026
…k PR #74)

Cherry-pick of 238283f + 6a17da2 + c1cc006 + 4679291 from feat/debug-provider-gui.
All 4 review feedback items addressed by contributor:
- tsc blocker: stale re-exports removed
- Log polling: monotonic seq cursor replaces Date.now()
- HTTP tests: /api/debug endpoints covered (auth, CORS, validation, redaction)
- Usage logs: both streams now route through running proxy API

Co-authored-by: Wibias <[email protected]>
lidge-jun added a commit that referenced this pull request Jul 9, 2026
… cherry-pick

PR #74's server/index.ts cleanup removed this re-export (stale on main),
but dev's request-log.test.ts still imports it from src/server.
@lidge-jun

Copy link
Copy Markdown
Owner

Cherry-picked into dev as 79deb8e (all 4 commits squashed).

All 4 review feedback items confirmed resolved:

  1. tsc blocker — stale re-exports removed (plus httpStatusFromTerminalError re-export restored for dev-only consumer in af0e747)
  2. Log polling — monotonic seq cursor replaces Date.now()
  3. HTTP tests — tests/api-debug.test.ts covers auth/CORS, PUT validation, limit cap, redaction
  4. Usage logs — both streams route through running proxy API

1794 tests pass, 0 fail. Closing.

@lidge-jun lidge-jun closed this Jul 9, 2026
@Wibias
Wibias deleted the feat/debug-provider-gui branch July 13, 2026 19:18
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…k PR lidge-jun#74)

Cherry-pick of 238283f + 6a17da2 + c1cc006 + 4679291 from feat/debug-provider-gui.
All 4 review feedback items addressed by contributor:
- tsc blocker: stale re-exports removed
- Log polling: monotonic seq cursor replaces Date.now()
- HTTP tests: /api/debug endpoints covered (auth, CORS, validation, redaction)
- Usage logs: both streams now route through running proxy API

Co-authored-by: Wibias <[email protected]>
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…idge-jun#74 cherry-pick

PR lidge-jun#74's server/index.ts cleanup removed this re-export (stale on main),
but dev's request-log.test.ts still imports it from src/server.
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.

2 participants