Use when adding new error messages to React, or seeing "unknown error code" warnings.
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?
- Check
handleNavigate()insrc/gateway/server.ts— is there acasefor your view? - Check
generateSidebar()insrc/gateway/pages.ts— is nav item added? - Check page generator returns valid
A2UISurfaceData—ui.build(root)called? - Check imports — is
generateXxxPageimported inserver.ts?
Button/action not working?
- Check
handleAction()inserver.ts— is there a handler for youractionstring? - Check button
actionstring matches exactly (case-sensitive) - Check
payload— does it contain expected fields? - Check the action handler calls
await this.handleNavigate()to refresh UI after changes
Icon showing as emoji?
- Check
pages.ts— isiconusing a name (e.g."heart") or emoji (e.g."❤️")? - Check
ui/src/lib/icons.tsxICONSobject — does the icon name exist? - If new icon needed: add SVG to
ICONSinicons.tsx
Chat not working (SSE mode)?
- 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 - Check
_sseMode: Iftrue, a chat request is already in flight. The server rejects concurrent SSE requests with_chatLock. - Check
_chatLock: If stucktrue, the previous SSE stream didn't close cleanly. Look for errors inpha logs -f. - SSE events not arriving?: Check that the response has
Content-Type: text/event-streamandCache-Control: no-cache. - Stream closes immediately?: Check agent creation —
this.getAgent()returns valid agent? Check LLM API key in.pha/config.json.
Chat not updating (WebSocket fallback)?
- Check
sendChatUpdate()— isthis.currentView === "chat"true? - Check
handleAgentEvent()— are events being processed? - Check agent creation —
this.getAgent()returns valid agent?
WebSocket reconnection issues?
- Frontend auto-reconnects on disconnect. Check browser console for WebSocket errors.
- Check
pha status— is the server actually running? - Check port conflicts — is another process using port 8000?
- After reconnect, frontend re-sends
initmessage 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.