fix(android): show live chat context usage#92837
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 15, 2026, 9:46 AM ET / 13:46 UTC. Summary PR surface: Other +375. Total +375 across 6 files. Reproducibility: yes. Source inspection on current main shows ChatContextMeter derives both label and fill from thinkingLevel, so high always maps to 82% independent of gateway token metadata; I did not run the old APK. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the Android-scoped fix after Android maintainer review accepts the session-event freshness model, while keeping gateway token accounting and protocol semantics unchanged. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection on current main shows ChatContextMeter derives both label and fill from thinkingLevel, so high always maps to 82% independent of gateway token metadata; I did not run the old APK. Is this the best way to solve the issue? Yes. Reusing existing gateway session metadata/events in the Android controller and composer is the narrow owner-boundary fix; adding a separate Android token source or changing gateway accounting would be broader. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 66079161d72a. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Other +375. Total +375 across 6 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
f71fbd7 to
504ef88
Compare
|
@clawsweeper re-review Added redacted Android emulator proof from a paired throwaway local gateway: fresh |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review The PR body now uses the structured proof fields required by the real-behavior gate, and the |
|
@obviyus This is ready for Android maintainer review now. The PR has connected Android emulator proof in the body, ClawSweeper marked the proof sufficient, CI is green, and I reran local autoreview against |
504ef88 to
13324f0
Compare
|
@clawsweeper re-review I pushed a follow-up for the session-state risk: Android now clears cached context usage when a newer session snapshot omits usage metadata, so the active chat shows |
|
@obviyus I pushed one more Android follow-up for the P1 session-state concern before final review. The branch now clears cached context usage when a newer session snapshot omits usage fields, so the meter prefers |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@obviyus final update from me before your review: I pushed the follow-up for the P1 session-state concern and ClawSweeper has re-reviewed the new head. The fix now clears cached context usage when a newer session snapshot omits usage fields, so Android shows |
989e0c8 to
ca6005a
Compare
|
Landed via rebase onto main.
Thanks @Tosko4! |
Summary
totalTokens/contextTokensmetadata instead of mapping the thinking preset to a fixed percentage.sessions.subscribe) and consumessessions.changed,session.message, andchat.history.sessionInfosession metadata so the meter can update after normal chat activity.Context --instead of displaying a stale or misleading percentage.Linked context
Closes #
Related #
Was this requested by a maintainer or owner?
No public maintainer issue. This was found while testing the Android chat UI: the composer showed the same
Context 82%value across different selected chats.Real behavior proof (required for external PRs)
Proof Mainsession.upstream/main.git diff --checkANDROID_HOME=/home/nabu/Android/Sdk ANDROID_SDK_ROOT=/home/nabu/Android/Sdk ./gradlew :app:clean :app:testThirdPartyDebugUnitTest :app:assembleThirdPartyDebug --no-daemon --stacktraceANDROID_HOME=/home/nabu/Android/Sdk ANDROID_SDK_ROOT=/home/nabu/Android/Sdk ./gradlew :app:testPlayDebugUnitTest :app:assemblePlayDebug --no-daemon --stacktrace./gradlew :app:installThirdPartyDebug --no-daemon --stacktrace, Android emulator pairing to a throwaway local proof gateway, opening the syntheticProof Mainchat, and capturingadbscreenshots plusuiautomatordumps../gradlew :app:lintThirdPartyDebug --no-daemon --stacktrace.BUILD SUCCESSFULfor:app:clean :app:testThirdPartyDebugUnitTest :app:assembleThirdPartyDebug.BUILD SUCCESSFULfor:app:testPlayDebugUnitTest :app:assemblePlayDebug.totalTokensFresh=false) replaces previous fresh metadata and renders as unknown usage.Context 41% · high, matching20500 / 50000 = 41%.Context -- · highwhentotalTokensFresh=false.Fresh metadata screenshot:
Stale metadata screenshot:
Context --for stale or absent usage. Thinking level remains visible in the same control.Context --state shown in the stale-metadata screenshot.ChatContextMeterderives the percentage fromthinkingLevel, withhighmapped to82%, so the displayed context value is independent of gatewaytotalTokens/contextTokensusage.Tests and validation
Commands run on the current rebased head:
git diff --checkANDROID_HOME=/home/nabu/Android/Sdk ANDROID_SDK_ROOT=/home/nabu/Android/Sdk ./gradlew :app:clean :app:testThirdPartyDebugUnitTest :app:assembleThirdPartyDebug --no-daemon --stacktraceANDROID_HOME=/home/nabu/Android/Sdk ANDROID_SDK_ROOT=/home/nabu/Android/Sdk ./gradlew :app:testPlayDebugUnitTest :app:assemblePlayDebug --no-daemon --stacktraceConnected Android proof also run earlier on this branch:
./gradlew :app:installThirdPartyDebug --no-daemon --stacktraceadbconnected-runtime screenshot proof against a throwaway local proof gateway.Regression coverage added:
mainalias resolution.Known validation note:
:app:lintThirdPartyDebugstill fails on existing unrelated lint errors outside this PR's touched code:OnboardingFlow.kt:POST_NOTIFICATIONSAPI-level lint.DeviceHandler.kt: package visibility lint.GatewayDiscovery.kt: two@RequiresApilint findings.app/src/debug/AndroidManifest.xml: exported receiver permission lint.Risk checklist
Did user-visible behavior change? (
Yes/No)Yes.
Did config, environment, or migration behavior change? (
Yes/No)No.
Did security, auth, secrets, network, or tool execution behavior change? (
Yes/No)No security/auth change. The Android operator connection now best-effort subscribes to existing gateway session events after connect.
What is the highest-risk area?
Session metadata freshness in the Android chat UI.
How is that risk mitigated?
The controller now distinguishes snapshots that explicitly include context-usage metadata from snapshots that omit usage fields. Explicit fresh usage renders the percentage, explicit stale usage renders
Context --, and newer snapshots with no usage fields clear previously cached token usage so the active chat cannot inherit stale context usage from an earlier event. Focused tests cover the meter decision logic and the session merge policy. The debug build installs on an emulator and the redacted emulator proof shows both fresh and stale gateway metadata states.Current review state
What is the next action?
Android maintainer review and merge judgment on the clean rebased head.
What is still waiting on author, maintainer, CI, or external proof?
Waiting on maintainer review/merge judgment. CI is green on the pushed head, and ClawSweeper re-review is complete with
status: ready for maintainer look,proof: sufficient, and no contributor-facing automated repair. ClawSweeper still flags the session-state risk for maintainer awareness because this path depends on session event freshness.Which bot or reviewer comments were addressed?
Addressed ClawSweeper's proof request with redacted Android emulator proof showing the composer context meter updating from connected gateway
totalTokens/contextTokensmetadata and showingContext --for stale usage. Also addressed ClawSweeper's session-state risk by clearing cached usage when newer session snapshots omit usage metadata, so Android prefers unknown usage over stale or wrong usage.AI-assisted: implemented with Codex, then manually inspected and tested in a local Android/OpenClaw setup.