Skip to content

feat: add default injection toggle and managed fallback plugin discovery#2122

Open
SupenBysz wants to merge 7 commits intocode-yeongyu:devfrom
SupenBysz:feat/default-injection-toggle-stack
Open

feat: add default injection toggle and managed fallback plugin discovery#2122
SupenBysz wants to merge 7 commits intocode-yeongyu:devfrom
SupenBysz:feat/default-injection-toggle-stack

Conversation

@SupenBysz
Copy link

@SupenBysz SupenBysz commented Feb 25, 2026

Summary

  • add top-level default_injection_toggle config field and wire it into transform hook creation
  • gate contextInjectorMessagesTransform by config while preserving default-enabled behavior
  • inject a managed default plugin entry when installed_plugins.json is missing
  • add focused tests for transform-hook gating and plugin discovery fallback behavior

Dependency Note

This branch is stacked on top of #2119 because it depends on its regression baseline.
While #2119 is open, this PR includes those base commits in GitHub history view.
Review focus for this PR: 325e0016, 01c79e3e, c9af780b.

Validation

  • bun test src/shared/model-error-classifier.test.ts src/hooks/model-fallback/hook.test.ts src/plugin/event.model-fallback.test.ts src/cli/model-fallback.test.ts src/hooks/session-notification.test.ts src/hooks/session-notification-input-needed.test.ts src/plugin/tool-execute-before-session-notification.test.ts src/cli/mcp-oauth/login.test.ts src/plugin-config.test.ts src/plugin/hooks/create-transform-hooks.test.ts src/features/claude-code-plugin-loader/discovery.test.ts
  • bun run typecheck
  • bun run build

Result:

  • tests: 87 pass / 0 fail
  • typecheck: pass
  • build: pass

Risk

  • localized behavior changes in config merge / transform hook gating / plugin discovery fallback
  • no API shape changes

Rollback

Revert PR-scoped files and rerun the same validation chain.


Summary by cubic

Adds a toggle to enable/disable default context injection and injects a managed default plugin when no plugin database is found, improving first-run reliability and control over message transforms. Stabilizes fallback provider selection, fixes session-notification state leakage, and syncs GitLab-style delivery docs to the ktai roadmap milestones.

  • New Features

    • Added default_injection_toggle config; gates contextInjectorMessagesTransform (default: enabled).
    • Inject managed default plugin when installed_plugins.json is missing.
  • Bug Fixes

    • Prefer current provider during first-hop fallback to keep selection stable.
    • Clear pending state in session-notification command finder to avoid cross-test leakage.
    • Added focused tests for hook gating and plugin discovery fallback.

Written for commit 0286a78. Summary will update on new commits.

SupenBysz and others added 6 commits February 26, 2026 04:42
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@SupenBysz
Copy link
Author

Milestone alignment update (issue/work-order):

  • M2 = Configurable injection + managed default plugin fallback (this PR)
  • dependency: M1 baseline PR #2119
  • merge order: M1 -> M2

M2 gate checklist:

  • extended tests/typecheck/build: pass locally
  • CI checks: wait for all green
  • post-M1 action: re-run verification on top of updated dev if needed before merge

Plan source: docs/guide/gitlab-issue-regression-delivery-plan.md (milestone section).

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 13 files

Confidence score: 3/5

  • Potential memory leak in src/plugin/hooks/create-transform-hooks.ts: when default_injection_toggle is disabled, producer hooks may still register without the consumer injector, risking uncollected resources.
  • This carries some runtime risk despite being a single issue, so merge confidence is moderate rather than high.
  • Pay close attention to src/plugin/hooks/create-transform-hooks.ts - ensure hooks are created/cleaned consistently when the injection toggle is off.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/plugin/hooks/create-transform-hooks.ts">

<violation number="1" location="src/plugin/hooks/create-transform-hooks.ts:58">
P1: Potential memory leak: when `default_injection_toggle` is disabled, the context injector transform hook (consumer) is not created, but other hooks like `claudeCodeHooks` and `keywordDetector` (producers) may still register context data to the shared `contextCollector` singleton. Without the consumer to call `consume()` and clear the sessions Map, state will accumulate unbounded over time.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


const contextInjectorMessagesTransform =
createContextInjectorMessagesTransformHook(contextCollector)
const contextInjectorMessagesTransform = isContextInjectionEnabled
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 26, 2026

Choose a reason for hiding this comment

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

P1: Potential memory leak: when default_injection_toggle is disabled, the context injector transform hook (consumer) is not created, but other hooks like claudeCodeHooks and keywordDetector (producers) may still register context data to the shared contextCollector singleton. Without the consumer to call consume() and clear the sessions Map, state will accumulate unbounded over time.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/plugin/hooks/create-transform-hooks.ts, line 58:

<comment>Potential memory leak: when `default_injection_toggle` is disabled, the context injector transform hook (consumer) is not created, but other hooks like `claudeCodeHooks` and `keywordDetector` (producers) may still register context data to the shared `contextCollector` singleton. Without the consumer to call `consume()` and clear the sessions Map, state will accumulate unbounded over time.</comment>

<file context>
@@ -52,8 +55,13 @@ export function createTransformHooks(args: {
 
-  const contextInjectorMessagesTransform =
-    createContextInjectorMessagesTransformHook(contextCollector)
+  const contextInjectorMessagesTransform = isContextInjectionEnabled
+    ? safeCreateHook(
+        "context-injector",
</file context>
Fix with Cubic

@SupenBysz
Copy link
Author

Milestone execution note:\n\n- M2 target: merge after M1 (#2119) is merged.\n- This PR is intentionally stacked on top of the M1 baseline.\n- I cannot request reviewers or merge from this account due repository permission limits.\n\nMaintainer action needed:\n1) Merge #2119\n2) Re-check #2122 diff on latest dev\n3) Merge #2122\n\nCurrent local verification for this PR scope is complete (tests/typecheck/build).

@SupenBysz
Copy link
Author

Milestone source-of-truth synced from GitLab :\n\n- M0-Architecture-and-UX-Freeze (2026-02-26 -> 2026-03-04)\n- M1-Desktop-OEM-Alpha (2026-03-05 -> 2026-03-19)\n- M2-Mobile-Realtime-MVP (2026-03-20 -> 2026-04-02)\n- M3-Security-and-Beta (2026-04-03 -> 2026-04-16)\n\nThis PR is aligned to M1 and keeps stack dependency order: #2119 -> #2122.

@SupenBysz
Copy link
Author

Milestone source-of-truth synced from GitLab group ktai:

  • M0-Architecture-and-UX-Freeze (2026-02-26 -> 2026-03-04)
  • M1-Desktop-OEM-Alpha (2026-03-05 -> 2026-03-19)
  • M2-Mobile-Realtime-MVP (2026-03-20 -> 2026-04-02)
  • M3-Security-and-Beta (2026-04-03 -> 2026-04-16)

This PR is aligned to desktop M1 issue #5 (OEM default integration + disable strategy) and keeps stack dependency order: #2119 -> #2122.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@SupenBysz
Copy link
Author

Execution-ready milestone gate status:

Maintainer runbook:

  1. Merge fix: stabilize fallback/notification regressions and add issue delivery docs #2119 into dev
  2. Rebase/refresh feat: add default injection toggle and managed fallback plugin discovery #2122 on latest dev if required by branch protection
  3. Merge feat: add default injection toggle and managed fallback plugin discovery #2122
  4. Trigger M3 closure verification on dev (targeted tests + typecheck + build)

I can execute step 4 immediately after the merges are done.

@SupenBysz
Copy link
Author

Unblock option added: integrated PR #2123 now contains M1+M2 combined on latest dev baseline. Maintainer can merge #2123 directly if sequential merge flow is blocked.

@SupenBysz
Copy link
Author

Milestone path update: integrated PR #2123 is now fully green and merge-ready. If maintainers choose the single-merge path, #2122 can be treated as superseded reference for M2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant