feat(gateway): session-level recall dedup with change detection (fixes #120) - #653
Open
heguang-mercy wants to merge 1 commit into
Open
feat(gateway): session-level recall dedup with change detection (fixes #120)#653heguang-mercy wants to merge 1 commit into
heguang-mercy wants to merge 1 commit into
Conversation
Adds opt-in SessionRecallDedup to the Gateway /recall endpoint: within a
session, a byte-identical appendSystemContext is skipped (empty context +
deduplicated flag) until the content changes. Disabled by default; config
recallDedup.{enabled,ttlMs,maxEntries} + TDAI_GATEWAY_RECALL_DEDUP_* env vars.
13 new unit tests; full suite 80/80.
Closes TencentCloud#120
Collaborator
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Issue #120 and #523 observed that on the Gateway/Hermes path, every turn calls
POST /recall(prefetch) and receives a byte-identicalappendSystemContext(stable persona / scene / tools blocks) ??87.5% of injections within a session were exact duplicates. The redundant text is re-sent to the LLM every turn, wasting tokens.The OpenClaw path is already covered by #188 / #335 / #375 / #514 (
showInjected,injectionMode,prependSystemContext), but those PRs explicitly kept the Gateway/recallresponse compatible. This PR fills that gap.Approach
Adds opt-in session-level dedup to the Gateway via a new
SessionRecallDedupcomponent (src/gateway/recall-dedup.ts):/recallreturnscontext: ""+deduplicated: true(new optional field, fully backward compatible).session_key; entries expire afterttlMs(default 1h), capped atmaxEntries(default 1000, LRU eviction), and cleared on/session/end.Configuration
Env vars:
TDAI_GATEWAY_RECALL_DEDUP_ENABLED,TDAI_GATEWAY_RECALL_DEDUP_TTL_MS,TDAI_GATEWAY_RECALL_DEDUP_MAX_ENTRIES.Changes
src/gateway/recall-dedup.ts??newSessionRecallDedup+fingerprintOfsrc/gateway/recall-dedup.test.ts??13 unit testssrc/gateway/types.ts??RecallResponse.deduplicated?: booleansrc/gateway/config.ts??recallDedupconfig section (env + yaml)src/gateway/server.ts??wire dedup into/recalland/session/endCHANGELOG.md??entry under UnreleasedTesting
npx vitest run??80/80 passing (5 files), including 13 new dedup tests covering: disabled passthrough, identical-repeat skip, session isolation, change-detection re-serve, empty-context passthrough, TTL expiry, LRU eviction, clearSession, and hit/miss counters.Closes #120