Summary
Each service should persist a structured crash reason to a well-known file on fatal exit, enabling diagnostic tools to quickly surface why a service is down without parsing raw logs.
Problem
When a service crashes (e.g., due to a migration mismatch), the only record is in the stderr log. Diagnostic tools and other services have no structured way to determine the cause of a crash. This is especially problematic when:
- Log files are rotated or truncated
- The crash happens during startup before logging is fully initialized
- Multiple restart attempts fill the log with repeated errors
Proposed Solution
-
On fatal exit, each service writes a JSON file to a standard location, e.g.:
~/Library/Application Support/agentd-<service>/last-error.json
-
Format:
{
"timestamp": "2026-04-17T19:15:49Z",
"error": "Migration file of version 'm20260329_000012_create_projects_table' is missing",
"category": "migration",
"exit_code": 1
}
-
The file is overwritten on each crash, so it always reflects the most recent failure.
-
On successful startup, the file is deleted (or a last-healthy.json is written alongside it).
Acceptance Criteria
Summary
Each service should persist a structured crash reason to a well-known file on fatal exit, enabling diagnostic tools to quickly surface why a service is down without parsing raw logs.
Problem
When a service crashes (e.g., due to a migration mismatch), the only record is in the stderr log. Diagnostic tools and other services have no structured way to determine the cause of a crash. This is especially problematic when:
Proposed Solution
On fatal exit, each service writes a JSON file to a standard location, e.g.:
~/Library/Application Support/agentd-<service>/last-error.jsonFormat:
{ "timestamp": "2026-04-17T19:15:49Z", "error": "Migration file of version 'm20260329_000012_create_projects_table' is missing", "category": "migration", "exit_code": 1 }The file is overwritten on each crash, so it always reflects the most recent failure.
On successful startup, the file is deleted (or a
last-healthy.jsonis written alongside it).Acceptance Criteria
last-error.jsonon fatal exit