Skip to content

[Bug] MemWalMock.recall ignores sort: recent and returns stale memories #1124

Description

@ilanvkn

Summary

MemWalMock.recall accepts RecallOptions.sort but ignores it. Two equally matching memories are returned oldest-first even with sort: "recent", limit: 1. This makes offline tests of newest-wins memory handoffs differ from the relayer.

Environment

  • dev commit: 3e0534e6a7099893515e447033e37f1ea34aa9ca
  • SDK: 0.1.8; Node v26.10.0; macOS
  • Deterministic offline mock; no LLM, wallet, or production service involved.

Reproduction

const mock = MemWalMock.create();
await mock.rememberAndWait("project release version one");
await mock.rememberAndWait("project release version two");

const result = await mock.recall({
  query: "project release",
  sort: "recent",
  limit: 1,
});
console.log(result.results[0].text);

Actual: project release version one
Expected: project release version two

Default / explicit relevance ordering should retain its existing semantic tie behavior.

Cause and proposed fix

In packages/sdk/src/mock.ts, recall sorts by distance then ascending sequence and truncates immediately, without reading options.sort.

The relayer's RecallSort::candidate_limit uses max(limit, min(5 * limit, 50)) for recent, then select_hits_for_sort selects newest candidates before truncation. The mock can mirror this bounded candidate window and use its deterministic insertion sequence as write-time ordering.

A local patch implementing this passes all 15 mock tests. Three new regressions cover:

  1. Newest selection before limit, retaining relevance behavior.
  2. Bounded semantic candidate window.
  3. Namespace filtering and token budgeting.

Original source: 12 pass / 3 new regressions fail. Patched source: 15 pass / 0 fail. Tests ran offline against TypeScript stripped with Node module hooks; full compiled SDK suite and typecheck have not been run.

This report and proposed patch were prepared with AI assistance. No production requests, credentials, or mainnet writes were used.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions