Skip to content

fix(clawrouter): sanitize attribution headers to ByteString#106454

Merged
steipete merged 2 commits into
openclaw:mainfrom
ZOOWH:codex/clawrouter-attribution-bytestring
Jul 18, 2026
Merged

fix(clawrouter): sanitize attribution headers to ByteString#106454
steipete merged 2 commits into
openclaw:mainfrom
ZOOWH:codex/clawrouter-attribution-bytestring

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

ClawRouter automatic agent/session attribution can contain emoji, CJK characters, or other non-ByteString values. Node/Undici converts Headers values to ByteString, so those IDs throw before the model request is sent.

Why This Change Was Made

One local policy-driven sanitizer now serves automatic agent, session, and request IDs. Ordinary safe values pass unchanged. Unsafe, encoded-looking, or oversized values become readable printable-ASCII prefixes plus a bounded SHA-256 suffix; request IDs retain their model-call suffix. Hashing uses the original UTF-16 code units so lone surrogates remain distinct. Control-character rejection and explicit operator headers remain unchanged.

This replaces the PR's initial duplicate attribution sanitizer with the existing request-ID strategy generalized behind one path, then closes encoded-namespace and lone-surrogate collision cases found during maintainer review.

User Impact

Before: Unicode automatic attribution could crash request construction with a ByteString TypeError.

After: Automatic IDs are bounded, printable ASCII, collision-resistant after rewriting, and accepted by Headers.

Evidence

Head: c67249675d9a64cd0d4551189c883ac978850fbb

$ node scripts/run-vitest.mjs extensions/clawrouter/index.test.ts
Test Files  1 passed (1)
Tests      13 passed (13)

$ node scripts/check-changed.mjs -- extensions/clawrouter/stream.ts extensions/clawrouter/index.test.ts
Blacksmith Testbox: passed
https://github.com/openclaw/openclaw/actions/runs/29624226948

Live production-wrapper proof on Node v26.5.0 with bundled Undici 8.7.0 constructed Headers for distinct Unicode agent/session pairs and a Unicode request ID. Rewritten agent/session values remained distinct; the request model suffix remained intact. Regression coverage also proves encoded-looking literal IDs and distinct lone surrogates do not alias generated values.

  • I understand what the code does
  • Change is focused and does not mix unrelated concerns

Real behavior proof

Behavior addressed: ClawRouter automatic attribution and request identifiers are sanitized before Node constructs transport headers.

Environment tested: macOS, Node v26.5.0, bundled Undici 8.7.0, production wrapClawRouterProviderStream imported from source.

Observed result: Unicode agent/session pairs produced distinct printable-ASCII headers; Unicode request ID remained bounded with :model:3; new Headers(...) succeeded for every captured request.

Not tested: Live ClawRouter server-side display. Explicit operator-supplied headers remain untouched by design.

@openclaw-barnacle openclaw-barnacle Bot added extensions: clawrouter Extension: clawrouter size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 13, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 13, 2026
@clawsweeper

clawsweeper Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 9:07 PM ET / July 18, 2026, 01:07 UTC.

Summary
The branch centralizes bounded printable-ASCII sanitization for ClawRouter automatic agent, session, and request attribution headers, with regression coverage for Unicode, collisions, length bounds, and Headers construction.

PR surface: Source +28, Tests +79. Total +107 across 2 files.

Reproducibility: yes. from source and the supplied regression test: pass Unicode automatic agent/session/request identifiers through the ClawRouter stream wrapper and construct transport headers. A fresh exact-head live run has not been attached to the PR body.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add a redacted exact-head terminal transcript or copied live output showing two distinct Unicode attribution pairs and successful Headers construction.
  • Update the PR body after posting the proof; if a fresh review does not appear, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR describes a credible live production-wrapper result, but it names fc2b8568 rather than current head c6724967, whose collision-resistance behavior changed; attach redacted exact-head terminal or live output before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The cited live production-wrapper result covers fc2b8568, not current head c6724967, whose collision-resistance change affects the observable header values.

Maintainer options:

  1. Decide the mitigation before merge
    Attach a redacted exact-head production-wrapper transcript showing distinct Unicode agent/session headers, preserved request-ID model suffixes, and successful Headers construction; then review the assigned maintainer’s merge judgment.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] The remaining merge gate is contributor-provided exact-head behavior proof, followed by the assigned reviewer’s normal judgment; no mechanical repair is indicated.

Security
Cleared: The two-file TypeScript change adds no dependency, workflow, permission, credential, artifact-download, or package-resolution surface.

Review details

Best possible solution:

Attach a redacted exact-head production-wrapper transcript showing distinct Unicode agent/session headers, preserved request-ID model suffixes, and successful Headers construction; then review the assigned maintainer’s merge judgment.

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

Yes, from source and the supplied regression test: pass Unicode automatic agent/session/request identifiers through the ClawRouter stream wrapper and construct transport headers. A fresh exact-head live run has not been attached to the PR body.

Is this the best way to solve the issue?

Yes, provisionally: one shared bounded-ID policy avoids duplicate sanitizers while preserving request-ID model suffixes and collision resistance. Exact-head runtime proof is still needed to confirm the proposed behavior.

AGENTS.md: unclear because the file could not be read completely.

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

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: Unicode automatic attribution can prevent ClawRouter model requests from being constructed for affected users.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR describes a credible live production-wrapper result, but it names fc2b8568 rather than current head c6724967, whose collision-resistance behavior changed; attach redacted exact-head terminal or live output before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +28, Tests +79. Total +107 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 56 28 +28
Tests 1 79 0 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 135 28 +107

What I checked:

  • Current-head proof gap: The PR body identifies live production-wrapper evidence for fc2b8568, while the current head is c6724967; the latter commit is specifically titled “keep sanitized ids collision-resistant,” so the supplied runtime result does not prove the exact current behavior. (extensions/clawrouter/stream.ts, c67249675d9a)
  • Focused regression coverage: The supplied diff adds assertions that Unicode agent/session attribution is rewritten to printable ASCII, remains distinct across similar inputs, and can be accepted by new Headers(...); request IDs retain their model-call suffix. (extensions/clawrouter/index.test.ts, c67249675d9a)
  • Feature provenance: The merged ClawRouter feature PR is the adjacent origin for this runtime path; its merge commit provides the relevant feature-history anchor rather than a duplicate implementation of this fix. (extensions/clawrouter/stream.ts, 4a354f76c1bf)
  • Maintainer engagement: The timeline shows steipete assigned the PR on July 17, 2026 and force-pushed the current head on July 18, 2026, so stale-PR cleanup reasons do not apply. (c67249675d9a)

Likely related people:

  • steipete: Authored the merged ClawRouter feature and both commits on the current PR head, and is assigned to this review. (role: feature owner and recent area contributor; confidence: high; commits: 4a354f76c1bf, be2e91ab2fe4, c67249675d9a; files: extensions/clawrouter/stream.ts, extensions/clawrouter/index.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • 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.
Review history (6 earlier review cycles)
  • reviewed 2026-07-13T15:37:33.573Z sha 38e49c1 :: needs real behavior proof before merge. :: [P1] Preserve distinct attribution IDs after sanitization
  • reviewed 2026-07-13T16:31:37.399Z sha 133b6c1 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-13T17:00:53.825Z sha 133b6c1 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-13T17:20:41.838Z sha 133b6c1 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T00:28:06.330Z sha fc2b856 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T00:46:09.829Z sha ec0b35f :: needs real behavior proof before merge. :: none

@ZOOWH

ZOOWH commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 13, 2026
@ZOOWH

ZOOWH commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 13, 2026
@steipete steipete self-assigned this Jul 17, 2026
@steipete
steipete force-pushed the codex/clawrouter-attribution-bytestring branch 2 times, most recently from fc2b856 to ec0b35f Compare July 18, 2026 00:43
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 18, 2026
@steipete
steipete force-pushed the codex/clawrouter-attribution-bytestring branch from ec0b35f to c672496 Compare July 18, 2026 01:04
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 18, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer review complete. Thanks @ZOOWH for the report and initial fix.

Head reviewed: c67249675d9a64cd0d4551189c883ac978850fbb

I rewrote the patch around one local policy-driven bounded-ID sanitizer shared by automatic attribution and request IDs. The final path keeps ordinary safe IDs unchanged, preserves request model-call suffixes, reserves generated suffix forms, and hashes original UTF-16 code units so encoded-looking literals and lone surrogates cannot deterministically alias rewritten attribution.

Proof:

No config, UI, capability, docs, or public API change.

@steipete
steipete merged commit 1c331b9 into openclaw:main Jul 18, 2026
98 of 100 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…#106454)

* fix(clawrouter): sanitize bounded header ids

Co-authored-by: ZOOWH <[email protected]>

* fix(clawrouter): keep sanitized ids collision-resistant

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: clawrouter Extension: clawrouter P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants