Fail loudly when the base context is read outside its scope (v1.6.4) - #9
Merged
Merged
Conversation
#5 fixed the one place that read the client after runWithBase() had returned. This makes the next such mistake announce itself instead of hiding. ContextualClient resolved through registry.resolve(getStore()), which could not tell "no scope at all" from "in a scope, no base named" — both arrived as undefined. With a single base the out-of-scope read then quietly succeeded via the registry default; with two or more it threw `Multiple bases available … Specify "base" parameter`, blaming the caller for omitting an argument they had supplied. That combination is what let the defect survive five months: the configuration that would have exposed it is not the one we run. The store now carries { base } instead of the bare name, so an absent store is detectable, and reading outside the scope throws a message that names the actual error — the same way regardless of how many bases are configured. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tn4FT2sVqoFz1QdpNDNAy7
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.
Nachtrag zu #5. Der hat die eine Stelle repariert, die den Client nach dem
runWithBase()-Scope las. Dieser PR sorgt dafür, dass der nächste solche Fehler sich meldet, statt sich zu verstecken.Warum der Bug fünf Monate überlebt hat
ContextualClientlöste überregistry.resolve(baseContext.getStore())auf. Der Store war der nackte Base-Name, also kam „gar kein Scope" und „im Scope, kein Name angegeben" beide alsundefinedan. Daraus folgten zwei Verhaltensweisen, die beide falsch sind:Multiple bases available … Specify "base" parameterDie erste Zeile ist der Grund, warum es niemandem auffiel: Die Konfiguration, die den Fehler zeigt, fahren wir selbst nicht — managed mode baut gar keinen
ContextualClient, Mock und Single-Base auch nicht. Die zweite Zeile ist der Grund, warum es als Bedienfehler durchging.Änderung
Der Store trägt jetzt
{ base }statt des nackten Namens. Damit ist ein fehlender Store unterscheidbar, und ein Zugriff außerhalb des Scopes wirft:Gleich, egal wie viele Bases konfiguriert sind. Die berechtigte Meldung (
Specify "base" parameter) bleibt erhalten, wo sie hingehört: innerhalb des Scopes ohne Base-Argument.Verifikation
tests/contextualClient.spec.ts, zuerst rot geschrieben. Der aufschlussreichste ist der Single-Base-Fall: der warf vorher gar nicht.lintundtypechecksauber. Die Absicherung deckt keinen weiteren Verstoß im Bestand auf — deckungsgleich mit der statischen Prüfung (einzigerrunWithBase-Aufrufer isthandleCallTool; alle Client-Zugriffe der 21 Tools liegen in der Handler-Closure; keinesetTimeout/Event-Callbacks, die den Kontext verlassen; keine lazy konsumierten Rückgaben).mainvor Fix: every tool call fails in multi-base mode with two or more bases #5 waren es 22 von 22).🤖 Generated with Claude Code
https://claude.ai/code/session_01Tn4FT2sVqoFz1QdpNDNAy7