Skip to content

fix(sensor): keep Gemini CLI history patches out of session metadata - #216

Open
rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/sensor-gemini-patch-records
Open

rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/sensor-gemini-patch-records

Conversation

@rudycelekli

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related issue: N/A (found by reading the code; reproduced on main at 6b33dff)

What changed?
Treat $patch records like $rewindTo: append them to journal_controls and do not apply them, consistent with the module's stated policy of retaining recorded activity across rewinds (masking/removing model context does not undo actions). Tool results still come from full message upserts (recordToolCalls -> pushMessage), which are unchanged.

Why?
Gemini-cli (google-gemini/gemini-cli#29568, merged 2026-10-01, packages/core/src/services/chatRecordingTypes.ts MessagePatchRecord, chatRecordingService.ts:1587 appendRecord({ $patch: patchPayload })) now appends {"$patch": {updates, removeIds, orderIds}} records when it syncs history (tool-output masking, removed/reordered turns). GeminiParser.parse_file (Sensor/adr_sensor/parsers/gemini_parser.py:143-156) only special-cases $rewindTo and $set; any other record without "id" is treated as a metadata update, so the whole patch lands in session_context.session_metadata["$patch"], each patch overwriting the previous one, and it is not listed in journal_controls.

How did you test it?

  • Reproduction: new tests/test_gemini_parser.py::test_history_patch_is_a_journal_control_not_session_metadata. main: FAILED ('$patch' not in {...session_metadata...}); branch: passed (patch in journal_controls, original tool result and both messages kept).
  • Test suite: Sensor pytest tests/ -q (py3.14) 609 passed; ruff clean; Python 3.9.6 parser test files 245 passed.
  • Not tested: a real gemini-cli journal with $patch (no Gemini CLI data locally); record shape taken from the upstream source above. Judgement call for the lead: an alternative would be to apply content/toolCalls patches, but that would replace recorded tool output with masked placeholders, against the parser's documented retention policy.

Potential risks
The change only affects the input described above; other paths go through the same code as before, and the component's existing tests pass.

AI assistance: Claude Code (model Claude Opus 5.5) found this bug, wrote the fix and test, and drafted this description; submitted by @rudycelekli.

🤖 Generated with Claude Code

Gemini CLI journals now append {"$patch": {...}} records when it syncs
history (masked tool output, removed or reordered messages). The parser
only knew $rewindTo and $set, so a patch was merged into session_metadata
under a "$patch" key, each one replacing the last. Patches are now kept
in journal_controls like rewinds, and recorded activity is left as-is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants