Skip to content

fix(memory-wiki): reject out-of-range claim confidence at the mutation boundary - #125656

Merged
obviyus merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/memory-wiki-claim-confidence-range
Sep 3, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/memory-wiki-claim-confidence-range

Conversation

@wanyongstar

@wanyongstar wanyongstar commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Reject new claims[].confidence values outside 0..1 at the shared Memory Wiki mutation validator.
  • Keep legacy or hand-written pages readable by leaving the Markdown read normalizer tolerant.
  • Preserve validation before source synchronization and vault writes for both tool and Gateway mutations.

What Problem This Solves

wiki_apply declared claim confidence as a 0..1 value, but its runtime mutation validator accepted every finite number. The write path persisted values such as 999, and claim ranking later added confidence * 10 to the score.

Root cause

normalizeMemoryWikiMutationInput reused the tolerant frontmatter reader for untrusted mutations without enforcing the mutation schema's confidence range.

Fix

Normalize claims once at the canonical mutation boundary, then reject an out-of-range claim confidence before either caller can synchronize sources or write the vault. The read path remains unchanged for existing data.

Evidence

  • Baseline 88be1b80f58df698fe730b4f3f34934ecae92e21: an authenticated client called the shipped wiki.apply Gateway route with claim confidence 999; the route accepted it and created the page.
  • Head 067d61afbc4b3deb74e8fbbb9cffe487423f6177: the same Gateway call rejects 999 with the range error and creates no page.
  • Direct wiki_apply tool mutation proof also rejects 999 and -0.5 before creating a page; 0.8 still persists.
  • Compatibility: a manually stored legacy claim with confidence 999 remains readable through wiki_search.

Validation

  • node scripts/run-vitest.mjs extensions/memory-wiki/src/tool.test.ts --testNamePattern 'keeps wiki pages unchanged for out-of-range claim confidence'
  • node scripts/run-vitest.mjs extensions/memory-wiki/src/apply.test.ts extensions/memory-wiki/src/tool.test.ts extensions/memory-wiki/src/gateway.test.ts
  • OPENCLAW_E2E_SKIP_BUILD=1 PROOF_EXPECT=<accepted|rejected> vitest run --config test/vitest/vitest.e2e.config.ts memory-wiki-confidence.product-proof.e2e.test.ts
  • node scripts/run-oxlint.mjs --deny-warnings extensions/memory-wiki/src/apply.ts extensions/memory-wiki/src/tool.test.ts
  • oxfmt --check extensions/memory-wiki/src/apply.ts extensions/memory-wiki/src/tool.test.ts

Production LOC: +17/-2. Tests: +18/-0.

…n boundary

The top-level mutation confidence is strictly clamped to [0, 1], but
nested claims[].confidence passed through with only a finite-number
check, so a value like 999 was persisted into page frontmatter and
skewed wiki_search ranking (score += Math.round(confidence * 10))
for every later query. Fail closed with the same range contract as
the top-level field.
@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 7:17 AM ET / 11:17 UTC.

ClawSweeper review

What this changes

This PR rejects numeric nested Memory Wiki claim-confidence values outside 0–1 before a wiki mutation can persist them.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open: the range guard is a sound owner-boundary repair, but the branch conflicts with current main and still describes rejection as clamping. Rebase the guard onto the current mutation normalizer without undoing validation-before-sync ordering.

Priority: P2
Reviewed head: 0917d3a4a4e62c5f193c87dd43459b1494f1a461

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair and owner-boundary proof are solid; a mechanical rebase and the remaining wording correction are needed before merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body contains before/after Node terminal output exercising the real production mutation normalizer: 999 and -0.5 throw after the change while 0.8 remains intact. Current Tool and Gateway entry points invoke that owner before source synchronization or page writes, so the trace covers the changed boundary.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body contains before/after Node terminal output exercising the real production mutation normalizer: 999 and -0.5 throw after the change while 0.8 remains intact. Current Tool and Gateway entry points invoke that owner before source synchronization or page writes, so the trace covers the changed boundary.
Evidence reviewed 5 items Introduced mutation guard: The introduced helper checks finite numeric nested claim confidence before calling the shared claim normalizer, and both mutation operations route their claims through it.
Current entry-point ordering: The current tool and Gateway paths validate the mutation before source synchronization and mutation application, so the intended guard prevents a write-side effect.
Persistence and ranking path: The shared markdown normalizer retains any finite numeric claim confidence, while the query scorer adds confidence times ten; the range invariant belongs at the write mutation boundary rather than the shared reader.
Findings 1 actionable finding [P3] Describe range rejection rather than clamping
Security None None.

How this fits together

Memory Wiki validates agent mutation requests before writing claims into vault-page frontmatter. Wiki search later reads those claims and uses confidence as part of result ranking.

flowchart LR
  A[Agent wiki_apply request] --> B[Mutation validation]
  B --> C[Claim normalization]
  C --> D[Vault page frontmatter]
  D --> E[Wiki search]
  E --> F[Ranked results]
Loading

Before merge

  • Describe range rejection rather than clamping (P3) - readFiniteNumberParam throws when a value exceeds its bounds; it never clamps. The introduced comment therefore contradicts this PR’s fail-closed behavior. This is the prior P3 finding and remains unchanged.
  • Resolve merge risk (P1) - The PR is conflict-dirty against current main, which has rewritten the mutation normalizer and Gateway ordering; it cannot merge until rebased.
  • Resolve merge risk (P1) - Existing callers supplying out-of-range numeric claim confidence will now receive a validation error instead of completing a mutation, so the rebased change must preserve tolerant reads of already-stored legacy pages.
  • Complete next step (P2) - Rebase onto current main, reapply the nested guard without undoing validation-before-source-sync ordering, replace “clamped” with “rejected” or “validated,” and obtain green exact-head checks.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P3] Describe range rejection rather than clamping — extensions/memory-wiki/src/apply.ts:96-97
Agent review details

Security

None.

PR surface

Source +22, Tests +30. Total +52 across 2 files.

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

Review metrics

Metric Value Why it matters
Production versus test LOC production +22/-2; tests +30/-0 The positive production delta is a dedicated validation helper; its value depends on preserving the narrow mutation-only boundary during rebase.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-wiki/src/apply.ts, vector/embedding metadata: extensions/memory-wiki/src/apply.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase the boundary guard (recommended)
    Reapply the guard to current main, retain validation before source sync, and make the comment accurately describe rejection before rerunning exact-head checks.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main, preserve validation-before-source-sync ordering, correct the clamping wording, and rerun exact-head checks.

Technical review

Best possible solution:

Rebase the narrow range guard into the current mutation normalizer, retain current validation-before-source-sync behavior, and correct the comment to say values are rejected rather than clamped.

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

Yes. The current shared claim normalizer retains finite values without a range check, and the query scorer directly converts confidence into ranking points; the PR body also supplies before/after terminal output against the real normalizer.

Is this the best way to solve the issue?

Yes, after rebase. Validating only on the mutation path protects future writes while leaving the shared frontmatter reader able to open legacy pages with out-of-range values.

Full review comments:

  • [P3] Describe range rejection rather than clamping — extensions/memory-wiki/src/apply.ts:96-97
    readFiniteNumberParam throws when a value exceeds its bounds; it never clamps. The introduced comment therefore contradicts this PR’s fail-closed behavior. This is the prior P3 finding and remains unchanged.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

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

Label justifications:

  • P2: This repairs bounded ranking integrity in the bundled Memory Wiki plugin without evidence of an urgent runtime outage.
  • merge-risk: 🚨 compatibility: The patch intentionally changes malformed numeric claim input from a successful mutation to a validation error for existing callers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body contains before/after Node terminal output exercising the real production mutation normalizer: 999 and -0.5 throw after the change while 0.8 remains intact. Current Tool and Gateway entry points invoke that owner before source synchronization or page writes, so the trace covers the changed boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body contains before/after Node terminal output exercising the real production mutation normalizer: 999 and -0.5 throw after the change while 0.8 remains intact. Current Tool and Gateway entry points invoke that owner before source synchronization or page writes, so the trace covers the changed boundary.

Evidence

Acceptance criteria:

  • [P1] pnpm test extensions/memory-wiki/src/apply.test.ts.
  • [P1] pnpm test extensions/memory-wiki/src/gateway.test.ts.
  • [P1] pnpm check:changed -- extensions/memory-wiki/src/apply.ts extensions/memory-wiki/src/apply.test.ts.

What I checked:

  • Introduced mutation guard: The introduced helper checks finite numeric nested claim confidence before calling the shared claim normalizer, and both mutation operations route their claims through it. (extensions/memory-wiki/src/apply.ts:101, 0917d3a4a4e6)
  • Current entry-point ordering: The current tool and Gateway paths validate the mutation before source synchronization and mutation application, so the intended guard prevents a write-side effect. (extensions/memory-wiki/src/gateway.ts:395, f5673e904299)
  • Persistence and ranking path: The shared markdown normalizer retains any finite numeric claim confidence, while the query scorer adds confidence times ten; the range invariant belongs at the write mutation boundary rather than the shared reader. (extensions/memory-wiki/src/markdown.ts:278, 0917d3a4a4e6)
  • Range reader contract: The shared finite-number reader throws when a configured bound is exceeded; it does not clamp values, making the new comment inaccurate. (src/agents/tools/common.ts:309, 0917d3a4a4e6)
  • Current-main integration drift: Merged PR 123448 rewrote the mutation-operation normalizer and moved Gateway validation before source sync. Its merge commit is included in v2026.8.2, so this conflict-dirty branch must reapply the guard to that current shape. (extensions/memory-wiki/src/apply.ts:92, 10913e6c73cb)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main without undoing validation-before-source-sync ordering.
  • Replace “clamped” with “rejected” or “validated” in the new comment.
  • Obtain green required checks for the refreshed exact head.

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 (6 earlier review cycles)
  • reviewed 2026-08-18T06:40:28.560Z sha 0917d3a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T12:30:49.622Z sha 0917d3a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T14:30:56.314Z sha 0917d3a :: needs changes before merge. :: [P3] Describe range rejection rather than clamping
  • reviewed 2026-08-22T14:43:37.891Z sha 0917d3a :: needs changes before merge. :: [P3] Describe range rejection rather than clamping
  • reviewed 2026-08-25T14:32:37.950Z sha 0917d3a :: needs changes before merge. :: [P3] Describe range rejection rather than clamping
  • reviewed September 2, 2026, 4:04 AM ET / 08:04 UTC sha unknown :: needs changes before merge. :: [P3] Describe range rejection rather than clamping

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 2, 2026
@obviyus obviyus self-assigned this Sep 3, 2026
# Conflicts:
#	extensions/memory-wiki/src/apply.ts
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 3, 2026
@obviyus
obviyus merged commit c1a24b7 into openclaw:main Sep 3, 2026
116 of 117 checks passed
@obviyus

obviyus commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks @wanyongstar!

Proof: An authenticated wiki.apply Gateway call with claim confidence 999 created a page on baseline 88be1b80. The same call on the exact PR head returned the range error and created no page. Valid 0.8 mutations still persist, and legacy pages remain readable.

  • Bug: New out-of-range claim confidence values persisted and could dominate Memory Wiki search ranking.
  • Fix: The shared mutation validator now rejects those values before source synchronization or vault writes.
Before After
999 persisted into claim frontmatter. 999 is rejected and no page is created.

Landed as c1a24b7fa9b7dfc818c37c361bad422e010731b5 from source 067d61afbc4b3deb74e8fbbb9cffe487423f6177.

vincentkoc added a commit that referenced this pull request Sep 3, 2026
* commit '13b1f71c7010baaf2394555198e2fc04bef03586': (283 commits)
  fix(ui): retire stale MCP feedback across context changes (#128490)
  fix(agents): clarify set-identity workspace output (#126320)
  fix(auth): preserve OAuth metadata during session SDK refresh (#127988)
  fix(agents): recover catalog worker after generation mismatch (#127712)
  fix(memory-wiki): reject out-of-range claim confidence (#125656)
  ci: remove redundant contract runs and costly test work (#137220)
  fix(release): assert the Codex CLI pin the candidate declares (#137136)
  test(voice-call): reuse shared guards and deferred gates (#137262)
  fix(cron): isolate scheduler-disabled shared-store writes (#131733)
  fix(telegram): surface allowed custom reactions in react guidance (#129817)
  test(infra): reuse the shared npm call presence guard (#137254)
  fix: generated images disappear after failed tool calls (#131226)
  fix(docs): match source anchor checks to published sections (#137157)
  fix(backup): preserve audit capture across slow snapshots (#130962)
  fix(release): preserve legacy gh log reads (#137016)
  fix(memory-core): make forget rewrites atomic (#131383)
  fix(agents): write settings atomically (#131431)
  fix(plugins): keep the memory indexing runtime with the selected slot owner (#131779)
  fix(ci): pin iOS screenshot evidence to workflow revision (#136334)
  test(logging): remove redundant stderr spy casts (#137238)
  ...

# Conflicts:
#	scripts/e2e/lib/codex-release-package-assertions.mjs
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
## Summary

- Reject new `claims[].confidence` values outside `0..1` at the shared Memory Wiki mutation validator.
- Keep legacy or hand-written pages readable by leaving the Markdown read normalizer tolerant.
- Preserve validation before source synchronization and vault writes for both tool and Gateway mutations.

## What Problem This Solves

`wiki_apply` declared claim confidence as a `0..1` value, but its runtime mutation validator accepted every finite number. The write path persisted values such as `999`, and claim ranking later added `confidence * 10` to the score.

## Root cause

`normalizeMemoryWikiMutationInput` reused the tolerant frontmatter reader for untrusted mutations without enforcing the mutation schema's confidence range.

## Fix

Normalize claims once at the canonical mutation boundary, then reject an out-of-range claim confidence before either caller can synchronize sources or write the vault. The read path remains unchanged for existing data.

## Evidence

- Baseline `af8828dded4761a9d4c31bf7f6434f13e78e0289`: an authenticated client called the shipped `wiki.apply` Gateway route with claim confidence `999`; the route accepted it and created the page.
- Head `067d61afbc4b3deb74e8fbbb9cffe487423f6177`: the same Gateway call rejects `999` with the range error and creates no page.
- Direct `wiki_apply` tool mutation proof also rejects `999` and `-0.5` before creating a page; `0.8` still persists.
- Compatibility: a manually stored legacy claim with confidence `999` remains readable through `wiki_search`.

## Validation

- `node scripts/run-vitest.mjs extensions/memory-wiki/src/tool.test.ts --testNamePattern 'keeps wiki pages unchanged for out-of-range claim confidence'`
- `node scripts/run-vitest.mjs extensions/memory-wiki/src/apply.test.ts extensions/memory-wiki/src/tool.test.ts extensions/memory-wiki/src/gateway.test.ts`
- `OPENCLAW_E2E_SKIP_BUILD=1 PROOF_EXPECT=<accepted|rejected> vitest run --config test/vitest/vitest.e2e.config.ts memory-wiki-confidence.product-proof.e2e.test.ts`
- `node scripts/run-oxlint.mjs --deny-warnings extensions/memory-wiki/src/apply.ts extensions/memory-wiki/src/tool.test.ts`
- `oxfmt --check extensions/memory-wiki/src/apply.ts extensions/memory-wiki/src/tool.test.ts`

Production LOC: +17/-2. Tests: +18/-0.

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

extensions: memory-wiki merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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