Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89b01311b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| val call = work[idx].parts.filterIsInstance<Part.ToolCall>().firstOrNull() | ||
| tools.verb(call?.name) !in PINNED_VERBS |
There was a problem hiding this comment.
Preserve pinned actions when pruning a round
Under cap pressure, if an assistant round contains task_progress before hand_to_user, ask_user, or request_confirmation, this firstOrNull() sees only the non-pinned bookkeeping call, so dropOldestRounds deletes the entire assistant message and all its results. ContextCompressor.fold already handles this ordering; apply the same action-call classification here so a handoff or confirmation is not silently removed from the remaining history.
Useful? React with 👍 / 👎.
| val sent = if (restored === raw.messages) raw else raw.copy(messages = restored, estimate = TokenEstimate.of(restored)) | ||
| var restored = ContextRecovery.ensure(history, raw.messages) | ||
| var sent = if (restored === raw.messages) raw else raw.copy(messages = restored, estimate = TokenEstimate.of(restored)) | ||
| fun exceedsCap(est: Int) = UsageMeter.estimate(est + overhead, compressor.scale) > cap || (est + overhead) > ContextLimits.MAX_INPUT_TOKENS |
There was a problem hiding this comment.
Count the transformed prompt toward the input cap
The overhead used by this check is computed from the original systemPrompt, but invokeModel() applies promptTransform before dispatch. If an enabled prompt-rewrite plugin expands the prompt, exceedsCap understates the request size and can send more than 100,000 tokens despite passing this guard; enforce the cap against the transformed prompt.
Useful? React with 👍 / 👎.
| if (fits(work)) return work | ||
| clipCandidateList(ranked { m, p -> isSummaryMessage(m) && p is Part.Text }) | ||
| if (fits(work)) return work | ||
| clipCandidateList(ranked { m, p -> m.author == Author.User && (p is Part.Text || p is Part.Thinking || p is Part.ToolResult) }) |
There was a problem hiding this comment.
Reject image-heavy requests that cannot fit the cap
If user-supplied images keep fits false, this final candidate list cannot clip them, and the earlier image-stripping step skips user messages. enforceCap can therefore return an over-cap request, which ModelCaller.attemptMember sends without a final fit check; downscale the images or fail before dispatch when the cap still cannot be met.
Useful? React with 👍 / 👎.
Summary
Ports 15-step periodic history compaction (keeping the last 3 full observations and screenshots) and a hard 100,000-token input cap per model call onto upstream
main.What this PR includes
ContextLimits: AddsMAX_INPUT_TOKENS = 100_000and capsusableandminTriggerfloor accordingly so large context windows (e.g., 128k / 1M) never exceed 100k input tokens per call.ContextCompressor:COMPACT_EVERY_STEPS = 15), preserving the last 3 full observations (KEEP_FULL_OBSERVATIONS = 3) while folding earlier completed steps into a deterministic summary.MAX_INPUT_TOKENS_CAP = 100_000during compaction and invokesHistoryPruner.enforceCapas a hard cap fallback.HistoryPruner:pruneOlderObservations(keeps the lastkeepFullUI observations and attached screenshots intact while shrinking older screen payloads and images).enforceCap(progressively prunes older observations, shrinks oversized results, strips non-user images, drops oldest non-pinned rounds while keeping tool call/result pairs intact, and clips oversized parts if still over cap).ModelCaller:HistoryPruner.enforceCapif needed) so neither non-streaming nor streaming calls exceed 100,000 estimated input tokens.CompactionAndCapTestand updatesContextLimitsTest,ContextCompressorTest,HistoryPrunerTest,StructuredCompactionTest,PrefixStabilityTest,PrefixStabilityAdaptersTest, andAgentLoopTest.Adaptations for upstream
mainmain(9c7aabd8) with all fork-only changes excluded (no Mika 2 branding, no full UI tree serialization changes, no Vertex/Gemini live refresh).ModelPool(attemptMember),RateLimitGovernor,ConversationMeter, andfirstActionCall()inModelCallerandContextCompressor.ContextCompressor'sfoldEvery: Int? = nullparameter backwards-compatible for existing upstream tests (ContextCompressorTest), while switchingModelCallerto use the new 15-step periodic compaction + keep-last-3-observations policy by default (superseding the temporary 16-roundTEMP_COMPACTION_EVERY_ROUNDSsetting inProviderStore, which can be removed in a follow-up cleanup if desired).UiTreeJsonfull-tree assertion fromCompactionAndCapTestso tests align with upstream'sUiTreeJsonoutput format.Verification
./gradlew :core:test --tests "*ContextLimitsTest*" --tests "*ContextCompressorTest*" --tests "*HistoryPrunerTest*" --tests "*CompactionAndCapTest*" --tests "*PrefixStabilityTest*" --tests "*PrefixStabilityAdaptersTest*" --tests "*StructuredCompactionTest*" --tests "*AgentLoopTest*"— passed (BUILD SUCCESSFUL).