Debugging Guide for Copex
Common Issues
Stale/Wrong Content Displayed
Symptoms: Response shows previous turn's content, or old message appears instead of new one.
Root Cause: History fallback triggered during streaming mode.
Investigation:
- •Check if streaming (
on_chunkprovided) - •Verify
received_contentflag is set when content arrives - •Check if history fallback is being used incorrectly
Fix Pattern:
python
# In client.py - only use history when NOT streaming
if not received_content and on_chunk is None:
# History fallback OK here
messages = await session.get_messages()
In CLI - prefer streamed content:
python
final_message = ui.state.message if ui.state.message else response.content
Empty or Missing Content
Symptoms: Response is empty, reasoning missing, or incomplete.
Debug Steps:
- •Add logging to
on_event():pythonprint(f"Event: {event_type}, data: {event.data}") - •Check
content_partsandreasoning_partslists - •Verify final events are received
Event Flow:
code
ASSISTANT_REASONING_DELTA → reasoning_parts.append() ASSISTANT_REASONING → final_reasoning = content ASSISTANT_MESSAGE_DELTA → content_parts.append() ASSISTANT_MESSAGE → final_content = content SESSION_IDLE → done.set()
Retry Not Working
Check:
- •
_should_retry()logic inclient.py - •Error matches
retry_on_errorspatterns - •
retry_on_any_errorconfig setting
Debug:
python
print(f"Error: {error_str}")
print(f"Should retry: {self._should_retry(e)}")
Timeout Despite Activity
Check: last_activity timestamp updates in on_event():
python
def on_event(event):
nonlocal last_activity
last_activity = asyncio.get_event_loop().time() # Must update!
Key Files to Check
| Issue | File | Function |
|---|---|---|
| Content/streaming | client.py | _send_once(), on_event() |
| UI display | cli.py | _stream_response*() |
| UI components | ui.py | CopexUI, build_*() |
| Retry logic | client.py | send(), _should_retry() |
| Config | config.py | CopexConfig |
Debugging Tools
Inspect Raw Events
python
response = await client.send(prompt)
for event in response.raw_events:
print(f"{event['type']}: {event['data']}")
Write Reproducing Test
python
def test_reproduces_bug():
events = [
# Exact sequence that causes the bug
]
session = FakeSession(events)
# Verify bug exists, then fix
Debug Checklist
- • Reproduce consistently
- • Identify component (client/cli/ui)
- • Add logging to trace events
- • Check raw_events for unexpected data
- • Write failing test
- • Fix and verify
- • Remove debug logging