Skip to content

Fix bulk of remaining issues with generalist profile#26073

Merged
joshualitt merged 37 commits intomainfrom
jl/cm-part-3
May 1, 2026
Merged

Fix bulk of remaining issues with generalist profile#26073
joshualitt merged 37 commits intomainfrom
jl/cm-part-3

Conversation

@joshualitt
Copy link
Copy Markdown
Contributor

Fixes #26072

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

Size Change: +12.9 kB (+0.04%)

Total Size: 33.9 MB

Filename Size Change
./bundle/chunk-3OETCUFQ.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-5EYBYUKZ.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-D4G2GSKB.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-EZGRGWLS.js 0 B -3.8 kB (removed) 🏆
./bundle/chunk-PXWSJWYN.js 0 B -12.5 kB (removed) 🏆
./bundle/chunk-TBLC5X2Z.js 0 B -14.7 MB (removed) 🏆
./bundle/chunk-VZQPYSEV.js 0 B -657 kB (removed) 🏆
./bundle/chunk-WQNKA6DF.js 0 B -2.72 MB (removed) 🏆
./bundle/core-N6P4X5N7.js 0 B -48.2 kB (removed) 🏆
./bundle/devtoolsService-ATQWCW5M.js 0 B -28 kB (removed) 🏆
./bundle/gemini-JTJPFVP2.js 0 B -581 kB (removed) 🏆
./bundle/interactiveCli-JMFOXQCD.js 0 B -1.32 MB (removed) 🏆
./bundle/liteRtServerManager-OZQ3HQQM.js 0 B -2.11 kB (removed) 🏆
./bundle/oauth2-provider-QDW2BPRR.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-2GBTYYSR.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-B26YBQG4.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-FUAS2IPB.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-NGXDOOSC.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-OVKNWUPB.js 657 kB +657 kB (new file) 🆕
./bundle/chunk-RRO2HM2M.js 2.72 MB +2.72 MB (new file) 🆕
./bundle/chunk-RTZRXWFI.js 14.7 MB +14.7 MB (new file) 🆕
./bundle/chunk-VVVCVVVE.js 12.5 kB +12.5 kB (new file) 🆕
./bundle/core-2PXEWS2G.js 48.4 kB +48.4 kB (new file) 🆕
./bundle/devtoolsService-OOZEHMRE.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-QF4GJSMO.js 581 kB +581 kB (new file) 🆕
./bundle/interactiveCli-X5KJW7SH.js 1.32 MB +1.32 MB (new file) 🆕
./bundle/liteRtServerManager-WGAVFDG7.js 2.11 kB +2.11 kB (new file) 🆕
./bundle/oauth2-provider-YLU6YZJJ.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IBHWQ36L.js 1.97 MB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-HRUJPPJX.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.1 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-KH2QDS2N.js 980 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/start-JPLMCYWE.js 0 B -652 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-GUXJ5VYU.js 932 B +932 B (new file) 🆕
./bundle/start-RSIJHHXY.js 652 B +652 B (new file) 🆕

compressed-size-action

- Inject stable synthetic IDs in GeminiChat for tool calls lacking them.
- Remove brittle positional matching in ContextGraphBuilder.
- Transition ContextGraph to deterministic ID-based lookup for tool results.
- Update system snapshots to reflect cleaner history mapping.
- Move synthetic ID generation to GeminiChat stream processing.
- Inject IDs directly into chunk objects to synchronize executor (Turn.ts) and history.
- Implement stateful deduplication during streaming to handle SDK repeats/deltas.
- Use stable synth_${promptId}_${index} format for absolute determinism.
- Standardize Turn.ts to trust and fallback to the same stable ID scheme.
- Refactor ContextGraphBuilder to process history in a single, stateless pass.
- Eliminate turn-to-turn persistent state to prevent mapping drift.
- Simplify ContextGraphMapper to utilize atomic reconstruction.
- Ensure structural resilience to history truncation and reordering.
- Introduce HistoryHardener utility to enforce Gemini API invariants.
- Patch role alternation, user-anchoring, and trailing-user requirements.
- Automatically repair orphaned tool calls with sentinel response nodes.
- Integrate hardener as the final step in context rendering.
- Update tests and snapshots to reflect defensive sentinel turns.
- Update graph nodes to store and serialize thoughtSignatures.
- Fix structural misalignment where signatures were dropped during projection.
- Fix bug in GeminiChat where fixed contents with signatures were discarded.
- Ensure tool calls are correctly linked to thoughts for Gemini-3 models.
- Pivot IR from a reconstructive model to a lossless 1:1 mirror of Gemini Parts.
- Update ContextGraphBuilder to perform 1:1 part-to-node projection.
- Update ContextProcessors (Truncation, Distillation, Masking, Snapshotting) to operate directly on pristine Part payloads.
- Simplify reconstruction logic in fromGraph to preserve original Part objects.
- Refactor all context tests and utilities to align with the flattened structure.
- Add safe Part cloning helpers with justified lint suppressions.
- Update system golden snapshots to reflect improved token estimation efficiency.
…ping

- Remove the logic that dropped orphaned function responses, as it was causing 'function name mismatch' errors when the API state became inconsistent.
- Instead, rely on the existing logic to inject missing responses for calls, which is the safer way to restore API invariants.
- This simplification ensures that we don't inadvertently create state mismatches by removing one half of a call/response pair while keeping the other.
- Re-enable the logic in HistoryHardener to drop 'functionResponse' parts if their preceding 'functionCall' was truncated. This is required by the Gemini API to maintain turn pairing invariants.
- Add ID-based deduplication in 'fromGraph' to ensure each node appears at most once in the history, preventing 'function name mismatch' and duplicate ID errors.
- These changes together ensure that the reconstructed history is both valid and consistent with the API's expectations.
…ardening

- Added 'Node Pinning' in ContextManager to prevent 'in-flight' tool calls (calls without responses) from being truncated during context management.
- Refactored HistoryHardener into a multi-pass validator that strictly enforces role alternation and pairing invariants.
- Fixed 'starts with model' and 'mismatched call/response' API errors by ensuring structural integrity is enforced AFTER all tool pairing modifications.
- Updated golden snapshots to reflect improved sentinel messaging.
- Implementation of globally unique synthetic IDs in GeminiChat and Turn.
- IDs now include promptId, turn timestamp, and a persistent counter to prevent collisions.
- Updated ContextGraphBuilder (toGraph.ts) to prioritize API/Synthetic IDs for node identity.
- Ensured that tool execution results preserve the call's unique ID, enabling 1:1 mapping in the graph.
- Verified with system lifecycle tests.
… observation

- Modified HistoryObserver to always process the FULL history from AgentChatHistory. Previously, it was only processing the incremental PUSH payload, which caused the ContextManager to erroneously prune all existing history nodes.
- Updated renderHistory in ContextManager to correctly identify and protect active tool calls during the synchronous rendering phase.
- These changes ensure that the Context Graph remains stable and only prunes nodes when they actually exceed the configured token budget.
…plication and token overcounting

- Implementation of stable, content-based IDs in 'toGraph.ts' using type-safe salted hashing (content + turn/part indices). This ensures node IDs remain consistent even when history objects are re-created (e.g., during thought stripping).
- Used idiomatic TypeScript type guards to safely handle Part subtypes while complying with strict ESLint rules.
- Added ID-based deduplication in 'ContextTokenCalculator' to ensure each unique node is only counted once toward the token budget.
- Refactored 'appendPristineNodes' in 'ContextWorkingBuffer' to skip nodes already present in the buffer by ID.
- These changes resolve the 'cutting too deep' issue where re-synchronization events caused the history to double in the internal buffer, triggering premature and aggressive truncation/summarization.
- Verified with all 113 context and system lifecycle tests.
- Fixed context graph ID collisions by namespacing tool call and response IDs ('call_' and 'resp_'). This ensures responses are not filtered out as duplicates of their corresponding calls.
- Refined token estimation heuristics to exclude massive 'thoughtSignature' metadata blobs (saving 100k+ phantom tokens in complex sessions).
- Updated image token estimates to Gemini 1.5 standards (258 tokens vs 3000).
- Verified with all context unit tests and system lifecycle golden tests.
- Added 'trace-improvements.md' documenting observability goals.
- Implemented 'Budget Audit' tracing to track max/retained tokens and pressure.
- Implemented 'Protection Audit' with structured reasons (e.g., system_prompt, in_flight_tool_call).
- Implemented 'Transformation Lineage' tracing in Orchestrator to track N->M node replacements and size deltas.
- Implemented 'Estimation Calibration' breakdown (Text, Media, Tool, Overhead) to verify token heuristics.
- All 113 context tests and system lifecycle tests passed.
- Updated 'render.ts' to protect all nodes in the most recent turn (logical episode) rather than just the single last node. This prevents partial pruning of multi-part turns which was causing orphaned tool calls.
- Updated 'toGraph.ts' with robust ID extraction that only uses API IDs if they are valid strings, and added content-based hashing fallback to ensure stability across history re-syncs even for tool parts without IDs.
- Verified with system lifecycle tests.
- Implemented index-independent stable IDs in toGraph.ts using content-based turn salts and occurrence counters. This prevents IDs from changing when history is re-indexed.
- Updated renderHistory to return metadata about whether permanent context management was applied.
- Updated GeminiClient to only overwrite chat history if real management (pruning/summarization) occurred, preventing transient hardening sentinels from poisoning the pristine conversation record.
- Ensures atomic protection of all parts in the most recent turn.
- Verified with system lifecycle tests.
…calls

- Fixed timing bug where tool responses were missing during context rendering by adopting requests into history immediately in 'GeminiClient'.
- Implemented 'refineToolResponses' in 'HistoryHardener' to hoist and re-order tool responses, ensuring strict API compliance and better model follow-up.
- Upgraded 'getStableId' to use SHA-256 for robust collision resistance in large graphs.
- Updated 'hardening-improvements.md' to track long-term stability goals.
- Verified with system lifecycle tests (Scenario 1-3).
- Updated hardening roadmap to reflect the decision to preserve mixed turns (tool responses + text) for better hinting support and role alternation stability.
- Confirmed core structural improvements (re-ordering, hoisting, SHA-256) are complete.
…d 'SILENT_SYNC' to break history re-sync loops.\n- Added Synchronous Pressure Barrier in 'renderHistory' to resolve sync/async race conditions.\n- Centralized node protection in 'ContextManager' to globally pin System Prompt and Recent Context.\n- Implemented render caching using graph-hash to reduce redundant overhead.\n- Refined processor thresholds for increased pruning sensitivity.\n- Fixed core test failures and updated system lifecycle golden snapshots.\n- Updated 'bugs.md' to reflect resolved status for all identified anomalies.
@joshualitt joshualitt marked this pull request as ready for review April 30, 2026 18:36
@joshualitt joshualitt requested a review from a team as a code owner April 30, 2026 18:36
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness and reliability of the context management system. By introducing history hardening, refining graph-to-history reconstruction, and enhancing token calculation accuracy, the changes ensure that the agent's context remains valid and within budget constraints. Additionally, the orchestrator has been updated to handle asynchronous pipeline execution more safely, and a new render cache reduces unnecessary computation.

Highlights

  • Context Management Hardening: Introduced a hardenHistory utility to ensure chat history adheres to Gemini API invariants, including role alternation, start/end constraints, and tool call pairing, using sentinel messages to patch violations.
  • Graph-to-History Reconstruction: Refactored fromGraph to be role-alternation-aware, using turnId to preserve original turn boundaries and ensure high-fidelity reconstruction of chat history from the episodic context graph.
  • Token Calculation Improvements: Updated token estimation constants and added structural overhead tracking per turn to improve the accuracy of context budget management.
  • Orchestrator Pipeline Safety: Implemented a pipeline mutex and node provider in the PipelineOrchestrator to ensure sequential pipeline execution operates on the latest live buffer state, preventing stale data processing.
  • Performance Optimization: Added a render cache to ContextManager to skip redundant history rendering when the graph and header state remain unchanged.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the context management system to improve fidelity by implementing a 1:1 mapping between graph nodes and Gemini Part objects, removing logical nodes like Episodes and Tasks. It introduces a history hardening pass to enforce API invariants and synchronous pressure barriers to ensure state consistency. Token estimation heuristics and profile configurations were also updated. A security vulnerability was identified in the BlobDegradationProcessor where unsanitized mimeType strings could lead to path traversal; a suggestion was provided to sanitize the file extension.

Comment thread packages/core/src/context/processors/blobDegradationProcessor.ts
@joshualitt joshualitt added this pull request to the merge queue May 1, 2026
@joshualitt joshualitt removed this pull request from the merge queue due to a manual request May 1, 2026
@joshualitt joshualitt added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit de8fdcf May 1, 2026
27 checks passed
@joshualitt joshualitt deleted the jl/cm-part-3 branch May 1, 2026 22:20
TirthNaik-99 pushed a commit to TirthNaik-99/gemini-cli that referenced this pull request May 4, 2026
kimjune01 pushed a commit to kimjune01/gemini-cli-claude that referenced this pull request May 6, 2026
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.

Fix issues with generalist profile

2 participants