Skip to content

fix(persistence): prevent orphaned tool_use entries after utility-gate intercept#3210

Merged
bug-ops merged 1 commit intomainfrom
3168-utility-gated-orphaned-sqlite
Apr 18, 2026
Merged

fix(persistence): prevent orphaned tool_use entries after utility-gate intercept#3210
bug-ops merged 1 commit intomainfrom
3168-utility-gated-orphaned-sqlite

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 18, 2026

Summary

  • persist_message silently stored parts_json = "[]" on serde failure, creating rows with no ToolResult parts that orphaned_tool_use_ids could never match — now returns early with an error log
  • Forward pass of strip_mid_history_orphans passed messages.get(i + 1) directly, so a System hint between an assistant tool_use and the user tool_result caused false orphan detection — now scans past System messages to find the first non-System candidate
  • Reverse pass had the same gap (found during test coverage), fixed symmetrically
  • Adds 3 regression tests: round-trip, System-between-pair, corrupt-parts-row

Test plan

Closes #3168

…e intercept

Three bugs in `strip_mid_history_orphans` and `persist_message` caused a WARN
flood on session startup whenever the utility gate intercepted a tool call:

1. `persist_message` silently stored `parts_json = "[]"` on serde failure,
   producing a row with no ToolResult parts that orphaned_tool_use_ids could
   never match. Now returns early with an error log instead.

2. Forward pass of `strip_mid_history_orphans` passed `messages.get(i + 1)`
   directly to `orphaned_tool_use_ids`, so a System hint between an assistant
   tool_use and the user tool_result was mistaken for the pair's next message,
   making the ToolUse appear orphaned. Now scans past System messages to find
   the first non-System candidate.

3. Reverse pass had the same gap (found during test coverage). Fixed
   symmetrically.

Adds three regression tests covering the round-trip, System-between-pair, and
corrupt-parts-row scenarios.

Closes #3168
@github-actions github-actions Bot added rust Rust code changes core zeph-core crate bug Something isn't working size/L Large PR (201-500 lines) labels Apr 18, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 18, 2026 21:31
@bug-ops bug-ops merged commit 44020ce into main Apr 18, 2026
32 checks passed
@bug-ops bug-ops deleted the 3168-utility-gated-orphaned-sqlite branch April 18, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core zeph-core crate rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: utility-gated tool_use leaves orphaned SQLite entry — WARN flood on next session

1 participant