Skip to content

feat(agents): add contextInjection 'never' to disable bootstrap file injection#65006

Merged
obviyus merged 1 commit intoopenclaw:mainfrom
xDarkicex:feat/context-injection-never
Apr 25, 2026
Merged

feat(agents): add contextInjection 'never' to disable bootstrap file injection#65006
obviyus merged 1 commit intoopenclaw:mainfrom
xDarkicex:feat/context-injection-never

Conversation

@xDarkicex
Copy link
Copy Markdown
Contributor

Summary

  • Problem: Memory and context-engine plugins cannot fully own system prompt lifecycle because bootstrap files (AGENTS/SOUL) are always injected
  • Why it matters: Plugins that serve authored docs via tools need to suppress bootstrap injection to avoid duplicate/context conflicting content
  • What changed: Added `contextInjection: "never"` option that skips workspace bootstrap file injection entirely
  • What did NOT change: Schema generation, CHANGELOG, auto-generated files left untouched

Change Type

  • Feature

Scope

  • Gateway / orchestration
  • Memory / storage

Linked Issue/PR

Root Cause

N/A - new feature

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
  • Target test or file: `src/config/zod-schema.agent-defaults.test.ts`
  • Scenario the test should lock in: `contextInjection: "never"` is accepted by schema
  • Existing test that already covers this (if any): test added in this PR
  • If no new test is added, why not: test added for schema validation

User-visible / Behavior Changes

  • `agents.defaults.contextInjection: "never"` now accepted as config option
  • When set, workspace bootstrap files are not injected into system prompt

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22+
  • Model/provider: any
  • Integration/channel (if any): any

Steps

  1. Set `agents.defaults.contextInjection: "never"` in config
  2. Run agent with memory plugin active
  3. Observe no AGENTS/SOUL bootstrap files in system prompt

Expected

Bootstrap files not injected when `contextInjection: "never"`

Actual

N/A - new functionality

Evidence

  • Failing test/log before + passing after: schema test passes

Human Verification

  • Verified scenarios: unit tests pass for schema and context helpers
  • Edge cases checked: "never" accepted, invalid values rejected
  • What you did NOT verify: full E2E with memory plugin

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? Only new optional value added to existing key
  • Migration needed? No

Risks and Mitigations

None

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 11, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 11, 2026

Greptile Summary

This PR adds contextInjection: "never" as a new option that fully suppresses workspace bootstrap file injection, enabling memory/context-engine plugins to own the system prompt lifecycle without duplicate content. The schema, type definitions, and both runtime paths (normal run in attempt.context-engine-helpers.ts and the compaction path in compact.ts) are all correctly updated and consistent.

Remaining gaps are all P2: the "never" branch in resolveAttemptBootstrapContext is untested at the behavior level (the context-injection test helper's type doesn't include it), and the resolveContextInjectionModeMock type in the shared test support file is stale.

Confidence Score: 5/5

Safe to merge; all findings are P2 style/test improvements that don't affect correctness.

No P0 or P1 issues found. The schema, types, and both runtime paths are consistent and correct. Remaining comments are about test coverage gaps and a semantic overload of isContinuationTurn that has no current downstream impact.

attempt.spawn-workspace.context-injection.test.ts and attempt.spawn-workspace.test-support.ts should be updated to include "never" in mock and helper types.

Comments Outside Diff (2)

  1. src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts, line 15 (link)

    P2 Missing "never" coverage in context-injection tests

    The resolveBootstrapContext helper's contextInjectionMode parameter type still only covers "always" | "continuation-skip", so there are no test cases exercising the new "never" path through resolveAttemptBootstrapContext. A case asserting that "never" skips the resolver call, returns empty files, and sets isContinuationTurn: true with shouldRecordCompletedBootstrapTurn: false would lock in the new behavior and catch regressions.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts
    Line: 15
    
    Comment:
    **Missing `"never"` coverage in context-injection tests**
    
    The `resolveBootstrapContext` helper's `contextInjectionMode` parameter type still only covers `"always" | "continuation-skip"`, so there are no test cases exercising the new `"never"` path through `resolveAttemptBootstrapContext`. A case asserting that `"never"` skips the resolver call, returns empty files, and sets `isContinuationTurn: true` with `shouldRecordCompletedBootstrapTurn: false` would lock in the new behavior and catch regressions.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test-support.ts, line 57 (link)

    P2 Mock type not updated for the new "never" value

    resolveContextInjectionModeMock is typed as Mock<() => "always" | "continuation-skip">, but resolveContextInjectionMode now returns the full AgentContextInjection union including "never". Any test that tries to set this mock to "never" will need a type assertion, and the divergence from the real signature is a latent footgun.

    The corresponding vi.fn initializer on line 111 would also need updating:

    const resolveContextInjectionModeMock = vi.fn<() => "always" | "continuation-skip" | "never">(
      () => "always",
    );
    
    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test-support.ts
    Line: 57
    
    Comment:
    **Mock type not updated for the new `"never"` value**
    
    `resolveContextInjectionModeMock` is typed as `Mock<() => "always" | "continuation-skip">`, but `resolveContextInjectionMode` now returns the full `AgentContextInjection` union including `"never"`. Any test that tries to set this mock to `"never"` will need a type assertion, and the divergence from the real signature is a latent footgun.
    
    
    
    The corresponding `vi.fn` initializer on line 111 would also need updating:
    ```
    const resolveContextInjectionModeMock = vi.fn<() => "always" | "continuation-skip" | "never">(
      () => "always",
    );
    ```
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts
Line: 15

Comment:
**Missing `"never"` coverage in context-injection tests**

The `resolveBootstrapContext` helper's `contextInjectionMode` parameter type still only covers `"always" | "continuation-skip"`, so there are no test cases exercising the new `"never"` path through `resolveAttemptBootstrapContext`. A case asserting that `"never"` skips the resolver call, returns empty files, and sets `isContinuationTurn: true` with `shouldRecordCompletedBootstrapTurn: false` would lock in the new behavior and catch regressions.

```suggestion
  contextInjectionMode?: "always" | "continuation-skip" | "never";
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test-support.ts
Line: 57

Comment:
**Mock type not updated for the new `"never"` value**

`resolveContextInjectionModeMock` is typed as `Mock<() => "always" | "continuation-skip">`, but `resolveContextInjectionMode` now returns the full `AgentContextInjection` union including `"never"`. Any test that tries to set this mock to `"never"` will need a type assertion, and the divergence from the real signature is a latent footgun.

```suggestion
  resolveContextInjectionModeMock: Mock<() => "always" | "continuation-skip" | "never">;
```

The corresponding `vi.fn` initializer on line 111 would also need updating:
```
const resolveContextInjectionModeMock = vi.fn<() => "always" | "continuation-skip" | "never">(
  () => "always",
);
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.context-engine-helpers.ts
Line: 31-35

Comment:
**`isContinuationTurn` overloaded with two distinct semantics**

Setting `isContinuationTurn = true` for `"never"` conflates two different reasons for skipping bootstrap injection: (1) we are on a safe continuation turn, and (2) injection is permanently disabled. While no current caller of `resolveAttemptBootstrapContext` reads `isContinuationTurn` downstream (only `shouldRecordCompletedBootstrapTurn`, `bootstrapFiles`, and `contextFiles` are destructured in `attempt.ts`), the overloaded meaning could mislead future callers. Consider tracking the reason separately (e.g., a dedicated `skipReason: "continuation" | "never" | undefined`) or at minimum adding a comment here explaining why `isContinuationTurn` doubles as the signal for the `"never"` mode.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Agents/bootstrap: add contextInjection '..." | Re-trigger Greptile

Comment thread src/agents/pi-embedded-runner/run/attempt.context-engine-helpers.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05ff1c5819

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/config/zod-schema.agent-defaults.ts
@obviyus obviyus force-pushed the feat/context-injection-never branch 4 times, most recently from 1048fe3 to cfc5f53 Compare April 25, 2026 05:40
@obviyus obviyus self-assigned this Apr 25, 2026
obviyus pushed a commit to xDarkicex/openclaw that referenced this pull request Apr 25, 2026
@obviyus obviyus force-pushed the feat/context-injection-never branch from cfc5f53 to be12455 Compare April 25, 2026 05:42
@obviyus obviyus force-pushed the feat/context-injection-never branch from be12455 to 83fed01 Compare April 25, 2026 05:45
Copy link
Copy Markdown
Contributor

@obviyus obviyus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the bootstrap config path: agents.defaults.contextInjection: "never" now skips workspace bootstrap injection in normal attempts and compaction without treating it as a continuation turn.

Maintainer follow-up: rebased onto latest main, kept generated runtime config schema aligned, added the active changelog entry, fixed the compact harness mock, and resolved the review-thread concerns.

Local gates: targeted context-injection/schema tests, compact sender-identity test, and pnpm check:base-config-schema.

@obviyus obviyus merged commit cc09925 into openclaw:main Apr 25, 2026
65 checks passed
@obviyus
Copy link
Copy Markdown
Contributor

obviyus commented Apr 25, 2026

Landed on main.

Thanks @xDarkicex.

vincentkoc added a commit that referenced this pull request Apr 25, 2026
…port

Two recent code changes lacked or had only partial doc coverage:

- contextInjection 'never' (#65006, xDarkicex): the new mode is now
  documented under agents.defaults.contextInjection, alongside the
  existing 'continuation-skip' mode, with guidance on when to use it
  (custom context engines, native runtimes that own their prompt).
- Nix Home Manager daemon PATH (#44402, jerome.benoit): document the
  service PATH auto-discovery (NIX_PROFILES right-to-left precedence
  and ~/.nix-profile/bin fallback) under the Nix install page.

Also sentence-case three Title-Cased headings on the Nix page ('What
You Get', 'Quick Start', 'Nix Mode Runtime Behavior') and drop a
duplicate body H1 that restated the frontmatter title.
Angfr95 pushed a commit to Angfr95/openclaw that referenced this pull request Apr 25, 2026
Angfr95 pushed a commit to Angfr95/openclaw that referenced this pull request Apr 25, 2026
…port

Two recent code changes lacked or had only partial doc coverage:

- contextInjection 'never' (openclaw#65006, xDarkicex): the new mode is now
  documented under agents.defaults.contextInjection, alongside the
  existing 'continuation-skip' mode, with guidance on when to use it
  (custom context engines, native runtimes that own their prompt).
- Nix Home Manager daemon PATH (openclaw#44402, jerome.benoit): document the
  service PATH auto-discovery (NIX_PROFILES right-to-left precedence
  and ~/.nix-profile/bin fallback) under the Nix install page.

Also sentence-case three Title-Cased headings on the Nix page ('What
You Get', 'Quick Start', 'Nix Mode Runtime Behavior') and drop a
duplicate body H1 that restated the frontmatter title.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants