Files
vibe-kanban/crates
Louis Knight-Webb fde7ae3efe Parse amp errors (vibe-kanban) (#852)
* ##  Implementation Complete!

I've successfully implemented the amp error parsing functionality. Here's a summary of what was accomplished:

### **Changes Made:**

1. **Extended ClaudeJson::Result** with amp-specific fields:
   - Added `error`, `num_turns`, `session_id` fields with proper serde aliases
   - Used `#[serde(default)]` for backward compatibility

2. **Updated normalize_entries method** to handle amp errors:
   - Only processes Result messages for `HistoryStrategy::AmpResume`
   - Detects errors through multiple criteria: `is_error`, subtype containing "error", error field presence, or result field containing error/message
   - Creates user-friendly ErrorMessage entries with timing and turn information
   - Preserves existing behavior for Claude Code (Default strategy)

3. **Updated extract_session_id** to handle Result messages:
   - Now extracts session_id from Result messages when present

4. **Added comprehensive tests**:
   - `test_amp_result_error_is_surfaced` - Tests the original error case from your example
   - `test_amp_result_error_with_subtype_only` - Tests subtype-only error detection
   - `test_amp_result_error_from_result_field` - Tests error extraction from result field
   - `test_amp_result_success_still_ignored` - Ensures success results remain ignored
   - `test_amp_result_session_id_extraction` - Tests session ID extraction
   - `test_claude_result_still_ignored_for_default_strategy` - Ensures Claude Code behavior unchanged

### **Example Output:**
When amp emits the error JSON you provided:
```json
{"type":"result","subtype":"error_during_execution","duration_ms":456090,"is_error":true,"num_turns":24,"error":"terminated","session_id":"T-efa72d99-3436-467b-a2d2-872546ad6f3c"}
```

It will now appear in the UI as:
> **AMP error (error_during_execution) after 24 turns / 456.1s: terminated**

The execution will correctly show as failed instead of "ended normally", and users will get clear information about what went wrong, how long it took, and how many turns were attempted.

* Cleanup script changes for task attempt daa967fc-b0a1-4c02-966f-ca3435e20a56

* Perfect!

##  Simplified Implementation Complete!

I've successfully simplified the error output as requested. Here's what changed:

### **Key Changes Made:**
1. **Simplified error content** - Now uses `serde_json::to_string(claude_json)` to JSON stringify the entire error object
2. **Removed complex formatting** - No more "AMP error (subtype) after X turns / Y.Ys: message" formatting
3. **Updated tests** - All test assertions now check for the raw JSON fields instead of formatted text
4. **Clean compilation** - Fixed unused variable warnings

### **Example Output:**
When amp emits the error JSON you provided:
```json
{"type":"result","subtype":"error_during_execution","duration_ms":456090,"is_error":true,"num_turns":24,"error":"terminated","session_id":"T-efa72d99-3436-467b-a2d2-872546ad6f3c"}
```

The UI will now show this exact JSON string as the error content, making it simple and giving users direct access to all the error information without interpretation.

### **Benefits:**
-  Simpler, cleaner output
-  No loss of information - all fields are preserved in the JSON
-  Maintains backward compatibility with Claude Code
-  All tests passing
-  Clean compilation with no warnings

The execution will still correctly show as failed instead of "ended normally", and the raw JSON error provides all the context users need to understand what went wrong.

* Cleanup script changes for task attempt daa967fc-b0a1-4c02-966f-ca3435e20a56

* Perfect!

##  Changes Complete!

I've made the requested modifications:

### **Changes Made:**

1. **Changed "AMP error" to "error"** in the fallback case:
   ```rust
   content: serde_json::to_string(claude_json)
       .unwrap_or_else(|_| "error".to_string()),
   ```

2. **Removed all amp result tests** that I added earlier:
   - `test_amp_result_error_is_surfaced`
   - `test_amp_result_error_with_subtype_only`
   - `test_amp_result_error_from_result_field`
   - `test_amp_result_success_still_ignored`
   - `test_amp_result_session_id_extraction`
   - `test_claude_result_still_ignored_for_default_strategy`

### **Final Implementation:**

The core functionality remains: when amp emits error result JSON logs like:
```json
{"type":"result","subtype":"error_during_execution","duration_ms":456090,"is_error":true,"num_turns":24,"error":"terminated","session_id":"T-efa72d99-3436-467b-a2d2-872546ad6f3c"}
```

This exact JSON string will be shown as the error content in the UI, and the execution will correctly be marked as failed instead of "ended normally".

The implementation is now minimal and clean, with only the original `test_result_message_ignored` test remaining to ensure Claude Code compatibility is preserved.

* Excellent!

##  Simplified Error Detection Complete!

I've updated the error detection logic to only trigger when `is_error: true`, making it much simpler and more explicit.

### **Changes Made:**

1. **Simplified error detection** - Now only checks `is_error.unwrap_or(false)`
2. **Removed complex error detection logic** that previously checked:
   - Subtype containing "error"
   - Error field presence/non-empty
   - Result field containing error/message objects
3. **Cleaned up unused variables** - Marked unused fields with `_`

### **Final Behavior:**

The implementation now only creates an ErrorMessage entry when:
- `HistoryStrategy::AmpResume` is used (amp execution)
- `is_error: true` in the JSON result

When your original error case occurs:
```json
{"type":"result","subtype":"error_during_execution","duration_ms":456090,"is_error":true,"num_turns":24,"error":"terminated","session_id":"T-efa72d99-3436-467b-a2d2-872546ad6f3c"}
```

This will be displayed as the raw JSON content since `is_error: true`, and the execution will be marked as failed.

The logic is now clean, explicit, and relies solely on amp's `is_error` flag to determine when to surface errors in the UI.
2025-09-25 17:55:34 +01:00
..
2025-09-25 08:08:33 +00:00
2025-09-25 08:08:33 +00:00