Skip to content

fix(active-memory): skip payload-less memory_search toolResults in tr… - #68773

Merged
Takhoffman merged 2 commits into
openclaw:mainfrom
SimbaKingjoe:fix/memory-search-tool-results
Apr 28, 2026
Merged

Takhoffman merged 2 commits into
openclaw:mainfrom
SimbaKingjoe:fix/memory-search-tool-results

Conversation

@SimbaKingjoe

Copy link
Copy Markdown
Contributor

fix(active-memory): skip payload-less memory_search toolResults in transcript debug lookup

Summary

  • Problem: readActiveMemorySearchDebug used asRecord(details?.debug) ?? {}, which forced an empty object {} when the debug field was missing. This made the subsequent guard !debug && !warning && !action && !error always falsy (because {} is truthy), so the function would return early on the newest memory_search toolResult even when it had no debug payload, shadowing older entries that did contain real debug data.
  • Why it matters: Memory search debug logs became incomplete or misleading — real debug information from earlier results was hidden by later empty results, making it harder to diagnose memory‑search behavior in production.
  • What changed: Removed the ?? {} fallback. Now debug is undefined when the field is absent, allowing the guard to correctly skip processing and walk back to find the most recent result that actually has debug data.
  • What did NOT change: No change to the actual content or formatting of debug logs when valid data exists. Behavior for results with populated debug remains identical. No other memory or tool execution logic is affected.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: asRecord(details?.debug) ?? {} intentionally defaulted missing debug to an empty object, but the guard that followed was designed to skip only when debug is falsy (undefined or null). An empty object {} is truthy, so the guard never triggered.
  • Missing detection / guardrail: There was no unit test that simulated a transcript with interleaved empty and populated memory_search results. Existing tests only verified happy paths where every result had a debug field.
  • Contributing context (if known): The original ?? {} was likely added to avoid undefined checks later, but it inadvertently broke the guard’s semantics.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/active-memory/index.test.ts (new test case added)
  • Scenario the test should lock in: A transcript with two memory_search tool results: first result with valid details.debug, second result with details: {} (no debug). The function should return the debug data from the first result, not skip both.
  • Why this is the smallest reliable guardrail: A unit test that directly calls readActiveMemorySearchDebug with a controlled transcript array isolates the exact regression without needing the full memory pipeline or external storage.
  • Existing test that already covers this (if any): None.
  • If no new test is added, why not: N/A – a regression test has been added as part of this PR.

User‑visible / Behavior Changes

None. This only affects internal debug logging used by developers.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: any
  • Runtime/container: Node.js 20+
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Create a transcript .jsonl where:
    • Entry A: memory_search tool result with details.debug = { backend: "qmd", hits: 3 }
    • Entry B (newer): another memory_search tool result with details: {} (no debug)
  2. Call readActiveMemorySearchDebug on this transcript.
  3. Observe the returned debug object.

Expected

The function returns the debug object from entry A (the older entry with real data).

Actual (before fix)

The function returns undefined (or early‑exits without processing), because entry B’s ?? {} created an empty object and the guard failed to skip.

Evidence

  • Failing test before + passing after (included in PR)
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios:
    • Empty debug field (details: {}) followed by a populated one → correct older debug returned.
    • Populated debug only → returns that debug.
    • No memory_search results → returns undefined.
    • Multiple populated results → returns the most recent one (unchanged behavior).
  • Edge cases checked: Empty details object, missing details field, debug set to null, debug set to an array (unlikely but handled gracefully).
  • What I did NOT verify: Interaction with the full memory storage layer (outside readActiveMemorySearchDebug). The change is isolated to this helper function.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

None.

@greptile-apps

greptile-apps Bot commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the ?? {} fallback from asRecord(details?.debug) in readActiveMemorySearchDebug, fixing a bug where a newer memory_search toolResult with no debug field would produce a truthy empty object, causing the guard (!debug && !warning && !action && !error) to never skip it and shadow older entries with real debug data. The fix is a single-line change accompanied by a well-targeted regression test.

Confidence Score: 5/5

Safe to merge — the change is minimal, correct, and covered by a new regression test.

The one-line removal of ?? {} directly fixes the described bug and does not affect any other code path. The new test validates the exact failure scenario. No P0/P1 findings.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(active-memory): skip payload-less me..." | Re-trigger Greptile

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

Keep this PR open. Current main still has the asRecord(details?.debug) ?? {} fallback in readActiveMemorySearchDebug, so a newer payload-less memory_search transcript result can still block an older useful debug payload. The PR remains a focused bug fix with a targeted regression test and no obvious security-sensitive unrelated changes in the provided diff.

Best possible solution:

Keep this PR open and land it, or an equivalent patch, after normal maintainer validation. The best code path is to remove the ?? {} fallback in readActiveMemorySearchDebug and keep the regression test proving a newer payload-less memory_search transcript entry does not hide older real debug telemetry.

What I checked:

Remaining risk / open question:

  • This read-only review did not run the Active Memory test file; normal maintainer validation should run the targeted test or changed-test lane before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 189c91eae6e1.

maxddai and others added 2 commits April 28, 2026 08:05
…anscript debug lookup

[asRecord(details?.debug) ?? {}] made the `!debug && !warning && !action && !error`
guard dead, so readActiveMemorySearchDebug returned on the newest `memory_search`
toolResult even when it had no debug fields, shadowing older entries that did.
Drop the `?? {}` so the skip guard walks back to the real debug record, and add
a regression test that writes a real transcript `.jsonl` with one empty and one
populated entry.
@Takhoffman
Takhoffman force-pushed the fix/memory-search-tool-results branch from 8ca5efe to 7058b51 Compare April 28, 2026 13:16
@Takhoffman
Takhoffman merged commit bdb75bd into openclaw:main Apr 28, 2026
59 checks passed
@Takhoffman

Copy link
Copy Markdown
Contributor

Merged in bdb75bd after representative verification with the Active Memory test, targeted formatting, and diff whitespace checks. I added the Unreleased changelog entry before merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
openclaw#68773)

Verified:
- pnpm install --frozen-lockfile
- pnpm test extensions/active-memory/index.test.ts
- pnpm exec oxfmt --check --threads=1 extensions/active-memory/index.ts extensions/active-memory/index.test.ts CHANGELOG.md
- git diff --check origin/main..HEAD
- gh pr checks 68773 --repo openclaw/openclaw --required

Co-authored-by: SimbaKingjoe <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
openclaw#68773)

Verified:
- pnpm install --frozen-lockfile
- pnpm test extensions/active-memory/index.test.ts
- pnpm exec oxfmt --check --threads=1 extensions/active-memory/index.ts extensions/active-memory/index.test.ts CHANGELOG.md
- git diff --check origin/main..HEAD
- gh pr checks 68773 --repo openclaw/openclaw --required

Co-authored-by: SimbaKingjoe <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
openclaw#68773)

Verified:
- pnpm install --frozen-lockfile
- pnpm test extensions/active-memory/index.test.ts
- pnpm exec oxfmt --check --threads=1 extensions/active-memory/index.ts extensions/active-memory/index.test.ts CHANGELOG.md
- git diff --check origin/main..HEAD
- gh pr checks 68773 --repo openclaw/openclaw --required

Co-authored-by: SimbaKingjoe <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
openclaw#68773)

Verified:
- pnpm install --frozen-lockfile
- pnpm test extensions/active-memory/index.test.ts
- pnpm exec oxfmt --check --threads=1 extensions/active-memory/index.ts extensions/active-memory/index.test.ts CHANGELOG.md
- git diff --check origin/main..HEAD
- gh pr checks 68773 --repo openclaw/openclaw --required

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants