Conversation
…ype keys `branches` is initialized as an object literal, so the lazy-init guard in processThought reads inherited Object.prototype members as existing entries for IDs such as "constructor", "toString", "valueOf", "hasOwnProperty" and "__proto__". The guard then skipped the assignment and the following push threw a TypeError, which the catch turned into isError: true even though the call had already been appended to thoughtHistory. Give `branches` a null prototype so any string ID behaves like any other.
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.
Description
branchIdis declared as an opaque string in the tool schema (src/sequentialthinking/index.ts:92—z.string().optional().describe("Branch identifier"), nopattern/format/refine), but the branch map is a plain object literal, so a schema-valid id that happens to name anObject.prototypemember is never treated as an ordinary key.The lazy-init guard at
src/sequentialthinking/lib.ts:63readsthis.branches[input.branchId]through the prototype chain. ForbranchIdvalues such asconstructor,toString,valueOf,hasOwnPropertyor__proto__, that lookup returns a truthy inherited value, so the= []assignment on line 64 is skipped, and line 66 calls.pushon something that is not an array. Thecatchatsrc/sequentialthinking/lib.ts:86converts the resultingTypeErrorintoisError: truecarrying the raw internal message:Only the spelling of the id changes the outcome;
branchId: "alt"creates a branch normally. Becausethis.thoughtHistory.push(input)atsrc/sequentialthinking/lib.ts:60runs before the branch block, the rejected call has also already been appended to the history.Fix: initialize
brancheswith a null prototype (Object.create(null)) so every string id is an ordinary own key, the same way the other official servers keep per-key state in aMap.Fixes #4813
Server Details
SequentialThinkingServer.processThoughtMotivation and Context
branchIdis documented as an opaque identifier ("Identifier for the current branch (if any)",src/sequentialthinking/index.ts:69) and the tool is registered withannotations: { readOnlyHint: true, idempotentHint: true }(src/sequentialthinking/index.ts:95-98). A well-formed call under the advertised schema should therefore succeed, but abranchIdthat collides with anObject.prototypekey instead returnsisError: truewith an internal JavaScript error message, and still counts towardthoughtHistoryLengthfor every later call.The failure is reachable from any
tools/callwithbranchFromThought >= 1and a collidingbranchId— no unusual setup is needed, and a client whosebranchIdis influenced by tool/prompt content reaches it without intending to.Same bug class as the previously fixed
modelcontextprotocol/servers#4157(filesystemedit_filenewTexthijacked byString.prototype.replacesemantics), where JS builtin semantics took over a documented string input.How Has This Been Tested?
Unit tests only; no LLM client was used.
Red — the added test run against the unpatched tree (
branches = {}):Green — after the fix, and the module's full suite:
The regression test is a table over
constructor,toString,valueOf,hasOwnPropertyand__proto__in the existingprocessThought - branchingblock ofsrc/sequentialthinking/__tests__/lib.test.ts, assertingisErroris undefined and the id appears inbranches.Breaking Changes
None. The tool's request and response shape is unchanged.
branchesis still serialized as a JSON array of strings throughObject.keys(this.branches)(src/sequentialthinking/lib.ts:81), which behaves identically on a prototype-less object.Types of changes
Checklist
The remaining boxes are left unchecked rather than ticked by default: this is a one-line state-initialization fix with no README, environment-variable, or LLM-client surface, and no new error handling is introduced.
Additional context
src/sequentialthinking/lib.ts:17—private branches: Record<string, ThoughtData[]> = {};→Object.create(null). TheObject.keys()consumer atlib.ts:81is the only reader of the map outside the guard, and it is unaffected.git diff:Note on scope: this change fixes the branch-tracking failure, so the colliding call now succeeds and is recorded exactly once. It does not change the pre-existing behavior that a call ending in
isErrorhas already been appended tothoughtHistory(lib.ts:60runs before the branch block) — that ordering affects error paths generally and is left untouched here to keep the patch minimal.