Skip to content

fix(relayer,sdk): retry transient recall drops and surface all-dropped recalls (#1036) - #1362

Merged
harrymove-ctrl merged 5 commits into
devfrom
fix/issue-1036-all-dropped-recall
Nov 5, 2026
Merged

harrymove-ctrl merged 5 commits into
devfrom
fix/issue-1036-all-dropped-recall

Conversation

@harrymove-ctrl

@harrymove-ctrl harrymove-ctrl commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1036
Fixes #1070

When every vector match in POST /api/recall failed Walrus blob download or SEAL decryption during a transient upstream flake, the relayer dropped all matches without retrying within the request deadline and returned HTTP 200 with results: [] and total: 0. Because total used the post-drop result length and no degraded wire flag was set, callers saw a response identical to a genuinely empty namespace.

Root Cause

  1. download_and_decrypt_blobs and the SEAL sidecar (/seal/decrypt, /seal/decrypt-batch) dropped failed blob downloads and transient key-server RPC failures on the first attempt instead of retrying within the remaining request deadline.
  2. DecryptOutcome::permanent_from_error checked "fetch_keys failed" before permanent SEAL substrings (NoAccessError, InvalidCiphertext, InvalidPersonalMessageSignature, Not enough shares), misclassifying permanent key-fetch rejections as transient and omitting sidecar BatchDecryptError.code.
  3. routes/recall.rs set RecallResponse.total = results.len() (post-drop count) and emitted no degraded wire flag when matches were dropped.
  4. Both @mysten-incubation/memwal (TypeScript SDK) and memwal (Python SDK) lacked a degraded flag, normalized pre-drop total handling, and an onDropped / on_dropped policy option to either inspect the degraded result or opt into a typed error when every matched memory was dropped.

Changes by Surface

  • Rust Relayer (services/server):
    • Extended stage::run_with_deadline task-local context with remaining_budget() and backoff_if_budget_allows(backoff, min_headroom) so retries only run when at least 1000ms of request budget remains.
    • Added single-attempt transient retry helpers download_ciphertext_with_retry (200ms backoff) and decrypt_chunk_with_retry (250ms backoff, retrying either a whole-chunk 503 UpstreamUnavailable or only the DecryptOutcome::Failed { permanent: false } subset).
    • Preserved BatchDecryptError.code from the sidecar and prioritized permanent SEAL codes/messages before generic "fetch_keys failed" matching so permanent errors are never retried.
    • Updated build_recall_response to set total to the pre-drop match count (hit_count.max(results.len() + dropped_count)) and emit degraded: true whenever dropped_count > 0 (skip_serializing_if = "is_false" for clean responses).
  • SEAL Sidecar & Relayer MCP (services/server/scripts):
    • Added retryTransientSealDecryptRpc (up to 2 attempts, 250ms backoff) around createDecryptSealClient() and fetchKeys in /seal/decrypt and /seal/decrypt-batch, skipping permanent SEAL errors immediately.
    • Updated memwal_recall MCP tool to inspect dropped_count > 0 empty responses (as well as MemWalRecallAllDroppedError) and surface isError: true with an explicit dropped-blob diagnostic message.
  • TypeScript SDK (packages/sdk):
    • Added degraded?: boolean on RecallResult and onDropped?: "ignore" | "throw" (defaulting to "ignore") on RecallOptions across MemWal and MemWalMock.
    • By default (onDropped: "ignore"), an all-dropped recall returns the degraded RecallResult (results: [], degraded: true, dropped_count, and pre-drop total) without throwing.
    • Added MemWalRecallAllDroppedError (name = "MemWalRecallAllDropped", code = "RECALL_ALL_DROPPED", exposing total, droppedCount, and namespace), thrown when onDropped: "throw" is selected.
    • Updated withMemWal AI SDK middleware to report degraded all-dropped recalls via onRecallError, avoid caching empty context on transient failure, and proceed gracefully with generation.
  • Python SDK (packages/python-sdk-memwal):
    • Added and exported MemWalRecallAllDropped (code = "RECALL_ALL_DROPPED"), degraded: bool = False on RecallResult, and on_dropped: str = "ignore" ("ignore" or "throw") across MemWal, MemWalSync, MemWalMock, MemWalMockSync, and RecallParams.
    • Omitted on_dropped returns the degraded RecallResult, while explicit on_dropped="throw" raises MemWalRecallAllDropped.

Verification

  • Rust Relayer: cargo test --bin memwal-server (engine::stage::tests, storage::seal::tests, engine::walrus_seal::tests, routes::recall::tests), cargo build --features ci-offline-onchain --bin memwal-server, and cargo clippy --bin memwal-server passed.
  • SEAL Sidecar & Relayer MCP: node --test --import tsx ./mcp/__tests__/recall-max-distance.test.ts ./__tests__/sidecar-seal-routes.test.ts (25 passed).
  • TypeScript SDK: pnpm --filter @mysten-incubation/memwal build && pnpm --filter @mysten-incubation/memwal test (379 passed, 0 failed).
  • Python SDK: uv run --extra dev ruff check memwal/ tests/ and uv run --extra dev pytest -q (520 passed, 0 failed).
  • Downstream Packages & Meta Checks: @mysten-incubation/memwal-mcp, @mysten-incubation/oc-memwal, check-compatibility-contract.mjs, check-docs-code-sync.mjs, check-docs-freshness.mjs, and verify-manual-sdk-release.mjs all passed.
  • Live dev & Local vs dev E2E Reproduction: Verified live dev (https://relayer.dev.memwal.ai) empty-namespace recall returns { results: [], total: 0 } cleanly while all-dropped recall (degraded: true, dropped_count: 3, total: 3 as well as legacy total: 0, dropped_count: 2) returns the normalized degraded result by default and raises MemWalRecallAllDroppedError / MemWalRecallAllDropped when onDropped: "throw" / on_dropped="throw" is passed.

@ducnmm ducnmm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Prepare new SDK release versions for the changed runtime payloads

This changes the TypeScript and Python SDK runtime/API (including the new all-dropped error and recall options), but their versions remain 0.1.12 and 0.2.2, which are already published. The stable release workflows skip publishing an existing version, so these SDK changes would not reach package users after promotion without a new release. The main-promotion version guard also fails against current main with packages/sdk: runtime payload changed but version 0.1.12 was not increased (received 0.1.12). Update the affected SDK version manifests and synchronized package/docs changelogs before shipping these payloads. No full Rust, sidecar, or SDK test suites were rerun locally in this review; the release guard was run against this exact head.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

Thanks @ducnmm for the review. I have updated both SDK version manifests and synchronized their changelogs:

  1. TypeScript SDK: Bumped to version 0.1.13 in packages/sdk/package.json, with synchronized release notes added to packages/sdk/CHANGELOG.md and docs/sdk/changelog.mdx.
  2. Python SDK: Bumped to version 0.2.3 in packages/python-sdk-memwal/pyproject.toml and packages/python-sdk-memwal/memwal/init.py, with synchronized release notes added to packages/python-sdk-memwal/CHANGELOG.md and docs/python-sdk/changelog.mdx.
  3. Verification:
  • node scripts/verify-package-version-bumps.mjs --base origin/main --head HEAD passed cleanly (packages/sdk: 0.1.12 -> 0.1.13).
  • node scripts/verify-manual-sdk-release.mjs passed with manifests and changelogs synchronized for both SDKs.
  • node scripts/check-docs-code-sync.mjs and node scripts/check-docs-freshness.mjs passed.
  • Full test suites passed: TypeScript SDK (378 passed), Python SDK (520 passed, ruff clean), downstream packages (331 MCP, 45 OpenClaw passed), compatibility contract verified, and Rust binary unit/integration tests (1012 passed).

Re-requesting review.

@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm October 31, 2026 04:10

@ducnmm ducnmm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The affected SDK versions are now updated to TypeScript 0.1.13 and Python 0.2.3. The main-promotion version guard and manual manifest/changelog verifier pass. One remaining documentation mismatch is noted below; no runtime change is requested for this point.

Comment thread packages/sdk/CHANGELOG.md Outdated

### Added

- `MemWalRecallAllDroppedError` (`name = "MemWalRecallAllDropped"`, `code = "RECALL_ALL_DROPPED"`) is thrown by `recall` and `recallManual` when every vector search match is dropped during Walrus blob download or SEAL decryption. It exposes `total`, `droppedCount`, and `namespace`. (#1036, #1070)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new all-dropped handler is implemented in recall() only. recallManual() still directly returns the /api/recall/manual response and neither performs this check nor accepts onDropped, so claiming that it throws this error gives callers an unsupported guarantee. Please restrict this entry and the matching docs changelog to recall(). Also, the ignore-mode result in the entry below exposes dropped_count; droppedCount belongs to the thrown error object.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6da4d1c: restricted the MemWalRecallAllDroppedError claim to recall() and updated the { onDropped: "ignore" } payload field to dropped_count in both CHANGELOG.md and docs/sdk/changelog.mdx.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

Thanks @ducnmm. Updated packages/sdk/CHANGELOG.md and docs/sdk/changelog.mdx in 6da4d1c to scope MemWalRecallAllDroppedError to recall() only and list dropped_count on the ignore mode result. Re-requesting review.

@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm October 31, 2026 10:20
@ducnmm

ducnmm commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@harrymove-ctrl Please preserve the existing recall() behavior by default: an all-dropped recall should return the degraded result rather than introduce a new exception. Default to onDropped: "ignore" in TypeScript and on_dropped="ignore" in Python; throw the typed all-dropped error only when the caller explicitly selects "throw". Keep degraded and dropped_count available so callers can inspect the failure without opting into exceptions.

Please align the SDK implementations, mocks, documentation and tests. Add regression coverage showing that an omitted policy returns the all-dropped result, while explicit "throw" raises the typed error. The default-to-throw behavior needs to be changed before approval.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm Addressed in 7d282a8:

  1. Defaulted onDropped to "ignore" in TypeScript (MemWal and MemWalMock) and on_dropped="ignore" in Python (MemWal, MemWalSync, MemWalMock, MemWalMockSync, and RecallParams), preserving existing recall() behavior by returning the normalized degraded RecallResult (results: [], degraded: true, dropped_count, and pre-drop total) without throwing.
  2. Kept MemWalRecallAllDroppedError / MemWalRecallAllDropped strictly opt-in when callers explicitly pass onDropped: "throw" / on_dropped="throw", while keeping AI middleware error reporting and retry behavior intact.
  3. Aligned SDK changelogs, API reference docs, mocks, and regression tests covering omitted policy, explicit "ignore", explicit "throw", and invalid policy validation across both SDKs (TypeScript: 379 passed; Python: ruff + 520 passed; docs and release checks green).

@ducnmm

ducnmm commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@harrymove-ctrl Thanks for updating the default policy to ignore.

Please preserve the existing recall().total semantics: the number of usable items returned by the relayer, before SDK-side filtering. Keep the transient retries, degraded, dropped_count, and opt-in typed errors.

This requires reverting both the relayer’s pre-drop total calculation and the TS/Python SDK normalization that changes a legacy all-dropped response from total: 0 to total: dropped_count. Callers can distinguish an incomplete recall through degraded and dropped_count without changing total.

Please align the docs and regression tests for healthy, partial-drop, and all-dropped responses, including legacy relayer responses.

We can keep retries and degraded-result handling together in this PR once the total change is removed; splitting is not necessary solely because of the file count.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm Addressed in 3b29a5b. Preserved existing usable items total semantics by reverting the relayer's pre-drop total calculation to results.len() and reverting SDK normalization that altered total from 0 to dropped_count on all-dropped recalls. Aligned API reference docs, changelogs, and regression tests across healthy, partial-drop, all-dropped, and legacy responses.

@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1036-all-dropped-recall branch 2 times, most recently from d09d6fa to 9e5102a Compare November 4, 2026 18:57
@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

Rebased onto dev cleanly. All 390 TypeScript SDK tests and 513 Python SDK tests pass with zero lint errors. Re-requested review.

@ducnmm ducnmm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed recall compatibility, retry boundaries, and middleware degradation handling. The default policy preserves degraded results and usable-item total semantics; typed errors remain opt-in. TypeScript SDK tests passed (390), and focused Python client/mock tests passed (95). Rust/MCP tests and live upstream-outage checks were not rerun locally.

@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1036-all-dropped-recall branch from 9e5102a to e92b264 Compare November 5, 2026 03:38
@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

Rebased cleanly onto latest dev (commit e92b264), resolving mcp/tools/recall.ts conflict with the newly merged empty-namespace diagnostics. All 390 SDK unit tests pass; re-requesting review.

@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm November 5, 2026 03:38
@harrymove-ctrl
harrymove-ctrl merged commit 06c3326 into dev Nov 5, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants