fix(core): Add structured error handling and responsive lock release

Improves core infrastructure with robot-friendly error output and
faster lock release for better sync behavior.

Error handling improvements (error.rs):
- ErrorCode::exit_code(): Unique exit codes per error type (1-13)
  for programmatic error handling in scripts/agents
- GiError::suggestion(): Helpful hints for common error recovery
- GiError::to_robot_error(): Structured JSON error conversion
- RobotError/RobotErrorOutput: Serializable error types with code,
  message, and optional suggestion fields

Lock improvements (lock.rs):
- Heartbeat thread now polls every 100ms for release flag, only
  updating database heartbeat at full interval (5s default)
- Eliminates 5-10s delay after sync completion when waiting for
  heartbeat thread to notice release
- Reduces lock hold time after operation completes

Database (db.rs):
- Bump expected schema version to 6 for MR migration

The exit code mapping enables shell scripts and CI/CD pipelines to
distinguish between configuration errors (2-4), GitLab API errors
(5-8), and database errors (9-11) for appropriate retry/alert logic.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-01-26 22:46:08 -05:00
parent cd44e516e3
commit 5fe76e46a3
3 changed files with 109 additions and 9 deletions

View File

@@ -15,8 +15,18 @@ const MIGRATIONS: &[(&str, &str)] = &[
("001", include_str!("../../migrations/001_initial.sql")),
("002", include_str!("../../migrations/002_issues.sql")),
("003", include_str!("../../migrations/003_indexes.sql")),
("004", include_str!("../../migrations/004_discussions_payload.sql")),
("005", include_str!("../../migrations/005_assignees_milestone_duedate.sql")),
(
"004",
include_str!("../../migrations/004_discussions_payload.sql"),
),
(
"005",
include_str!("../../migrations/005_assignees_milestone_duedate.sql"),
),
(
"006",
include_str!("../../migrations/006_merge_requests.sql"),
),
];
/// Create a database connection with production-grade pragmas.