When the agent crashes with an unhandled exception, record the error
(type + message) on the SessionEntry. On the next message, inject a
[System note: ...] into the context prompt so the agent wakes up
knowing what failed and can self-diagnose instead of starting blind.
Three injection points:
- SessionEntry: new fields last_error_type / last_error_message /
last_error_time (gateway/session.py)
- Exception handler: record crash on session_entry before returning
error to user (gateway/run.py:~9107)
- Context prompt builder: prepend crash note and clear fields so
the notice appears exactly once (gateway/run.py:~8216)
The agent sees: [System note: The previous session crashed with
ValueError: Model gpt-5.5 has a context window of 4,096 tokens...]