fix(agent-core): correct MCP tool-name hash and post-compaction injection marker#732
Open
Dmatut7 wants to merge 3 commits into
Open
fix(agent-core): correct MCP tool-name hash and post-compaction injection marker#732Dmatut7 wants to merge 3 commits into
Dmatut7 wants to merge 3 commits into
Conversation
`stableHash8` hex-encoded a value produced by `Math.imul`, which returns a signed 32-bit int. For the ~50% of inputs that hash negative, `toString(16)` emitted a leading `-`, yielding a 9-char `-xxxxxxxx` suffix (and `-` is not a hex digit) instead of the documented deterministic 8-char hash used when a qualified MCP tool name exceeds 64 chars. Coerce to unsigned 32-bit before encoding so the suffix is always 8 lowercase-hex characters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…summary `onContextCompacted` remaps an injection's stored index after compaction replaces the first `compactedCount` messages with a single summary at index 0. A surviving injection (old index >= compactedCount) maps to new index >= 1, but the guard kept any `newInjectedAt >= 0`. When the injection was the last message in the compacted prefix (`injectedAt === compactedCount - 1`), `newInjectedAt` is 0 — so it was wrongly pinned to the summary message instead of being cleared. That stale marker made PluginSessionStartInjector never re-inject and PlanModeInjector emit a weaker (sparse/none) reminder right after the full one was compacted away. Require `newInjectedAt >= 1` so a compacted-away injection becomes null and re-injects as intended. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 89bc94e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
No existing issue — two agent-core correctness bugs explained below.
Problem
(1)
stableHash8hex-encoded aMath.imulresult (signed 32-bit); for ~half of inputs the hash is negative, sotoString(16)produced a 9-char-xxxxxxxxsuffix (with a-, not a hex digit) instead of the documented 8-char hash used when a qualified MCP tool name exceeds 64 chars. (2)DynamicInjector.onContextCompactedremapped an injection's index with a>= 0guard, but compaction puts a single summary at index 0 so a surviving injection maps to>= 1; when the injection was the last message folded into the summary (injectedAt === compactedCount - 1, which yields 0) it was pinned to the summary instead of cleared — so plugin session-start blocks never re-injected and plan-mode reminders dropped to sparse/none right after a full one was compacted away.What changed
(1) Coerce the hash to unsigned 32-bit before encoding → always 8 lowercase-hex chars. (2) Require
newInjectedAt >= 1, so a compacted-away injection becomes null and re-injects. Tests added for both.Checklist