Skip to content

Key the tool response cache by tool id and nested params - #1308

Merged
helpcodeai merged 2 commits into
mainfrom
fix/tool-cache-key
Oct 28, 2026
Merged

helpcodeai merged 2 commits into
mainfrom
fix/tool-cache-key

Conversation

@helpcodeai

Copy link
Copy Markdown
Contributor

Summary

The tool response cache (responseMapping.cacheTtl) built its key from the tool name and a hash of the parameters. Two problems:

The key is now tool_cache:v3:<toolId>:<scope>:<hash>, with the parameters hashed with keys sorted at every depth (the existing hashContent helper). The prefix bump means v2 entries are never read again and simply expire.

Changes

  • buildCacheKey takes the registered tool and uses its id instead of its name.
  • Parameters are hashed with hashContent (recursive key sort, sha256).
  • Tests: different tool ids give different keys, and nested parameters change the key.

Type

  • Bug fix

Testing

  • Added/updated unit tests

Commands, in packages/backend after npm ci and prisma generate:

  • npx jest src/mcp-server/dynamic-mcp-tools: 2 suites, 105 tests passed.
  • Same spec with the old dynamic-mcp-tools.ts: 3 failed (the two new tests and the key prefix check).
  • npx tsc --noEmit -p tsconfig.json: clean.
  • npx eslint on the two changed files: clean.

Behaviour in Cloud and self-hosted is the same. After the deploy, cached tools miss once and refill under the new keys.

Checklist

  • My code follows the existing code style
  • I have tested my changes locally
  • This PR has a descriptive title

Related Issues

Relates to #1296

@helpcodeai
helpcodeai enabled auto-merge (squash) October 28, 2026 08:25
@helpcodeai
helpcodeai merged commit 2ca647e into main Oct 28, 2026
14 checks passed
@helpcodeai
helpcodeai deleted the fix/tool-cache-key branch October 28, 2026 08:35
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant