Skip to content

Make MCP development task creation reliable - #173

Merged
mikepsinn merged 4 commits into
mainfrom
feature/mcp-development-task-discovery
Aug 1, 2026
Merged

Make MCP development task creation reliable#173
mikepsinn merged 4 commits into
mainfrom
feature/mcp-development-task-discovery

Conversation

@mikepsinn

@mikepsinn mikepsinn commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Why

An AI agent asked to record an Optimitron improvement could not reliably find the canonical development parent. searchTasks required every natural-language term to match, while createTask required the parent's opaque database ID. That combination encourages orphaned tasks, duplicate tasks, or no task at all instead of keeping development work in the EV-ranked Optimitron queue.

What changed

  • make natural multi-word task searches tolerant of request-framing words while preserving bounded candidate retrieval
  • guarantee exact stable task-key matches with an indexed fast path and explicit relevance boost
  • let createTask resolve either parentTaskId or an exact parentTaskKey, with the same account and OAuth-client access boundaries
  • teach MCP clients the canonical optimitron:dev search, deduplication, and creation flow
  • repair the MCP guide's previously invalid createTask example and add a valid development-task example
  • add regressions for natural search, exact-key priority, MCP dispatch, ambiguous parent inputs, root protection, and OAuth-boundary enforcement

Validation

  • vitest: 276 focused tests passed after rebasing onto current main
  • tsc --noEmit --project tsconfig.next.json
  • tsc --noEmit --project tsconfig.tests.json
  • git diff --check

No UI surfaces changed, so screenshot review is not applicable.

Summary by CodeRabbit

  • New Features

    • Create and update tasks using either a parent ID or exact parent key.
    • Improved task search supports exact task-key matching, more relevant multi-word results, and clearer filtering.
    • Added guidance for discovering and managing development tasks under the optimitron:dev root.
  • Bug Fixes

    • Strengthened access checks and validation for task parents and search results.
    • Prevented invalid, duplicate, inaccessible, or circular task relationships.

Copilot AI review requested due to automatic review settings August 1, 2026 00:40
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
optimitron-web Ready Ready Preview Aug 1, 2026 1:29am

@mikepsinn
mikepsinn force-pushed the feature/mcp-development-task-discovery branch from d0104b9 to acb4b3a Compare August 1, 2026 00:41
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The MCP task workflow now supports exact parent keys, improved task search, and optimitron:dev discovery. Validation enforces access boundaries, parent exclusivity, reserved-root rules, and resolved parent persistence.

Changes

Task discovery and parenting

Layer / File(s) Summary
Task search filtering and ranking
packages/web/src/lib/tasks.server.ts, packages/web/src/lib/__tests__/tasks.server.test.ts, packages/web/src/lib/__tests__/mcp-server.test.ts
Search ignores request-framing terms, requires distinctive-term matches, limits candidates to 64, preserves access filters, and prioritizes exact task-key matches.
Parent selection and persistence
packages/web/src/lib/mcp-server.ts, packages/web/src/lib/__tests__/mcp-server.test.ts
Task creation and updates accept one parent ID or key, validate client access, reject reserved roots, and persist the resolved parent ID.
Optimitron development guidance and contracts
packages/web/src/lib/mcp-instructions.ts, packages/web/src/lib/mcp-server.ts, packages/web/src/lib/__tests__/mcp-tool-catalog.test.ts, docs/MCP_SERVER.md
Instructions and schemas document optimitron:dev, parent-key discovery, duplicate checks, failure handling, and current task fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant MCPServer
  participant TasksServer
  participant TaskDatabase
  MCPClient->>MCPServer: Search for a parent or duplicate task
  MCPServer->>TasksServer: Apply query, visibility, status, and client boundary
  TasksServer->>TaskDatabase: Retrieve and rank task candidates
  TaskDatabase-->>TasksServer: Return matching tasks
  TasksServer-->>MCPServer: Return ordered results
  MCPClient->>MCPServer: Create task with parentTaskKey
  MCPServer->>TaskDatabase: Resolve accessible parentTaskKey
  TaskDatabase-->>MCPServer: Return resolved parent task ID
  MCPServer->>TaskDatabase: Persist child task with parent task ID
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: improving the reliability of MCP development task creation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/mcp-development-task-discovery

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.

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

Copy link
Copy Markdown

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: d0104b94fd

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/web/src/lib/tasks.server.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves reliability of Optimitron MCP task discovery and creation by making task search more tolerant of natural-language framing, adding an exact task-key fast path/boost, and allowing MCP createTask to resolve parents via either an opaque ID or an exact stable task key (with OAuth/client-access boundaries enforced).

Changes:

  • Updated searchTasks to OR-match distinctive terms (dropping request-framing words) while bounding candidate retrieval, and to prioritize exact stable taskKey matches.
  • Extended MCP createTask parent resolution to accept parentTaskId or parentTaskKey, with validation for ambiguous inputs and boundary enforcement.
  • Updated MCP instructions/docs and added regression tests covering the new search and parent-resolution behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/web/src/lib/tasks.server.ts Adjusts task search term handling, adds exact-key fast path/boost, and changes candidate retrieval strategy for relevance ranking.
packages/web/src/lib/mcp-server.ts Allows createTask to resolve parent by stable key, enforces OAuth/client-access boundaries, and tightens parent validation rules.
packages/web/src/lib/mcp-instructions.ts Updates first-run MCP client guidance to direct agents toward optimitron:dev and the new parent-key workflow.
packages/web/src/lib/tests/tasks.server.test.ts Adds/updates regressions for OR-ranked term search and exact-key prioritization behavior.
packages/web/src/lib/tests/mcp-tool-catalog.test.ts Ensures the MCP instruction string continues to mention how to target the canonical dev root.
packages/web/src/lib/tests/mcp-server.test.ts Adds regressions for tool dispatch, parent-key resolution, ambiguous-parent rejection, and client-boundary enforcement.
docs/MCP_SERVER.md Fixes/extends MCP guide examples and adds a documented Optimitron development task creation flow.
Suppressed comments (1)

packages/web/src/lib/tests/mcp-tool-catalog.test.ts:60

  • This test currently enshrines the ambiguous parentTaskKey "optimitron:dev" phrasing from MCP_SERVER_INSTRUCTIONS. If the instructions are updated to the clearer parentTaskKey='optimitron:dev' form, this assertion should be updated to match so the catalog test continues validating the intended guidance.
        : undefined,
    ).toEqual(["taskId", "completionEvidence"]);
    expect(completeClaim?.description).toContain(

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/web/src/lib/tasks.server.ts Outdated
Comment thread packages/web/src/lib/mcp-instructions.ts Outdated
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR review packet

Start here

  • 🖼️ Visual review
  • ⚠️ Screenshot baseline fallback: main@6bdd72b89377 from CI run 30675393243; exact PR base main@69d5f69e3c8b had no usable artifact.
  • 🚀 Preview deployment
  • ☝️ Cmd/Ctrl-click review links to keep this PR open.
  • 🔑 ?login=demo signs in as the demo user; ?logout=1 clears the session.
  • 💬 For a visual problem, use the comment button in latest.html or reply here with @claude and the checklist item.

No user-facing page or component changes were inferred from changed files or the visual review manifest.

Changed files considered
  • docs/MCP_SERVER.md
  • packages/web/src/lib/__tests__/mcp-server.test.ts
  • packages/web/src/lib/__tests__/mcp-tool-catalog.test.ts
  • packages/web/src/lib/__tests__/tasks.server.test.ts
  • packages/web/src/lib/mcp-instructions.ts
  • packages/web/src/lib/mcp-server.ts
  • packages/web/src/lib/tasks.server.ts

Updated automatically when this PR's preview or visual review reruns.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/web/src/lib/mcp-server.ts (1)

14858-14894: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Write-conflict replay check does not recognize parentTaskKey requests.

At Line 14884, the idempotency check compares existingTask.parentTaskId === optionalString(a.parentTaskId). When the original createTask call supplied parentTaskKey instead of parentTaskId, a.parentTaskId is undefined, but existingTask.parentTaskId holds the real resolved ID string. The comparison always fails for parentTaskKey requests, so a retried call after a unique-constraint race never matches the replay condition.

The pre-creation duplicate check earlier in the same case block (around Line 10958) avoids this by comparing against the resolved parentTaskId local variable. That variable is scoped to the createTask case block and is not visible in this shared catch handler, which is why the catch block reads the raw request field instead.

Resolve the request's parent reference the same way before comparing, so retries using parentTaskKey get the correct idempotent-replay result instead of a spurious WRITE_CONFLICT.

🔧 Proposed fix
+              const requestedParentTaskId = optionalString(a.parentTaskId);
+              const requestedParentTaskKey = optionalString(a.parentTaskKey);
+              const resolvedRequestedParentId =
+                requestedParentTaskId ??
+                (requestedParentTaskKey
+                  ? (
+                      await prisma.task.findFirst({
+                        where: {
+                          deletedAt: null,
+                          taskKey: requestedParentTaskKey,
+                        },
+                        select: { id: true },
+                      })
+                    )?.id
+                  : undefined);
               if (
                 existingTask?.taskKey === taskKey &&
                 existingTask.title === optionalString(a.title) &&
-                existingTask.parentTaskId === optionalString(a.parentTaskId)
+                existingTask.parentTaskId === resolvedRequestedParentId
               ) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/web/src/lib/mcp-server.ts` around lines 14858 - 14894, Update the
write-conflict replay check in the shared handler around createTaskReplayResult
to resolve the request’s parent reference through the same
parentTaskKey/parentTaskId lookup used by the createTask flow before comparing
it with existingTask.parentTaskId. Use the resolved parent ID for both request
forms, while preserving the existing title and task-key comparisons and replay
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/web/src/lib/mcp-server.ts`:
- Around line 14858-14894: Update the write-conflict replay check in the shared
handler around createTaskReplayResult to resolve the request’s parent reference
through the same parentTaskKey/parentTaskId lookup used by the createTask flow
before comparing it with existingTask.parentTaskId. Use the resolved parent ID
for both request forms, while preserving the existing title and task-key
comparisons and replay behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a0a013b-a8bf-482e-a96d-f34faaecc5e3

📥 Commits

Reviewing files that changed from the base of the PR and between 69d5f69 and a6daa03.

📒 Files selected for processing (7)
  • docs/MCP_SERVER.md
  • packages/web/src/lib/__tests__/mcp-server.test.ts
  • packages/web/src/lib/__tests__/mcp-tool-catalog.test.ts
  • packages/web/src/lib/__tests__/tasks.server.test.ts
  • packages/web/src/lib/mcp-instructions.ts
  • packages/web/src/lib/mcp-server.ts
  • packages/web/src/lib/tasks.server.ts

@mikepsinn
mikepsinn merged commit 5136a84 into main Aug 1, 2026
23 checks passed
@mikepsinn
mikepsinn deleted the feature/mcp-development-task-discovery branch August 1, 2026 16:18
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.

2 participants