fabro/test
Bryan Helmkamp 81554581ca
fix(agent): preserve tool-call pairs during compaction (#447)
## Summary
Fixes OpenAI Responses requests after context compaction by ensuring
preserved tool results are not separated from the assistant tool calls
that produced them. The previous fixed-size preserved tail could retain
a `function_call_output` while dropping the matching `function_call`,
which OpenAI rejects as an orphaned tool result.

## Changes
- Extends `History::compact` so the preserved range moves backward until
every kept tool result has its matching assistant tool call.
- Adds a unit invariant test for compacted histories that serialize tool
results.
- Adds an OpenAI twin integration regression that forces compaction
during a tool-use loop.
- Teaches the OpenAI twin to validate orphaned `function_call_output`
items and script response usage counts for deterministic compaction
tests.

## Test Plan
- `cargo +nightly-2026-04-14 fmt --check --all`
- `git diff --check`
- `FABRO_TEST_MODE=twin cargo nextest run -p fabro-agent --test it
openai_twin_compaction_preserves_tool_call_pairs --run-ignored all`
- `cargo nextest run -p fabro-agent`
- `cargo nextest run -p twin-openai`
- `cargo nextest run -p fabro-test`
- `cargo +nightly-2026-04-14 clippy -p fabro-agent -p fabro-test -p
twin-openai --all-targets --no-deps -- -D warnings`

---

[![Compound
Engineering](https://img.shields.io/badge/Compound_Engineering-6366f1)](https://github.com/EveryInc/compound-engineering-plugin)
🤖 Generated with GPT-5 via [Codex](https://openai.com/codex)
2026-05-28 10:37:30 -04:00
..
analysis feat(test): add DuckDB diff query for bench-tests CSVs 2026-04-28 09:27:05 -07:00
attractor refactor(types): remove stage status compatibility 2026-04-30 06:48:47 -04:00
bin feat(release): support prerelease builds 2026-04-14 15:43:00 -04:00
docs Remove retired OpenAI catalog models 2026-05-24 11:40:35 -04:00
dot-compatibility fix(graph): support dotted Fabro graph attributes (#324) 2026-05-20 09:31:08 -04:00
templated_inputs fix(validate): pick up sibling workflow.toml inputs for bare .fabro path (#242) 2026-05-12 12:05:21 -04:00
templated_unbound_imported fix(validate): treat undefined template vars in @file prompts as warnings (#290) 2026-05-16 17:31:22 -04:00
templated_unbound_partial feat(template): resolve template error locations (#333) 2026-05-20 20:15:04 -04:00
templates fix(workflow): allow workflow-root template partials (#322) 2026-05-20 09:22:28 -04:00
twin fix(agent): preserve tool-call pairs during compaction (#447) 2026-05-28 10:37:30 -04:00
branching.fabro refactor(types): remove stage status compatibility 2026-04-30 06:48:47 -04:00
conditions.fabro refactor(types): remove stage status compatibility 2026-04-30 06:48:47 -04:00
invalid.fabro Rename .dot files to .fabro and update all references 2026-03-13 22:27:19 -04:00
legacy_tool.fabro Rename .dot files to .fabro and update all references 2026-03-13 22:27:19 -04:00
parallel.fabro Attractor spec hunks 14 & 16: remove error_policy and k_of_n/quorum from parallel handler 2026-03-23 14:59:35 -04:00
simple.fabro Rename .dot files to .fabro and update all references 2026-03-13 22:27:19 -04:00
styled.fabro Rename .dot files to .fabro and update all references 2026-03-13 22:27:19 -04:00
templated_unbound.fabro fix(validate): pick up sibling workflow.toml inputs for bare .fabro path (#242) 2026-05-12 12:05:21 -04:00