Skip to content

refactor(worker): unify inference payload handling - #139245

Merged
steipete merged 1 commit into
mainfrom
codex/deslop-worker-inference
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/deslop-worker-inference

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Maintainer-requested maintenance of worker inference streaming. Stream events and terminal results share one operation sequence, but keeping their admission and callback-failure behavior aligned required maintaining duplicate paths.

Why This Change Was Made

Use one operation-owned handler for identity checks, sequence admission, gap notification, event delivery and terminal settlement. Reuse the existing error normalizer and remove the four duplicated private methods. Frame validation, replay reset and connection lifecycle retain their existing owners.

User Impact

No user-visible behavior change. Reconnect/replay, callback rejection and terminal results preserve their existing behavior. Production is +24/−54, net −30 lines; tests are unchanged.

Evidence

Head: cdce21b73a239ca6b99a983fee13001f6e02c0a1, based on bdd75d44c56154a24123be1a4218647b5f6712f3. The committed patch matches the tested and reviewed source. The separate final-head review is clean and exact-head CI passed. The first completed ClawSweeper review covers this exact head and reports no correctness or security findings, Before merge: None, and no outstanding Rank-up or checklist items. Its full report has been reviewed.

  • The three focused suites passed before and after: 48 tests per run, comprising 47 existing tests plus one temporary 22-scenario characterization. Every byte of the ordered traces matched, including gaps, duplicates, identity mismatches, callback failures and replay ordering. The temporary test was removed and the original test bytes restored.
  • The full classified core/coreTests gate passed all 28 actual check phases, including typechecks, formatting, lint and all selected guards. Managed P2, independent peer and final committed-head reviews are clean.
  • The classified plan did not require a full build. Validation used synthetic worker inputs; no live-provider run was performed.

CI actually tested merge a403932e15be57a3986645e8442ce774dc3f40a5, with verified ordered parents main 886aaa689076b7b7c2f7a4d8d0048e89f5855698 and this exact PR head. That main snapshot has no overlapping change in the worker neighborhood, inference producer/schema, shared error normalizer or dependency pins since the candidate base.

OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs src/worker/worker-rpc-clients.test.ts src/worker/inference-stream.runtime.test.ts src/worker/worker-connection.test.ts
OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/check-changed.mjs -- src/worker/worker-rpc-inference-client.ts

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review September 5, 2026 17:29
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 1:47 PM ET / 17:47 UTC.

ClawSweeper review

What this changes

Unifies worker model-stream events and final results under one handler and reuses the existing error normalizer without changing observable behavior.

Merge readiness

✅ Ready for maintainer review

Keep open as useful maintenance work. No blocking correctness findings: the refactor preserves sequencing, callback rejection, and terminal settlement, and remains absent from current main.

Priority: P3
Reviewed head: cdce21b73a239ca6b99a983fee13001f6e02c0a1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with equivalent error handling, preserved lifecycle semantics, relevant existing coverage, and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-owned, behavior-preserving refactor is exempt from contributor live-proof requirements; its reported synthetic characterization exercises the changed inference handler, but is not claimed as live-provider proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-owned, behavior-preserving refactor is exempt from contributor live-proof requirements; its reported synthetic characterization exercises the changed inference handler, but is not claimed as live-provider proof.
Evidence reviewed 11 items Verified introduced change: The pinned merge-base-to-head diff only consolidates inference handling and replaces equivalent error conversion. Identity checks, replay reset, cancellation, and disposal remain intact.
Verified merge-result scope: Raw test-merge parents are the pinned base followed by the exact PR head. Comparing that merge with its base changes only the inference client; unrelated endpoint drift is not attributable to this PR.
Payload discrimination and validation: Event payloads require event; terminal payloads require outcome. Both use closed schemas. WorkerConnectionFrameDispatcher validates these frames and connection identity before notifying listeners, supporting the unified handler’s event-property discrimination.
Findings None None.
Security None None.

How this fits together

Cloud workers request model inference through the Gateway. This client orders incoming stream updates and final results before passing them to the worker’s agent loop.

flowchart LR
  A[Worker agent loop] --> B[Inference request]
  B --> C[Gateway inference service]
  C --> D[Validated stream frames]
  D --> E[Identity and sequence checks]
  E --> F[Stream updates]
  E --> G[Final result or error]
  F --> A
  G --> A
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -30. Total -30 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 24 54 -30
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 24 54 -30

Review metrics

Metric Value Why it matters
Production versus tests Production net −30 lines; tests unchanged The reduction removes duplicate operation policy without moving code into test support or adding a parallel abstraction.

Technical review

Best possible solution:

Keep sequence admission and settlement with the inference operation owner, preserving transport validation and replay reset at their existing boundaries.

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

Not applicable: this PR claims behavior-preserving cleanup rather than a bug fix; source comparison and existing coverage support that premise.

Is this the best way to solve the issue?

Yes. Consolidating the two paths inside their existing operation owner removes duplicated policy without moving operation state into the transport dispatcher or changing sibling clients.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3e4becea5e2c.

Labels

Label changes:

  • add P3: This is bounded maintenance with preserved runtime behavior and no reported user-facing failure.
  • 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: This maintainer-owned, behavior-preserving refactor is exempt from contributor live-proof requirements; its reported synthetic characterization exercises the changed inference handler, but is not claimed as live-provider proof.

Label justifications:

  • P3: This is bounded maintenance with preserved runtime behavior and no reported user-facing failure.
  • 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: This maintainer-owned, behavior-preserving refactor is exempt from contributor live-proof requirements; its reported synthetic characterization exercises the changed inference handler, but is not claimed as live-provider proof.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff only consolidates inference handling and replaces equivalent error conversion. Identity checks, replay reset, cancellation, and disposal remain intact. (src/worker/worker-rpc-inference-client.ts:171, cdce21b73a23)
  • Verified merge-result scope: Raw test-merge parents are the pinned base followed by the exact PR head. Comparing that merge with its base changes only the inference client; unrelated endpoint drift is not attributable to this PR. (src/worker/worker-rpc-inference-client.ts, a403932e15be)
  • Payload discrimination and validation: Event payloads require event; terminal payloads require outcome. Both use closed schemas. WorkerConnectionFrameDispatcher validates these frames and connection identity before notifying listeners, supporting the unified handler’s event-property discrimination. (packages/gateway-protocol/src/schema/worker-inference.ts:339, cdce21b73a23)
  • Exact error-conversion equivalence: toStringifiedError preserves Error instances and otherwise constructs new Error(String(value)), exactly matching the removed expressions. This is an existing repository-owned package export. (packages/normalization-core/src/error-coercion.ts:192, cdce21b73a23)
  • Producer and consumer invariant: The Gateway producer advances one sequence for events and terminal frames; durable replay emits terminal sequence 1. The client retains synchronous replay-cursor reset, and the stream adapter receives gap notification before processing later events. (src/gateway/worker-environments/inference.ts:264, cdce21b73a23)
  • Runtime boundary and sibling paths: The stream adapter calls the inference client and converts completion or rejection into agent-stream outcomes. Worker runtime owns client creation and disposal; transcript and live-event clients retain separate sequencing contracts. The changed contract is OpenClaw’s worker protocol, with no affirmative dependency on Codex runtime or protocol behavior. (src/worker/inference-stream.runtime.ts:353, cdce21b73a23)

Likely related people:

  • Peter Steinberger: 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 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

The final one-file refactor is ready to land at cdce21b73a239ca6b99a983fee13001f6e02c0a1. Inference events and terminal results now share the same operation-owned identity, sequence and callback-failure handling. Transport validation, synchronous replay reset, connection fencing and sibling clients retain their existing responsibilities. Production decreases by 30 lines; tests are unchanged.

All 47 existing tests in the three selected suites passed before and after, alongside one temporary characterization covering 22 ordered scenarios with byte-identical traces. The full classified gate, managed P2, peer and separate exact-head review passed. Exact-head CI is green, with its actual tested merge and both parents verified. No live-provider run or full build is claimed.

I read the completed ClawSweeper review at this exact head. It has no findings, security concerns, Before merge items or outstanding Rank-up moves. Proceeding through native prepare/merge under the requested codebase cleanup.

@steipete
steipete merged commit f7aa916 into main Sep 5, 2026
255 of 256 checks passed
@steipete
steipete deleted the codex/deslop-worker-inference branch September 5, 2026 18:08
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 5, 2026
* commit '911d7d5b0c107f7274f2415ca9655dcc6105f0e8': (867 commits)
  fix(skills): deliver pending Workshop approval controls (#139248)
  fix(gateway): deliver loopback ask_user prompts to the originating channel (#138831)
  docs: keep root agent instructions focused on repository policy (#139258)
  fix(matrix): exclude archived state roots from scans and selection (#112329)
  perf(agents): prepare exact tool names once per catalog batch (#139267)
  fix: preserve Swarm progress and simplify owner plumbing (#139269)
  fix(tailscale): release claims after gateway process-group exit (#139261)
  refactor(cli): simplify lazy command registration (#139108)
  test(ui): retain synthetic widget failure evidence (#139229)
  fix(buzz): keep implicit replies at thread root (#138879)
  test(diagnostics): await graceful Gateway shutdown before cleanup (#139247)
  fix(ci): unblock releases with different tooling package managers (#139259)
  feat(ui): add social preview links for private sessions (#139250)
  fix(codex): retain failed conversations for guarded continuation (#139246)
  chore(ui): refresh control ui locales (#139200)
  fix(ci): run browser checks for real-gateway inputs (#139256)
  fix(llama-cpp): reconcile managed router state before requests (#136363)
  chore(i18n): refresh native locales (#139237)
  refactor(worker): unify inference payload handling (#139245)
  refactor(terminal): replay wrapped prefixes in one pass (#139240)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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