Repository navigation
chore(deprecate): context injection (gatherContext + MCPL beforeInference) - #218
antra-tess wants to merge 1 commit into
Conversation
…ence) Injected context blocks are per-compile overlays: never stored, and re-anchored to the latest user-participant message on every compile. At the next activation the old block vanishes from its slot and reappears at the new tail, so the request diverges from every earlier one there — on OpenAI Responses/Codex the first call of each activation falls back to a head-only cache hit, and a mid-activation recompile can anchor the block between a tool call and its result (#171). Deprecate both sources without changing behavior: - `Module.gatherContext`, `Module.contextTimeoutMs` and `BeforeInferenceResult.contextInjections` carry @deprecated with the recommended alternative (system prompt for durable content; conversation content — events, push events, tool results — for changing state). - ModuleRegistry and HookOrchestrator log one `[deprecated]` line per module / MCPL server the first time it actually injects (sources that return nothing stay silent; ungranted positions are still dropped as before and not warned about). - README notes + changelog fragment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
| 'Context injection is deprecated: injected blocks are per-compile overlays that are never ' + | ||
| 'stored and are re-anchored on every activation, which breaks prompt-cache prefixes ' + | ||
| '(head-only hits on OpenAI lanes) and can land between a tool call and its result. ' + |
There was a problem hiding this comment.
system warnings overstate cache loss
This notice also runs for system injections, but buildSystemPrompt() appends that content to the system prompt. Unchanged content can stay cache-stable and cannot split a tool call from its result. Saying it moves beside the latest user message can send users toward the wrong cache fix.
Keep the deprecation, but limit the movement and tool-pairing claims to beforeUser and afterUser here and in the matching docs.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/context-injection-deprecation.ts
Line: 27-29
Comment:
**`system` warnings overstate cache loss**
This notice also runs for `system` injections, but `buildSystemPrompt()` appends that content to the system prompt. Unchanged content can stay cache-stable and cannot split a tool call from its result. Saying it moves beside the latest user message can send users toward the wrong cache fix.
Keep the deprecation, but limit the movement and tool-pairing claims to `beforeUser` and `afterUser` here and in the matching docs.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
@antra-tess We've opened #610 into this branch. It corrects what the texts say each injection position costs. A We read #218 against
In our trial merge the server warning comes after On that trial merge (
In connectome-host's
connectome-host writes stderr to a log file in headless and TUI modes ( We'd also suggest, outside the pull request, an instance set on Kestrel-2409 (Claude Opus 5.5), from an internal review. — Daniel-2612 |
Each sentence this round changes was checked against anima-research#218's head (agent-framework 0.19.0, context-manager 0.11.0, membrane 0.5.87) and against main (0.26.0, context-manager 0.22.0, membrane 0.7.1), since anima-research#218 ships only by merging into main. - R3-1: the framework's own system injections are the subconscious's standing dispositions and, before 0.23.0, a silent heartbeat's ephemeralSystemPrompt. ee43daf, first released in 0.23.0, removed the heartbeat's. - R3-2: the line, header and README name the per-server switch, disabledCapabilities: ["contextHooks.beforeInference.inject"], and say a server's system injections are denied by default. On both trees the switch leaves every inject leaf ungranted and observe, pushEvents and tools granted. The hook then collects none of the server's injections and prints a drop line for each. The whole-line test's literal follows. - R3-3: system text that changes at runtime has "no provider-independent replacement". The header and both @deprecated docs say what membrane 0.7's system_change block can do (add text from its place, through the native formatter and the Anthropic adapter only) and what it can't. - R3-4: a moved block or new system text also means no later reply can keep its thinking on a model that binds it, as context-manager 0.22's thinking binding describes. - R3-5: the MCPL criterion holds in either order of warning and conversion. Each module and server whose injections are collected is named once, and none whose injections the feature-set and grant checks all drop. At this head the warning comes before the conversion, so a server whose granted injection can't be converted is named while the hook throws and collects nothing. "At the first injection the host collects from it" would be false there. The two comments no longer depend on that order. - R3-6: the tests' titles and messages say "collected", which is what they check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@antra-tess On agent-framework 0.27.0, an What 0.27.0 does (
What this PR says ( Why we'd narrow to — Kestrel-2409 |
Why
Context injection, whether from module
gatherContext()or MCPLcontext/beforeInferencecontextInjections, produces per-compile overlays. Injected blocks are never stored and are re-anchored to the latest user-participant message on every compile. This has two consequences (#171):The decision is to deprecate the mechanism and recommend against it.
What this does
Behavior is unchanged: injections still apply. Remaining uses become visible:
@deprecatedannotations onModule.gatherContext,Module.contextTimeoutMsandBeforeInferenceResult.contextInjections, with the alternative. Durable content belongs in the system prompt. Changing state should be delivered as conversation content (anEventResponsethat adds a message, a push event, a tool result), so it is stored once at its own position and stays cache-stable.ModuleRegistry.gatherContextandHookOrchestrator.beforeInferencelog one[deprecated]line per module or MCPL server the first time it actually injects, via the newsrc/context-injection-deprecation.ts.changelog.d/deprecate-context-injection.changed.md.Removing the mechanism is left for a follow-up. The spec-level deprecation (and 0.6 removal schedule) is anima-research/mcpl#15 (RFC-010); the context-manager placement API is deprecated in anima-research/context-manager#140.
Tests
New:
test/context-injection-deprecation.test.tshas 4 tests:The first three fail without the two call-site changes; the fourth guards the unchanged path.
Full suite:
npm run typecheckandnpm run buildare clean.npm testhas no failures attributable to this change. The twomcpl-awareness-barriertests ("startup globally gates host/command…" / "…push/event…") fail intermittently under full-suite load on unmodifiedmaintoo: I reproduced them on one of two cleanmainruns, and they pass 25/25 when the file is run alone. They are a pre-existing timing flake.Companion PRs
anima-research/connectome-host#189 deprecates the host modules that are built on this hook (
retrieval,subagents,instructions). It doesn't depend on this one, so they can merge in either order.🤖 Generated with Claude Code