Skip to content

fix(gateway): avoid loading inactive worker history - #145591

Merged
steipete merged 1 commit into
mainfrom
codex/worker-model-context-preparation-20260912
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/worker-model-context-preparation-20260912

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes unnecessary Gateway memory use when cloud-worker turns begin in sessions with inactive transcript branches. Preparing a small active conversation loaded and retained the physical transcript's inactive message payloads while credentials, workspace media, and skills were prepared.

Why This Change Was Made

Use the existing selected model-context readers for recorder-owned or already-persisted input. A pending recorder keeps the synchronous read-before-persist ordering, so its own append cannot invalidate an asynchronous snapshot. Already-persisted input uses the asynchronous reader and revalidates the caller, cancellation, exact placement claim, and current transcript identity after the read.

Unrecorded input keeps its writable SessionManager, preserving captured append ancestry, conflict handling, and writer custody. The completion reader and recorder-race fallback remain unchanged. No schema, retention, or transcript-commit recovery contract changes.

User Impact

Worker turns stop retaining inactive message payloads during this preparation phase while keeping the same active history and current-input/base-leaf behavior. This is a bounded allocation repair, not a claim that all Gateway memory pressure or stalls are resolved.

Evidence

Both permanent 64-row tests fail on the unmodified producer because it hydrates 64 inactive 1 KiB messages, then pass with zero inactive payloads. The active conversation remains four messages for already-persisted input or three before recorder-owned persistence. The earlier 512-row diagnostic measured roughly 614 KB of serialized loaded payload versus under 600 bytes for the selected reader; that is a payload proxy, not a retained-heap or RSS measurement.

All 10 focused tests pass on the current candidate. They cover input/history/base-leaf parity, split logical/append leaves, canonical persistence already in flight or begun after snapshot acquisition, and cancellation, claim loss, caller revocation, and session rebinding during the asynchronous read. Existing launcher/media/handoff and SessionManager owner suites previously passed 124 tests on the integration base.

Independent P0-P2 review is clean. The revised Blacksmith wire proof passed two authenticated chat turns, history-prefix/input/base-leaf checks, completed supervisor receipts, and joined cleanup; the owned lease is completed. The native synced proof verified both producer hashes, the harness, tests, and lockfile before its build (Node 24.19.0). Its delegated checkout metadata follows the hydrated main; exact-head CI is tracked separately on this PR.

The campaign wire harness remains private rather than duplicating the maintained service suite. It uses a loopback mock provider and a separate authenticated operator.read/operator.write client; it does not establish real-provider behavior or multi-profile membership semantics. The final native changed checks passed, including typechecking, lint, dead-code and repository guards.

Exact-head CI passed after one qualified rerun of the unchanged QA gallery shard. A temporary path containing gif deterministically reproduces its log-as-image classification failure; the original CI failure is retained and the unrelated gallery repair is tracked separately.

@clawsweeper

clawsweeper Bot commented Sep 12, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 04:20
@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 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 12:27 AM ET / 04:27 UTC.

ClawSweeper review

What this changes

Worker-turn preparation uses existing selected-history readers to avoid retaining inactive transcript payloads, with regression coverage for input ordering, branch ancestry, and cancellation.

Merge readiness

✅ Ready for maintainer review

The allocation repair remains useful: both inspected main and the latest release still load the full transcript during worker preparation. No blocking defect was found in the introduced changes, and the maintainer-authored PR is protected from cleanup.

Priority: P2
Reviewed head: 8bc13c1cc1a859f677fb9cf0e483439c347abe07

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair using established readers, with meaningful regression coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Reported authenticated worker turns support history parity, while inspected tests cover payload selection and invalidation; the private wire trace was not independently inspected.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Reported authenticated worker turns support history parity, while inspected tests cover payload selection and invalidation; the private wire trace was not independently inspected.
Evidence reviewed 8 items Current main still has the allocation problem: The inspected main revision calls SessionManager.open before building history and awaiting credentials; the full reader loads the physical transcript snapshot.
Latest-release comparison: The supplied latest release, v2026.9.4, also uses the full reader at this preparation step; this repair is not already present there.
Reader selection and post-read checks: Already-persisted input uses the asynchronous selected reader; a pending recorder keeps synchronous ordering; unrecorded input retains its writable manager. The new await is followed by caller, cancellation, exact claim, and transcript-identity checks.
Findings None None.
Security None None.

How this fits together

The Gateway prepares conversation history and the current input before launching an OpenClaw worker. Its transcript reader supplies the history and base leaf used to assemble the worker request while durable transcripts remain Gateway-owned.

flowchart TD
  A[Admitted worker turn] --> B{Input persistence state}
  C[Gateway transcript] --> D[Selected history reader]
  B -->|Already persisted| D
  B -->|Recorder pending| D
  B -->|Unrecorded input| E[Writable transcript reader]
  D --> F[Validate current turn after async read]
  E --> G[Prepare history and base leaf]
  F --> G
  G --> H[Launch worker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +644. Total +664 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 22 2 +20
Tests 2 644 0 +644
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 666 2 +664

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +20 lines; tests +644 lines The small production increase reuses existing readers and adds post-await validation; most growth exercises allocation and ordering invariants.

Technical review

Best possible solution:

Keep transcript selection with the existing reader owner while preserving canonical input persistence, exact branch ancestry, and live admission checks.

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

Yes, from source: prepare a worker turn on a short selected branch with substantial inactive history; current main opens the full transcript before credential preparation. This review did not execute that scenario.

Is this the best way to solve the issue?

Yes. Reusing the selected-context readers fixes allocation at its producer without changing storage, while retaining the writable path where append custody is required.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded memory-allocation repair for worker sessions with inactive transcript branches, without evidence of an urgent runtime outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Reported authenticated worker turns support history parity, while inspected tests cover payload selection and invalidation; the private wire trace was not independently inspected.

Label justifications:

  • P2: This is a bounded memory-allocation repair for worker sessions with inactive transcript branches, without evidence of an urgent runtime 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 supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Reported authenticated worker turns support history parity, while inspected tests cover payload selection and invalidation; the private wire trace was not independently inspected.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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.

@steipete
steipete merged commit aa7eabb into main Sep 12, 2026
393 of 395 checks passed
@steipete
steipete deleted the codex/worker-model-context-preparation-20260912 branch September 12, 2026 04:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 12, 2026
Classify recognized file suffixes before free-form artifact kind hints so
metadata cannot turn logs or JSON into media without previews. Preserve the
complete kind label and existing fallback for unknown or extensionless files.

Make the path-redaction regression deterministic and cover conflicting media
hints, existing fallback behavior, and the real HTTP gallery response.

Related: #145591
steipete added a commit that referenced this pull request Sep 12, 2026
Classify recognized file suffixes before free-form artifact kind hints so
metadata cannot turn logs or JSON into media without previews. Preserve the
complete kind label and existing fallback for unknown or extensionless files.

Make the path-redaction regression deterministic and cover conflicting media
hints, existing fallback behavior, and the real HTTP gallery response.

Related: #145591
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
Classify recognized file suffixes before free-form artifact kind hints so
metadata cannot turn logs or JSON into media without previews. Preserve the
complete kind label and existing fallback for unknown or extensionless files.

Make the path-redaction regression deterministic and cover conflicting media
hints, existing fallback behavior, and the real HTTP gallery response.

Related: openclaw#145591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: 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.

1 participant