Skip to content

fix: use default variant for update-task/update-subtask with --research flag#1692

Open
octo-patch wants to merge 1 commit into
eyaltoledano:nextfrom
octo-patch:fix/issue-1689-update-task-research-variant
Open

fix: use default variant for update-task/update-subtask with --research flag#1692
octo-patch wants to merge 1 commit into
eyaltoledano:nextfrom
octo-patch:fix/issue-1689-update-task-research-variant

Conversation

@octo-patch

@octo-patch octo-patch commented Apr 23, 2026

Copy link
Copy Markdown

Fixes #1689

Problem

When running task-master update-task --id=<n> --research --prompt="...", the command crashes immediately with:

[ERROR] Failed to load prompt update-task: Cannot read properties of undefined (reading 'replace')

The same error also affects update-subtask --research.

Root cause: Both update-task-by-id.js and update-subtask-by-id.js computed variantKey = 'research' when useResearch is true. However, neither update-task.json nor update-subtask.json define a 'research' variant (only expand-task.json does). Accessing template.prompts['research'] returns undefined, so spreading it produces {} with no system or user keys — causing renderTemplate(undefined, …) to crash.

Solution

Use the 'default' variant in both files when useResearch is true. The default variant in both templates already contains {{#if useResearch}} / {{#if (not useResearch)}} Handlebars conditionals that produce the appropriate research-aware prompt. No changes to the prompt templates are needed.

  • update-task-by-id.js: simplified variantKey selection to appendMode ? 'append' : 'default'
  • update-subtask-by-id.js: simplified to always 'default'

Testing

  • Added a regression test in update-task-by-id.test.js that verifies loadPrompt is called with 'default' (not 'research') when useResearch is true.
  • All existing tests continue to pass (npm test -- --testPathPattern=update-task-by-id: 13/13 passing).
  • npm run format-check passes (biome reports no issues).

Note

Low Risk
Low risk: this is a small change to prompt variant selection to avoid loading a non-existent template variant, plus a regression test to lock the behavior in.

Overview
Fixes update-task and update-subtask crashing when run with --research by stopping use of a non-existent research prompt variant and always loading the default variant (while still using the research AI role when requested). Adds a regression unit test to assert update-task calls loadPrompt with default when useResearch is true, and includes a patch changeset documenting the fix.

Reviewed by Cursor Bugbot for commit 9b24e71. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed crash occurring when task and subtask update commands are invoked with research mode enabled. Commands now use the correct prompt template variant to avoid undefined reference errors.
  • Tests

    • Added regression test to verify proper prompt variant selection when research mode is enabled during task updates.

…ch flag (fixes eyaltoledano#1689)

The update-task and update-subtask commands were requesting a non-existent
'research' prompt variant. When useResearch is true they now use the 'default'
variant, which already contains {{#if useResearch}} conditionals to render
research-specific content, avoiding a crash: "Cannot read properties of
undefined (reading 'replace')".

Also adds a regression test to prevent recurrence.
@changeset-bot

changeset-bot Bot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9b24e71

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request fixes a bug where update-task and update-subtask commands crashed when invoked with the --research flag. The fix removes attempts to load a non-existent 'research' prompt variant, instead always loading the 'default' variant while preserving research mode functionality through template conditionals.

Changes

Cohort / File(s) Summary
Bug Fix - Task/Subtask Prompt Variant Selection
scripts/modules/task-manager/update-task-by-id.js, scripts/modules/task-manager/update-subtask-by-id.js
Changed prompt variant logic from conditionally selecting 'research' based on useResearch flag to consistently using 'default' variant. Research mode behavior is preserved through existing template conditionals rather than variant switching.
Test & Documentation
tests/unit/scripts/modules/task-manager/update-task-by-id.test.js, .changeset/fix-update-task-research-variant.md
Added regression test verifying updateTaskById loads 'default' variant when useResearch flag is true. Documented fix in changeset entry for task-master-ai package.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • eyaltoledano
  • Crunchyman-ralph
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: use default variant for update-task/update-subtask with --research flag' directly and specifically describes the main change—fixing a crash by switching to the default variant when using the --research flag.
Linked Issues check ✅ Passed The PR fully addresses the coding requirements in issue #1689: it fixes the crash when using --research flag by ensuring the 'default' variant is used instead of the non-existent 'research' variant, while preserving research-aware behavior through template conditionals.
Out of Scope Changes check ✅ Passed All changes are directly within scope: modifications to update-task-by-id.js and update-subtask-by-id.js fix the variant selection bug, the changeset documents the fix, and the test validates the fix—no unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
scripts/modules/task-manager/update-subtask-by-id.js (1)

305-310: Fix is correct; consider adding a symmetric regression test for update-subtask.

Forcing variantKey = 'default' resolves the crash, and the update-subtask.json default template already handles useResearch via {{#if useResearch}} conditionals, so research-backed output is preserved. The AI service role on line 312 correctly remains tied to useResearch.

Only update-task-by-id.test.js gained a regression test — it would be worth mirroring it for update-subtask-by-id.js so a future refactor doesn't silently reintroduce a missing-variant lookup here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/modules/task-manager/update-subtask-by-id.js` around lines 305 - 310,
Add a symmetric regression test for update-subtask to mirror
update-task-by-id.test.js: create a new test (e.g.,
update-subtask-by-id.test.js) that simulates the missing-variant lookup on
promptManager.loadPrompt for update-subtask and asserts the handler in
update-subtask-by-id.js completes without throwing and preserves research-backed
output (exercise the {{`#if` useResearch}} path); stub/mock
promptManager.loadPrompt and AI service role to reproduce the original crash
case and verify variantKey falls back to 'default' and behavior matches the
existing update-task test expectations.
tests/unit/scripts/modules/task-manager/update-task-by-id.test.js (1)

688-741: Good regression test; consider also asserting useResearch flows into promptParams.

The test correctly locks in the 'default' variant key for useResearch: true. As a low-cost hardening, also assert that promptParams.useResearch === true is passed — that would catch a future regression where the variant is still 'default' but useResearch is accidentally dropped from the params (which would break the template's {{#if useResearch}} branches and silently lose research behavior).

♻️ Optional hardening
 		const promptManagerInstance = getPromptManager.mock.results[0].value;
 		const loadPromptCall = promptManagerInstance.loadPrompt.mock.calls[0];
 		expect(loadPromptCall[2]).toBe('default');
+		// Guard against useResearch being dropped from promptParams, which would
+		// silently disable the {{`#if` useResearch}} branches inside the 'default' template.
+		expect(loadPromptCall[1]).toEqual(
+			expect.objectContaining({ useResearch: true })
+		);
 	});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/scripts/modules/task-manager/update-task-by-id.test.js` around
lines 688 - 741, Add an assertion that the prompt parameters include
useResearch=true so the template sees the flag: after retrieving
promptManagerInstance and loadPromptCall (as in the existing test where
loadPromptCall[2] is the variant), check that loadPromptCall[3].useResearch ===
true (or the correct argument index for promptParams in loadPrompt calls) to
ensure updateTaskById passes useResearch into promptParams when calling
getPromptManager().loadPrompt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@scripts/modules/task-manager/update-subtask-by-id.js`:
- Around line 305-310: Add a symmetric regression test for update-subtask to
mirror update-task-by-id.test.js: create a new test (e.g.,
update-subtask-by-id.test.js) that simulates the missing-variant lookup on
promptManager.loadPrompt for update-subtask and asserts the handler in
update-subtask-by-id.js completes without throwing and preserves research-backed
output (exercise the {{`#if` useResearch}} path); stub/mock
promptManager.loadPrompt and AI service role to reproduce the original crash
case and verify variantKey falls back to 'default' and behavior matches the
existing update-task test expectations.

In `@tests/unit/scripts/modules/task-manager/update-task-by-id.test.js`:
- Around line 688-741: Add an assertion that the prompt parameters include
useResearch=true so the template sees the flag: after retrieving
promptManagerInstance and loadPromptCall (as in the existing test where
loadPromptCall[2] is the variant), check that loadPromptCall[3].useResearch ===
true (or the correct argument index for promptParams in loadPrompt calls) to
ensure updateTaskById passes useResearch into promptParams when calling
getPromptManager().loadPrompt.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7a553e35-3f4b-4b57-b2d2-36ac390e3967

📥 Commits

Reviewing files that changed from the base of the PR and between 487c3d3 and 9b24e71.

📒 Files selected for processing (4)
  • .changeset/fix-update-task-research-variant.md
  • scripts/modules/task-manager/update-subtask-by-id.js
  • scripts/modules/task-manager/update-task-by-id.js
  • tests/unit/scripts/modules/task-manager/update-task-by-id.test.js

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