Skip to content

feat(keyword-detector): prevent ultrawork instruction injection on every trigger#3433

Open
linuxtopia wants to merge 1 commit intocode-yeongyu:devfrom
linuxtopia:dev
Open

feat(keyword-detector): prevent ultrawork instruction injection on every trigger#3433
linuxtopia wants to merge 1 commit intocode-yeongyu:devfrom
linuxtopia:dev

Conversation

@linuxtopia
Copy link
Copy Markdown

@linuxtopia linuxtopia commented Apr 14, 2026

Summary

  • Prevent ultrawork keyword detector from injecting ~3K tokens of instruction text on every trigger
  • Added session-level cache to detect when ultrawork mode is already active
  • Returns early on subsequent keyword matches, avoiding redundant instruction injection
  • Preserves the initial toast notification while blocking duplicate injections

Context


Summary by cubic

Stops repeated ultrawork instruction injection to avoid ~3K token bloat on every trigger. Adds per-session mode tracking so ultrawork (and other modes) activate once and skip reinjection. Addresses Linear #2076.

  • Bug Fixes
    • Added a session-level cache (Map<sessionID, Set<modeType>>) to track active modes.
    • Skips reinjection when a mode is already active; preserves the initial toast.
    • Removed text-part instruction injection; logs “Mode activated (no injection)” and returns early.

Written for commit da80a7e. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign the CLA, please comment on this PR with:

I have read the CLA Document and I hereby sign the CLA

This is a one-time requirement. Once signed, all your future contributions will be automatically accepted.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@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 1 file

Confidence score: 2/5

  • There is a high-confidence functional regression in src/hooks/keyword-detector/hook.ts: removing instruction injection means mode prompts are never injected.
  • Because this affects core prompt behavior (severity 8/10, confidence 10/10), the risk of user-facing breakage is significant and this is not a routine minor issue.
  • Pay close attention to src/hooks/keyword-detector/hook.ts - restore and verify instruction injection so mode prompts are applied correctly.
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/hooks/keyword-detector/hook.ts">

<violation number="1" location="src/hooks/keyword-detector/hook.ts:158">
P1: The instruction injection logic has been entirely removed, preventing mode prompts from ever being injected.</violation>
</file>

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

output.parts[textPartIndex].text = `${allMessages}\n\n---\n\n${originalText}`

log(`[keyword-detector] Detected ${detectedKeywords.length} keywords`, {
log(`[keyword-detector] Mode activated (no injection)`, {
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 14, 2026

Choose a reason for hiding this comment

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

P1: The instruction injection logic has been entirely removed, preventing mode prompts from ever being injected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/hooks/keyword-detector/hook.ts, line 158:

<comment>The instruction injection logic has been entirely removed, preventing mode prompts from ever being injected.</comment>

<file context>
@@ -120,24 +153,13 @@ export function createKeywordDetectorHook(
-      output.parts[textPartIndex].text = `${allMessages}\n\n---\n\n${originalText}`
-
-      log(`[keyword-detector] Detected ${detectedKeywords.length} keywords`, {
+      log(`[keyword-detector] Mode activated (no injection)`, {
         sessionID: input.sessionID,
         types: detectedKeywords.map((k) => k.type),
</file context>
Fix with Cubic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is intentional. The goal is to remove the ~3K token instruction injection entirely. Ultrawork mode activation is handled by the keyword detection itself, not by injected instruction text. Mode prompts are not required for the mode to function correctly - they were previously informational only.

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