| name | debugging-acai |
| description | Debugging tools and techniques for acai. Use when investigating errors, analyzing session behavior, or troubleshooting issues in the acai CLI application. Includes guidance on reading logs, session files, and common error patterns. |
Debugging acai
Key Principles
- Never read log files directly - Use
tail to view the end of log files
- Use dynamic-read-session to inspect sessions - Don't read session JSON files directly
- Correlate errors with sessions - Use sessionId from error logs to find relevant sessions
Log Files
Application Logs
Location: ~/.acai/logs/current.log
Reading logs:
tail -n 50 ~/.acai/logs/current.log
tail -f ~/.acai/logs/current.log
grep "sessionId" ~/.acai/logs/current.log | tail -20
Common Log Patterns
- ERROR level: Application errors that may need investigation
- WARN level: Non-fatal issues that might affect behavior
- agent-error events: Errors emitted by the agent loop
Model Request Timing Telemetry
The agent loop emits one structured JSON log line per model request, correlated
by a stable requestId of the form <sessionId>:<iteration>. Each request emits
three events (filter on the event field):
model.request.start — model, provider, iteration, inputTokenEstimate
model.first_token — ttftMs (time-to-first-token in ms)
model.request.end — modelResponseMs, ttftMs, inputTokens,
outputTokens, outputTokensPerSecond, reasoningTokens, finishReason,
retryCount, providerRequestId, and selected providerHeaders
(request id, rate-limit, retry-after)
grep '"requestId":"<sessionId>:' ~/.acai/logs/current.log
grep '"event":"model.request.end"' ~/.acai/logs/current.log | tail -20
Per-turn timing (wallClockMs, modelMs, toolMs) is also persisted in the
session file and rolled up in the exit Session Summary (Total/Model/Tools/
Overhead and Tool/Total ratio), so you can see whether a session is dominated by
model response time or tool execution.
Session Files
Reading Sessions
Always use the dynamic-read-session tool - Never read session JSON files directly as they can be large.
await dynamicReadSession({ sessionId: "uuid-here" })
Parameters:
sessionId: The session UUID (found in logs or session filenames)
maxTurns: Limit conversation turns (default: 50)
Session File Locations
- Directory:
~/.acai/sessions/
- Pattern:
session-{uuid}.json
Finding Session IDs
- From logs: Look for
sessionId field in error context
- From filenames: Session files are named
session-{uuid}.json
- From session list: List files in
~/.acai/sessions/
ls -la ~/.acai/sessions/ | tail -20
Common Error Patterns
Bad Request Errors
Check error log context for:
responseStatus: HTTP status code (400 = Bad Request)
responseBody: API error message
modelId: Which model was being used
messageCount: How many messages in context
NoOutputGeneratedError
The model produced no output. Common causes:
- Invalid system prompt
- Model rate limiting
- Tool schema issues
- Context too long
Session Restoration
When debugging session issues:
- Find session ID from logs
- Use dynamic-read-session to view the conversation
- Check for truncation or missing messages
Debugging Workflow
-
Find the error in logs:
tail -100 ~/.acai/logs/current.log | grep -i error
-
Extract session ID from the error context
-
Read the session to understand what led to the error:
-
Check recent sessions:
ls -lt ~/.acai/sessions/ | head -10
Manual Testing
When testing features manually, use tmux to run the REPL:
tmux new -s acai
node source/index.ts
tail -f ~/.acai/logs/current.log