shuiyuan1223

debug-gateway

0
0
# Install this skill:
npx skills add shuiyuan1223/skillfix_xuetang --skill "debug-gateway"

Install specific skill from multi-skill repository

# Description

Use when debugging the Gateway server - WebSocket issues, A2UI rendering problems, page not loading, action handlers not working.

# SKILL.md


name: debug-gateway
description: Use when debugging the Gateway server - WebSocket issues, A2UI rendering problems, page not loading, action handlers not working.


Debug PHA Gateway

Quick Diagnosis

Server not starting?

bun run build          # Rebuild
pha start              # Start server
curl localhost:8000/health  # Should return {"status":"ok"}

Page not rendering?

  1. Check handleNavigate() in src/gateway/server.ts β€” is there a case for your view?
  2. Check generateSidebar() in src/gateway/pages.ts β€” is nav item added?
  3. Check page generator returns valid A2UISurfaceData β€” ui.build(root) called?
  4. Check imports β€” is generateXxxPage imported in server.ts?

Button/action not working?

  1. Check handleAction() in server.ts β€” is there a handler for your action string?
  2. Check button action string matches exactly (case-sensitive)
  3. Check payload β€” does it contain expected fields?
  4. Check the action handler calls await this.handleNavigate() to refresh UI after changes

Icon showing as emoji?

  1. Check pages.ts β€” is icon using a name (e.g. "heart") or emoji (e.g. "❀️")?
  2. Check ui/src/lib/icons.tsx ICONS object β€” does the icon name exist?
  3. If new icon needed: add SVG to ICONS in icons.tsx

Chat not working (SSE mode)?

  1. SSE endpoint: POST /api/ag-ui β€” test with curl:
    bash curl -X POST http://localhost:8000/api/ag-ui \ -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"hello"}]}' \ --no-buffer
  2. Check _sseMode: If true, a chat request is already in flight. The server rejects concurrent SSE requests with _chatLock.
  3. Check _chatLock: If stuck true, the previous SSE stream didn't close cleanly. Look for errors in pha logs -f.
  4. SSE events not arriving?: Check that the response has Content-Type: text/event-stream and Cache-Control: no-cache.
  5. Stream closes immediately?: Check agent creation β€” this.getAgent() returns valid agent? Check LLM API key in .pha/config.json.

Chat not updating (WebSocket fallback)?

  1. Check sendChatUpdate() β€” is this.currentView === "chat" true?
  2. Check handleAgentEvent() β€” are events being processed?
  3. Check agent creation β€” this.getAgent() returns valid agent?

WebSocket reconnection issues?

  1. Frontend auto-reconnects on disconnect. Check browser console for WebSocket errors.
  2. Check pha status β€” is the server actually running?
  3. Check port conflicts β€” is another process using port 8000?
  4. After reconnect, frontend re-sends init message to get fresh A2UI state.

Data Flow

WebSocket (pages, navigation, actions)

Client WebSocket Message
  β†’ GatewaySession.handleMessage()
    β†’ handleInit() / handleNavigate() / handleUserMessage() / handleAction()
      β†’ generateXxxPage() / agent.chat()
        β†’ send(JSON) β†’ WebSocket β†’ Frontend renders

SSE (chat streaming)

Client POST /api/ag-ui
  β†’ GatewaySession.handleChatSSE(message, writer, encoder)
    β†’ agent.chat() with streaming callback
      β†’ SSE events: RunStarted β†’ TextMessageContent* β†’ ToolCallStart/End β†’ RunFinished
        β†’ writer.write(encoder.encode("data: {json}\n\n"))

Logging

  • Server logs: console.log("[Tag] message")
  • Agent events: Logged in handleAgentEvent()
  • LLM API calls: Logged by installFetchInterceptor()
  • View logs in real-time: pha logs -f

Common Issues

Symptom Cause Fix
Blank page Missing case in handleNavigate Add route case
"Using toolName..." in chat No custom label in TOOL_DISPLAY_NAMES Add to A2UIRenderer.tsx
Type error on build i18n key missing Add to types.ts + both locale files
Icon renders as text Icon name not in ICONS object Add SVG to ui/src/lib/icons.tsx
Action does nothing No handler in handleAction Add else if branch
SSE hangs _chatLock stuck true Restart server (pha restart)
Chat duplicates SSE + WebSocket both sending messages Check _sseMode flag
CORS error on SSE Missing CORS headers Check server CORS config for /api/ag-ui

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.