Skip to content

improve(android): reuse chat history during live updates - #147940

Merged
vincentkoc merged 1 commit into
mainfrom
perf/android-prepared-history-tranche4
Sep 14, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/android-prepared-history-tranche4

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Closes #147937

What Problem This Solves

Android chat repeats unchanged history preparation when streaming text or pending tools update.

User Impact

No intended visual or behavioral change. This reduces repeated internal preparation work while preserving chat content, disclosure, message identity, and scroll ownership. No configuration or migration is required.

This is not a claim about overall Android speed, phone frame time, retained heap, RSS, or APK size. The candidate retains flat metadata and can retain an additional history-sized reference container in non-dashboard cases.

Why This Change Was Made

ChatScreen remembers prepared history by the complete message list and session. The preparation reuses the existing projection and completed-work analysis, retaining canonical rows and flat spans rather than temporary turn graphs. Live updates emit one final timeline directly; final row materialization remains linear.

The internal raw-history builder and second grouping pass are removed, with all existing callers migrated together. Tests preserve live suppression, early content/tool-result replacement with stable IDs and an unchanged tail, disclosure during later streaming, and disclosure reset on session changes.

Evidence

  • Full preservation suites and scoped checks: baseline 153/153 and candidate 153/153 across nine classes, no failures or skips; changed checks and diff check passed. A later private-reporting failure left that attempt's aggregate and source restoration unqualified. Those passing components are retained, not represented as a complete successful run.
  • Source-bound retained capture/parity/timing results: real ChatCompletedWorkLayoutTest baseline 5/5 and candidate 5/5; nine parity cells and all 45 pairs completed. All 23 input pins were restored, the archive and unique artifact marker were verified, and the owned lease completed. "Completed campaign" refers to these verified source-bound retained results and cleanup, not a successful GitHub workflow conclusion: this Actions lifecycle is terminal CANCELLED.
  • Nine corresponding before/after screenshot pairs are byte-identical. The fixtures exercise the actual ChatScreen, including disclosure, replacement, hidden turns, and session reset.
  • Fresh scoped P0-P2 review found no actionable findings. The later stable-idempotency-key fixture correction was separately reviewed. Only byte-verified remote formatter output was applied afterward.

The timing matrix used 200/1,000/5,000 synthetic messages, collapsed/expanded/non-dashboard modes, and 100 live updates per batch. Each cell had three warmup batches per arm and five alternating pairs. Candidate preparation is included inside every batch; typed parity, hashing, and verification are outside timing, with a bounded last-result sink.

Runtime: Linux x64, Eclipse Adoptium JVM 21.0.10; Gradle 9.7.1 used the repository's Java 21 daemon policy with a Java 17 launcher. These are JVM helper measurements, not Android ART measurements.

Synthetic messages Mode Baseline median ms / 100 updates Candidate median ms / 100 updates Median paired wall reduction Positive pairs
200 Collapsed 1.708 0.428 75.35% 5/5
200 Expanded 1.764 0.433 75.41% 5/5
200 Non-dashboard 0.820 0.226 72.45% 5/5
1,000 Collapsed 7.622 1.447 81.02% 5/5
1,000 Expanded 7.791 1.132 85.75% 5/5
1,000 Non-dashboard 3.446 0.665 81.85% 5/5
5,000 Collapsed 43.139 3.312 92.23% 5/5
5,000 Expanded 47.053 3.895 91.39% 5/5
5,000 Non-dashboard 18.631 2.177 88.10% 5/5

Paired reductions are medians of 100 * (A - B) / A for the five pairs, not ratios of the separate arm medians. The 5,000-message collapsed median difference is about 0.398 ms per update. These synthetic history sizes are not established production limits; five favorable pairs do not establish a statistical confidence bound.

Process-CPU samples were coarse, including zero-denominator pairs, so wall time is the primary result. Separate JFR profiles locate allocation activity but do not provide exact allocation totals or retained-memory measurements. Raw recordings and the full archive are not published because they can include environment and process metadata.

Proof base: a43ed90d0e9f22d929c86b3a850ae51209006656. Measured unformatted patch SHA-256: 6d74a8649aa673791f46ae42e22220c37ca0d18ef060ceb5f8c7903dec0f41cc. Verified formatter-only patch SHA-256: 43003aeef066ea629f2a4c80078b65ecccb0a8419fb53780dbf7c769eb28017e.

The separate exact-head hosted CI run 34809774031 is SUCCESS. Native review, prepare, and squash merge completed on September 14, 2026 at 06:06:40 UTC as 5e26a6646663a7d960378f8afe3947ba11a59dcc. All twelve landed files match the prepared head, and native cleanup is complete. Native admitted an advisory mainline-infrastructure drift warning under its existing policy; no enforced gate was bypassed or guard flag changed. The proof scope and historical limitations above are unchanged.

Before and after

Expanded completed work is intentionally unchanged.

Baseline Candidate
Baseline expanded completed work Candidate expanded completed work

@vincentkoc vincentkoc self-assigned this Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@vincentkoc
vincentkoc marked this pull request as ready for review September 14, 2026 05:28
@openclaw-barnacle openclaw-barnacle Bot added app: android App: android size: L maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 1:39 AM ET / 05:39 UTC.

ClawSweeper review

What this changes

Android chat reuses prepared transcript rows and completed-work metadata during live updates, with preservation tests for content replacement, disclosure, and session changes.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization: current main still repeats history preparation during live updates. No actionable correctness or security defect was found, and the maintainer-authored PR remains paired with its open issue.

Priority: P2
Reviewed head: 8210ac711b0d7177f2a010a13e05c7d18530b658

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful preservation coverage and inspected visual evidence; performance conclusions remain appropriately limited to reported JVM measurements.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.
Evidence reviewed 7 items Current main still performs repeated preparation: Fetched main rebuilds the transcript when streaming text or pending tools change, then applies completed-work grouping. The proposed preparation boundary is therefore still useful.
Lifecycle-scoped preparation and complete cutover: Preparation is remembered by the complete message list and session; live inputs still invalidate final assembly. The old builder and grouping entry points have no remaining production references. Canonical message objects, stable keys, and disclosure ownership remain intact.
Preservation coverage exercises the chat screen: The added Robolectric cases use ChatScreen and the controller to verify earlier text/tool-result replacement with unchanged IDs and tail, expanded history during later streaming, and disclosure reset across sessions. These are preservation tests, not Android device-performance measurements.
Findings None None.
Security None None.

How this fits together

Android chat combines published message history with streaming text, pending tools, and queued messages. Its timeline supplies the visible conversation, completed-work disclosures, and scroll anchors.

flowchart TD
  A[Published history and session] --> B[Prepare transcript rows and work spans]
  B --> C[Reuse prepared history]
  D[Live text and tool updates] --> E[Assemble timeline]
  C --> E
  F[Disclosure state] --> E
  E --> G[Chat rows and scroll anchors]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +147, Other +43. Total +190 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 9 230 83 +147
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 142 99 +43
Total 12 372 182 +190

Review metrics

Metric Value Why it matters
Production and preservation coverage Production +43 net lines; tests +147 net lines Production growth introduces reusable flat preparation metadata; most net growth protects existing behavior during that cutover.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #147937
Summary: This PR is the explicit implementation candidate for the paired preparation-cost issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep transcript preparation within the chat-screen lifecycle, invalidated by complete history and session changes, while preserving the existing rendering and scroll contracts.

Do we have a high-confidence way to reproduce the issue?

Yes, for repeated preparation: current-main ChatMessageList rebuilds history when live text or tools change. Source establishes that mechanism; no phone-performance regression was reproduced.

Is this the best way to solve the issue?

Yes. Reusing existing projection and grouping logic at the screen's history/session boundary avoids a competing cache owner, and all former callers migrate together.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ad157baa20b1.

Labels

Label changes:

  • add P2: This is a bounded Android chat preparation optimization without a demonstrated urgent user-facing regression.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.

Label justifications:

  • P2: This is a bounded Android chat preparation optimization without a demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The external-contributor proof gate does not apply to this MEMBER-authored internal optimization. Inspected ChatScreen fixture screenshots support visual preservation; the reported JVM campaign does not establish Android device performance.

Evidence

What I checked:

Likely related people:

  • answer: Raw commit 4ad3a43 adds apps/android/app/src/main/java/ai/openclaw/app/ui/chat/ChatWorkedSummary.kt:48 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4ad3a43562fd; files: apps/android/app/src/main/java/ai/openclaw/app/ui/chat/ChatWorkedSummary.kt)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@vincentkoc
vincentkoc merged commit 5e26a66 into main Sep 14, 2026
113 of 114 checks passed
@vincentkoc
vincentkoc deleted the perf/android-prepared-history-tranche4 branch September 14, 2026 06:06
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Sep 17, 2026
Port upstream 5e26a66: split buildChatTimeline into prepareChatHistory + buildTimeline, add expandedWorkKeys, and reuse chat history across live updates.

This is the prerequisite refactor for openclaw#148050 (collapse completed work), which assumes prepareChatHistory/buildTimeline/expandedWorkKeys already exist. Fork customizations (iOS-aligned timestamp placement in ChatScreen, composer squircle/104dp) are preserved.
threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Sep 17, 2026
Port upstream 5e26a66: split buildChatTimeline into prepareChatHistory + buildTimeline, add expandedWorkKeys, and reuse chat history across live updates.

Prerequisite refactor for openclaw#148050 (collapse completed work). Fork customizations (iOS-aligned timestamp placement in ChatScreen, composer squircle/104dp) preserved. Version reset to 2026.9.17.1 (new day).
threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Sep 17, 2026
)

Port upstream b4c6e36: add ChatMessage.phase/isError, ChatTimelineItem.hasUnresolvedTools, and collapse completed work in default chats. Builds on openclaw#147940 (prepareChatHistory/buildTimeline/expandedWorkKeys).

Version 2026.9.17.2.
threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Sep 17, 2026
…48904)

Port upstream 03c158f: render cited source previews (favicon + source list) in chat. Adds 4 new files (ChatSourceTools, GatewaySourcePreviews, ChatSourcePreviewViews, ChatSourcePreviews), wires AndroidScreenshotFixture.sourcePreviewConfig/loadSourceFavicon into NodeRuntime, and updates native-source.json (+7 strings).

Depends on openclaw#148050 (phase/isError/hasUnresolvedTools) which depends on openclaw#147940 (prepareChatHistory/buildTimeline/expandedWorkKeys). Fork customizations preserved. Version 2026.9.17.3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid repeated Android chat history preparation during streaming

1 participant