Skip to content

fix(knowledge): keep source page reads whole at surrogate boundaries - #193433

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/knowledge-source-page-surrogate-safe-311
Nov 5, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/knowledge-source-page-surrogate-safe-311

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Ontology source pagination uses bare UTF-16 slices. When an emoji crosses a page boundary, one page ends with its high surrogate and the next starts with its low surrogate. JSON can retain the separate halves, but consumers encoding each page to UTF-8 get replacement characters instead of the authored source. The returned first continuation is also inside the character.

Fix

Preserve @SunnyShu0925's fix: route the authorized source read through the existing textWindow owner, just like other bounded text surfaces. Return that owner's text and nextOffset. SourcePath authorization, source inventory, totalChars, schema, and budgets are unchanged; explicit offsets inside a pair receive the existing refusal. No new validation owner, schema, configuration, auth, retry guidance, or model-facing text.

Consolidate the existing source-view regression's repeated options while retaining per-page UTF-8 round-trip, exact full concatenation, misaligned-offset refusal, source authorization, and diagnostics assertions. Clarify the existing source-offset documentation.

Evidence

Built Linux Gateway proof and focused checks: secretless node:24.22.1, main twice/candidate twice, independently built runtimes and shipped openclaw.mjs entry point. Normal plugins.sessionAction pagination returns six pages and terminates in every run. Main: first nextOffset 256, two split-character pages, UTF-8-per-page concatenation corrupts the source. Candidate: first nextOffset 255, zero split-character pages, lossless concatenation. Misaligned offset refused; authorized inventory, totals, default/full read, maxChars=512, unauthorized path and invalid-budget controls are exactly unchanged across all four runs.

Real owner chat/tool execution provisions the store via a faithful local OpenAI-compatible fixture; all source inspection goes through the built Gateway. Separate task-owned profiles/config/state/DB/workspaces/ports, verified resolved paths. No live credentials, no fault injection, no model-quality claim.

21 focused tests, typed lint, focused test typecheck and formatter passed. Final regression copied to frozen main fails exactly the per-page UTF-8 assertion; seven other tests pass.

Whole-PR deltas: production +8/-4 (12 gross, net +4); tests +5/-10 (net -5); docs +5/-3. No allocation file or shared ceiling change. The existing shared window owner eliminates the last bare source-page slice; no new machinery.

Merge risk

Low: only selected source text windows change at surrogate boundaries. ASCII/full-window controls and source authorization remain unchanged. Reverting restores split pages, not a data migration: no stored source bytes, registry state, schema, auth, inventory, or protocol is modified. No downgrade or recovery action is required.

Ref: BUG-311-knowledge-ontology-source-page-splits-surrogate-pair (local finding)
@clawsweeper

clawsweeper Bot commented Nov 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR routes Knowledge ontology source pagination through the existing Unicode-safe text-window helper.

Example: Read ontology.yaml with maxChars=256 when 😀 spans UTF-16 offsets 255–256.

  • Before: The first continuation is 256, splitting the emoji and corrupting independently UTF-8-encoded pages.
  • After: The first continuation is 255, preserving the emoji and lossless page concatenation.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with shipped-entry-point before/after evidence, a meaningful regression, and no open findings; broad CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied Linux Docker trace exercises the built Gateway's plugins.sessionAction ontology source reads twice before and twice after the fix: six-page traversal terminates, split pairs disappear, UTF-8 reconstruction becomes exact, and authorization controls remain unchanged; the final head preserves those production bytes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An emoji crossing a source-page boundary becomes replacement characters when consumers encode pages separately to UTF-8.
Reason: Lossless source reads are an existing contract, and the repair reuses established machinery without adding configuration or persistence.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current-main Unicode pagination defect with a small, coherent change; no actionable findings remain, and CI is still pending.

Priority: P2
Reviewed head: e9c6cbfff00b517009a3ffedd35f9912f240eef8

Before merge

None.

Findings

None.

Agent review details

How this fits together

Knowledge's authorized ontology inspection receives a source path and pagination limits, reads the enumerated source, and returns bounded text with its continuation offset.

flowchart LR
  A[Gateway session action] --> B[Knowledge service]
  B --> C[Authorized storage operation]
  C --> D[Ontology inspection]
  D --> E[Shared text window]
  E --> F[Source text and continuation]
Loading

Technical review

Best possible solution:

Use the existing textWindow owner for source text and continuation offsets, as this PR does.

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

Current-main source deterministically splits an emoji crossing the requested boundary, and the supplied built-Gateway before/after trace confirms the failure and repair; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: reuse the existing Unicode-safe window and its continuation, retaining source authorization and extending the existing integration regression.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Ontology source inspection and continuation keeps the original intent (65ad180: The bundling PR retains bounded, authorized source inspection, including malformed manifests; no stated intent requires splitting Unicode characters.)
  • Source-view regression and documentation keeps the original intent (65ad180: The original regression protects exhaustive reads, path refusal, and diagnostics; the changed fixture retains these contracts and adds independent encoding checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit 65ad180 adds extensions/knowledge/src/text-window.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 65ad18005286; files: extensions/knowledge/src/text-window.ts)
  • Peter Lee: Raw commit 2724b2c adds extensions/knowledge/src/inspection.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 2724b2c33bf7; files: extensions/knowledge/src/inspection.ts)

PR surface

Source +4, Tests -5, Docs +2. Total +1 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 4 +4
Tests 1 5 10 -5
Docs 1 5 3 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 18 17 +1

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +8/-4; tests +5/-10 Small production growth delegates pagination to the existing owner; the regression extends an existing fixture while removing repeated options.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A concrete Unicode corruption bug affects bounded Knowledge source reads with limited blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-05T11:35:37.254Z sha 7f28fe3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-05T13:41:47.104Z sha 7f28fe3 :: needs maintainer review before merge. :: none

Reviewed November 5, 2026, 9:28 AM ET / 14:28 UTC (Revision 3).

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Built Linux Gateway before/after proof

Preserved @SunnyShu0925's fix. Frozen main f24a3f03cd16176b2704ec2e51aba9b459a09f90 versus contributor candidate 7f28fe332f06, independently installed and runtime-built in secretless Docker node:24.22.1. The final maintenance changes touch only tests/docs, so the proven production bytes remain unchanged.

Used the shipped openclaw.mjs --profile <owned-profile> gateway run and gateway call plugins.sessionAction (pluginId knowledge, actionId ontology, agentId main). Four fresh isolated runs: main twice, candidate twice. Each verified and printed its exact binary's config and agent SQLite paths under its own /work/runs/1793888283796-d06068f0-<run>/; separate HOME, config, state, workspace and loopback ports. No live state/credentials or fault injection.

The normal Knowledge tool provisions the owner's store through a real chat.send/agent.wait turn, with a faithful local OpenAI-compatible tool-call fixture. The Gateway executes knowledge_ontology, returns the real result to the fixture and completes the turn. While stopped, an ordinary authored private/ontology.yaml source is installed in that task-owned vault. Restart gives each run a fresh source inventory. The malformed YAML remains inspectable/diagnosable, just as in the existing source-view regression. No source authorization or registry internals are bypassed.

The source places 😀 across the first 256-unit boundary, followed by repeated 🦞 comments. Paging uses only the returned nextOffset, with maxChars:256, until null:

run    pages  first nextOffset  pages with split pairs  concatenate UTF-16  UTF-8 each page then concatenate
base1  6      256               2                      exact               NOT exact
base2  6      256               2                      exact               NOT exact
cand1  6      255               0                      exact               exact
cand2  6      255               0                      exact               exact

Every page's total/totalChars matches the full source length; page lengths stay <=256, offsets advance by exactly the returned text length, and the sixth page ends pagination. Main only reconstructs if consumers retain the lone UTF-16 halves until joining; encoding pages separately corrupts them. Candidate preserves each complete character and reconstructs exactly in both cases.

Controls, checked in all four runs and compared exactly across parsed responses (no normalization): authorized source inventory, totals, full default-window read, maxChars:512, unauthorized ../../etc/passwd refusal, and invalid maxChars:255 refusal are identical. A deliberately misaligned offset 256 is accepted on main but refused on candidate. Through the real Gateway the refusal is the existing redacted UNAVAILABLE / plugin session action failed envelope (CLI exit 1), not the internal Unicode diagnostic; the focused regression covers the existing Unicode refusal at the owner boundary.

Setup captures are retained transparently: HTTP tools intentionally lack a memory audience, so provisioning moved to the normal owner chat turn; the fixture selected direct tool schemas and sufficient context; its authored file was placed in the authorized private partition; expected Gateway error envelopes are captured rather than treated as CLI transport successes. None of those setup failures is counted as product reproduction. The completed four-run receipt above is from invocation 1793888283796-d06068f0.

Local evidence: ~/Developer/.agents/handoffs/openclaw-bugloop/proofs/193433/ contains proof.mjs, compare.mjs, runtime-summary.json, four complete invocation JSON files (CLI calls, model requests/tool results, Gateway logs, pages and controls), and install/build/check logs.

Focused checks: 21 tests passed across inspection.test.ts and ontology.test.ts; changed production/test typed lint, focused test typecheck using the canonical compiler wrapper, and changed-file formatting passed. The final regression copied to frozen main fails exactly the per-page UTF-8 round-trip assertion (seven other tests pass). Consolidated repeated source-view options without removing any assertions or cases. Whole-PR deltas: production +8/-4 (12 gross, net +4); tests +5/-10 (net -5); docs +5/-3.

@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Exact-head CI failure classification

Head e9c6cbfff00b517009a3ffedd35f9912f240eef8, CI run 42044690759. No jobs rerun, no repush for green. Fresh exact-head ClawSweeper is 5/6 with no findings.

  1. check-lint-core-3: fails on existing eslint(max-lines) diagnostics: src/config/sessions/transcript.test.ts:1078:4 has 1029/1000 lines, and src/config/sessions/session-entry-read.worker.ts:728:2 has 710/700. Both exact paths, line locations, counts and thresholds are present in hourly main 42035744729 / core-3, main SHA 72088ef3eae80873ea6c8267ecda5c8f2b7aeee2. That hourly job succeeds with those warnings; this PR's selected changed-lint scope treats them as failure. The warnings themselves are inherited, not introduced by this Knowledge-only diff.

  2. check-lint-core-5: core child processes fail before lint parity because resolveDevTool cannot stage pinned Bun openclaw-v1.4.4-20261026-191755ec11-webkit-b82bc917e9; both traces end at scripts/lib/dev-tool.mts:30:13 with OPENCLAW_LINT_TOOL=bun: could not stage the pinned fork. The selected Knowledge extension stripe passes, with 0 warnings/errors. I sampled recent unrelated failed CI runs and found no matching failed core-5 receipt, then established scoped main/candidate parity in the retained secretless Node 24.22.1 Linux container:

main f24a3f03cd16176b2704ec2e51aba9b459a09f90:
  fresh task-owned cache, resolveDevTool("lint", CI="", OPENCLAW_LINT_TOOL="bun")
  exit 1: could not stage the pinned fork; dev-tool.mts:30:13
candidate (same production bytes as final head):
  separate fresh task-owned cache, identical operation
  exit 1: could not stage the pinned fork; dev-tool.mts:30:13

This is a scoped stager reproduction, not a full shard rerun. Local Docker is linux-arm64 whereas hosted CI is linux-x64; the matching failure is in the same unmodified staging owner, pin and shell stager, before any linted product file executes. git diff --exit-code <main> HEAD confirms dev-tool.mts, pinned-bun.mts, openclaw-bun.json, stage-openclaw-bun.sh, lint-parity.mts, and run-oxlint.mts are unchanged. Knowledge source pagination cannot reach or alter those staging inputs. Local receipts: stage-parity.sh, stage-{base,cand}.{log,exit}, and ci-failed.log under proofs/193433/.

openclaw/ci-gate is red as an aggregate of those two jobs; its status reconciliation reports the same failure. One cancelled check is a superseded PR context and evidence run; the replacement passed. No selected product test/type/lint coverage was cancelled. The PR's two focused suites (21 tests), focused typecheck and changed-file typed lint passed, and the hosted Knowledge extension lint stripe passed. No unrelated code was changed.

@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the reds are inherited. core-3 shows the same max-lines diagnostics (transcript.test.ts:1078 and session-entry-read.worker.ts:728) on hourly main run 42035744729. core-5's pinned Bun staging failure reproduces identically on main and the candidate. The hosted Knowledge lint this PR touches passed. Receipt: #193433 (comment)

@obviyus
obviyus merged commit 6d49ef1 into openclaw:main Nov 5, 2026
110 of 115 checks passed
@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Landed in 6d49ef1. Thanks @SunnyShu0925. Knowledge source pages no longer split emoji across page boundaries.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…penclaw#193433)

fix(knowledge): page authorized sources on Unicode-safe boundaries

Knowledge source pages were cut with a bare UTF-16 slice, so emoji and other surrogate pairs could be split across pages, corrupting each page's text, and the next offset could be wrong. Pages now use the existing Unicode-safe text window, so pages concatenate losslessly and the next offset is correct. A misaligned offset gets the existing refusal. Source authorization, inventory, totals and budgets are unchanged.

Evidence: built Gateway `plugins.sessionAction` pagination, twice per ref. Main split two pages and corrupted per-page UTF-8; with this change every character is kept, the next offset is 255, and the pages reconstruct the source exactly. Inventory, totals, budgets and unauthorized-source controls match. Details: openclaw#193433 (comment).

Thanks @SunnyShu0925.

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

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. plugin: knowledge proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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.

2 participants