Skip to content

fix(worker): avoid repeatedly serializing screenshot history - #146907

Merged
vincentkoc merged 1 commit into
mainfrom
perf/worker-replay-sizing-20260913
Sep 13, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/worker-replay-sizing-20260913

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Cloud worker turns repeatedly serialize unchanged screenshot history while pruning an oversized inference request. Each removed image previously triggered another full request encoding before inference could start.

Why This Change Was Made

Keep the existing full-frame measurement for requests that already fit. Once pruning starts, cache each unchanged message's encoded byte length for that synchronous request and combine those lengths with the exact envelope and array separators. The fitter replaces changed message objects, so later measurements only re-encode those replacements.

Pruning rules, original transcript history, protected images and the final transport payload check remain unchanged. Production grows by 28 lines to own exact request-local measurement; regression tests add 143 lines.

User Impact

Screenshot-heavy requests need less serialization work when historical images must be removed to fit the payload budget. Requests that fit retain their single full-frame measurement. No configuration, protocol or storage change is required. No measured Team latency or memory improvement is claimed.

Evidence

  • The actual private helper matched the full encoder across 872 direct candidate comparisons covering UTF-8, escaping, repeated replacements and payload boundaries.
  • The adapter regression compares the fitted request with the canonical fitter, checks the 25 MiB boundary at minus one, exact and plus one byte, preserves original messages, and measures encoded work on fitting and oversized histories.
  • Independent source reviews through P2 found no actionable issue. Targeted formatting and whitespace checks passed.
  • Signed head d1e22c62be8cf24d89b1e98312a4f05ecb0d6a24 preserves tested production from 07db30618c230e81332a36cbb625380e69e5ae0e / tree e4f9cba446776482074c87a62cc9444783e02958. Later fixture corrections use satisfies while constructing a mutable request and add braces to two existing statements; runtime behavior and assertions are unchanged.
  • Native Node 24.19.0 validation passed all 12 tests on the captured tree. Original production passed the fitting control and failed only the oversized work bound after request equality, payload size and original-message assertions passed: 209,737,348 serialized bytes against a 117,448,972-byte upper bound. The candidate passed that bound and every functional case. Source restoration and clean-tree checks passed. Test runner.
  • Fresh hosted CI and native preparation remain pending.

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

clawsweeper Bot commented Sep 13, 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 13, 2026 09:25
@vincentkoc
vincentkoc force-pushed the perf/worker-replay-sizing-20260913 branch from 180886a to 562f80a Compare September 13, 2026 09:33
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 7:20 AM ET / 11:20 UTC (Revision 2).

ClawSweeper review

What this changes

Caches unchanged messages’ encoded sizes while trimming oversized worker inference requests, reducing repeated screenshot serialization and adding regression coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from current main and v2026.9.4. No actionable correctness or security findings were found; the maintainer-authored PR should remain open for normal merge handling.

Priority: P2
Reviewed head: d1e22c62be8cf24d89b1e98312a4f05ecb0d6a24

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful boundary and work-budget regressions, no actionable findings, and appropriately limited performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate and changes no authority boundary; supplied adapter tests exercise sizing with mocked inference start and do not establish live latency or memory improvement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate and changes no authority boundary; supplied adapter tests exercise sizing with mocked inference start and do not establish live latency or memory improvement.
Evidence reviewed 9 items Request-local cache and exact byte accounting: The helper measures the empty-message envelope, adds array commas and independently encoded message sizes, and caches only during synchronous fitting of a cloned request.
Fitter preserves cache validity: Each image replacement creates a new message object; unchanged messages retain their identities. Protected images and opaque provider replay retain their existing rules.
Final transport guard remains authoritative: The dispatcher creates UUID request IDs and checks the actual encoded frame against the payload limit before sending; this guard is unchanged.
Findings None None.
Security None None.

How this fits together

Cloud workers send conversation context through the Gateway for model inference. The worker stream adapter trims eligible historical images to fit the transport budget while preserving the original transcript.

flowchart TD
  A[Worker conversation context] --> B[Clone inference request]
  B --> C[Measure full request]
  C --> D{Fits transport budget?}
  D -->|Yes| F[Gateway inference request]
  D -->|No| E[Prune eligible images and reuse message sizes]
  E --> D
  E --> G[Report error if protected context cannot fit]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +28, Tests +143. Total +171 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 39 11 +28
Tests 1 143 0 +143
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 182 11 +171

Review metrics

Metric Value Why it matters
Sizing regression boundaries 3 payload boundaries and 2 workload cases Coverage checks exact fitting decisions alongside unchanged fitting-request work and reduced oversized-request serialization.

Technical review

Best possible solution:

Keep exact sizing within the existing adapter, with request-local caching and unchanged image-retention and final transport checks.

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

Yes, from source: current main serializes the entire inference frame after every eligible image removal. The adapter regression targets that repeated work; it was inspected but not executed here.

Is this the best way to solve the issue?

Yes. The cache follows the fitter’s message-replacement contract and preserves exact frame sizing without changing pruning policy, protocol, or stored data.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement for screenshot-heavy worker inference, without evidence of an urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 MEMBER-authored PR is exempt from the external-contributor proof gate and changes no authority boundary; supplied adapter tests exercise sizing with mocked inference start and do not establish live latency or memory improvement.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vyctor H. Brzezowski: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T09:50:29.021Z sha 562f80a :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf/worker-replay-sizing-20260913 branch from 562f80a to d1e22c6 Compare September 13, 2026 11:10
@vincentkoc
vincentkoc merged commit d36f184 into main Sep 13, 2026
186 checks passed
@vincentkoc
vincentkoc deleted the perf/worker-replay-sizing-20260913 branch September 13, 2026 11:24
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit to zachisfine/openclaw that referenced this pull request Sep 13, 2026
* temp/pr-146799: (70 commits)
  test: reuse explicit fallback config fixtures (openclaw#146948)
  fix(computer): return fresh window observations after actions (openclaw#146822)
  refactor(feishu): remove unreachable requester topic selection (openclaw#146904)
  improve(gateway): reduce CPU spent listing agent-owned sessions (openclaw#137745)
  fix(ui): avoid recapturing chat drafts during UI updates (openclaw#146884)
  fix(ui): show system uptime in the debug overlay (openclaw#146960)
  fix(retry): honor waits beyond the native timer limit (openclaw#145718)
  fix(ui): keep chat history idle when run status changes (openclaw#146802)
  fix(ui): reuse persisted text during chat streaming (openclaw#146831)
  refactor(qa): share harness drift result construction (openclaw#146903)
  test(agents): coordinate settings lock contention (openclaw#146949)
  fix(worker): avoid repeatedly serializing screenshot history (openclaw#146907)
  fix(secrets): stop buffered upload writes after cancellation (openclaw#146840)
  perf(doctor): avoid unnecessary state runtime imports (openclaw#146926)
  improve: reduce compaction request estimation work (openclaw#146961)
  fix(ci): wait for forwarded avatar imports before assertions (openclaw#146729)
  perf(workers): skip configured Git author lookups (openclaw#146833)
  fix: admit borrowed memory writes through the agent database owner (openclaw#146760)
  fix(discord): prevent voice playback gaps and stale turn controls (openclaw#146798)
  improve: reduce worktree filesystem stalls and archive syncs (openclaw#146906)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit 'ccfd2377cd07d1ad3a583ba64d08e29a065f7061': (1587 commits)
  fix(ui): avoid recapturing chat drafts during UI updates (#146884)
  fix(ui): show system uptime in the debug overlay (#146960)
  fix(retry): honor waits beyond the native timer limit (#145718)
  fix(ui): keep chat history idle when run status changes (#146802)
  fix(ui): reuse persisted text during chat streaming (#146831)
  refactor(qa): share harness drift result construction (#146903)
  test(agents): coordinate settings lock contention (#146949)
  fix(worker): avoid repeatedly serializing screenshot history (#146907)
  fix(secrets): stop buffered upload writes after cancellation (#146840)
  perf(doctor): avoid unnecessary state runtime imports (#146926)
  improve: reduce compaction request estimation work (#146961)
  fix(ci): wait for forwarded avatar imports before assertions (#146729)
  perf(workers): skip configured Git author lookups (#146833)
  fix: admit borrowed memory writes through the agent database owner (#146760)
  fix(discord): prevent voice playback gaps and stale turn controls (#146798)
  improve: reduce worktree filesystem stalls and archive syncs (#146906)
  fix(ui): avoid extra chat rail work while replies stream (#146883)
  improve(ui): speed up populated Usage timelines (#146947)
  test(gateway): retain auth recovery failure diagnostics (#146925)
  fix(tests): create private temporary home directories (#146931)
  ...

# Conflicts:
#	test/tsconfig/tsconfig.core.test.agents-other.json
#	test/tsconfig/tsconfig.core.test.agents-root.json
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant