Repository navigation
fix(trajectory): snapshot authoritative loop history - #84
Merged
Merged
Conversation
- Skip the forced flush when cancellation arrives after on_loop_end, so the terminal snapshot is not replaced by an empty envelope. - Re-bind diagnostics by content fingerprint when compaction or a thinking reset substitutes shallow copies of assistant messages. - Degrade non-JSON values instead of failing every later snapshot. - Restore the hook-only contract (messages/tool_calls None or empty). - Count tool results toward coalesced snapshots again. - Keep the spool incremental: re-render only from the first new or changed message, detected by reference signatures. - Omit thinking_blocks annotations already present as native content. - Drop dead _message_count state and redundant history rebinding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83.
Trajectory JSON reconstructed assistant turns from the executable subset of calls and tool messages from result callbacks. This duplicated first-turn assistants when synthetic replies had already been appended, omitted later synthetic replies, and could write an immediate invalid-call result before its assistant because response hooks ran in background tasks. Regression tests reproduce all three failures against main.
Stream JSON snapshots from the loop's live history at coalesced flush boundaries and at completion/cancellation, including every native call, engine-generated reply, post-processed result body, injection, rollback and compaction. Await trajectory hooks to keep response/result events ordered. Keep diagnostic annotations separate from history, release discarded references after snapshots, and preserve atomic replacement, forensic spools on failed writes, image redaction and configured body limits. JSONL continues to record execution events and original tool outputs.
The JSON conversation now follows the normalizer's reasoning policy and native content-block shape; consumers needing flattened text should use
messages.text_of. The documented snapshot contract excludes transient request addenda and provider middleware edits. Includes an independent release fragment without changing the package version.Validation:
pytest -q: 2373 passed, 1 skipped.uv build: source distribution and wheel built successfully.