Repository navigation
CTX7-4100: Return an MCP task from the code tools while a code index is built - #3944
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
… and follow the Tasks spec errors
…bind tasks to verified owners
f773b33 to
cef3d14
Compare
There was a problem hiding this comment.
To fix on commit cef3d14 before this PR is ready:
- [major] Public docs still say the code tools never make the agent wait; the new self-hosting env vars are not documented (
docs/howto/experimental-tools.mdx:161) - [minor] checkGate skips the version normalisation fetchLibraryCode does, so one library version can get several gates (
packages/mcp/src/lib/code-task.ts:500) - [minor] A transient failure on the poll after the 30-minute wait ends the task with an error, not the promised 'being indexed' text (
packages/mcp/src/lib/code-tools.ts:655) - [minor] Results delivered through tasks/get are not recorded in tool-call telemetry (
packages/mcp/src/lib/code-tools.ts:652) - [minor] "Unknown task" lookup-and-throw repeated in three handlers (
packages/mcp/src/lib/code-tools.ts:646) - [minor] Task lifecycle logic is split between code-task.ts and code-tools.ts (
packages/mcp/src/lib/code-tools.ts:636) - [minor] MemoryCodeTaskStore.put evicts gates, but gates are added in claimCheck (
packages/mcp/src/lib/code-task.ts:441) - [minor] Unused default value for the new codeTaskStore parameter (
packages/mcp/src/lib/experimental-tools.ts:780)
Full review in the PR comment · Context7 Ops
💬 Not approved yetFor MCP clients that support Tasks, such as Claude Code, the code tools now return a task while a library's source is indexed. The agent gets the real result when the index is ready, for up to 30 minutes. Other clients see the same text as before. Not approved because a lockfile changed; the bot cannot verify resolved URLs or integrity hashes; it changes security-sensitive code; it is a large change. A person reviews this PR. Details: findings, what changes, screenshots, API responsesWhat changes
Commit Checks: risk, security, maintainability. Model anthropic/claude-opus-5.5, about $0.07. Ask Context7 Ops in Slack for more pages, a question about the code or a rerun. |
…rd task outcomes, and move the task lifecycle to code-task.ts
|
Docs7 for context7.com
Commit |
There was a problem hiding this comment.
To fix on commit ba1b9d9 before this PR is ready:
- [minor] A transient failure after the 30-minute wait releases the version's gate as if the index were done (
packages/mcp/src/lib/code-task.ts:319) - [minor] A task-backed call that is never polled to completion is never recorded in telemetry (
packages/mcp/src/lib/code-tools.ts:430)
Full review in the PR comment · Context7 Ops
No blocking findings on commit ba1b9d9.
…d tools/call outcomes at call time
There was a problem hiding this comment.
To fix on commit d3aa514 before this PR is ready:
- [minor] A tool call that becomes a task is counted twice as an authenticated tool call (
packages/mcp/src/lib/code-task.ts:324)
Full review in the PR comment · Context7 Ops
…l sends one auth event
There was a problem hiding this comment.
No findings on commit e439354. A person gives the final approval because a lockfile changed; the bot cannot verify resolved URLs or integrity hashes; it changes security-sensitive code; it is a large change.
Full review in the PR comment · Context7 Ops
ramazanoacar
left a comment
There was a problem hiding this comment.
Thanks Fahreddin, this is a solid piece of work. Here's what I went through:
- Task binding and storage: tasks are bound by
callerBinding, so only a verified OAuth user stands for a refreshed token, and another caller gets the same "Unknown task" error as an unknown ID. Redis holds the request and a hash of the caller, never the credential. - The gate: one gate per caller and library version (normalised the way
fetchLibraryCodereads it) keeps parallel greps and globs inside the poll pass. Only a finished index opens it, so a timeout after the wait doesn't release it for the other tasks. - Redis scripts: they make the first final status win, so a cancel that lands during the API request is answered from the store.
- Fallbacks: a client without the extension, a 2025-era request, or a server without a store gets the same text as today. A store failure while creating the task falls back to that text too.
- Lockfile: it only adds
@upstash/redis@1.41.0and its one dependency,uncrypto@0.1.3.
Approving.
Small notes (non-blocking)
UPSTASH_REDIS_REST_URL/UPSTASH_REDIS_REST_TOKENare the SDK's default names, and the Vercel and Upstash integrations set exactly these. A self-hosted server that already has them for another database would start writingmcp:code-task:*keys there and advertising tasks without anyone choosing it. A prefixed pair (e.g.CONTEXT7_TASKS_REDIS_REST_URL/_TOKEN) would make it opt-in. If you keep the names, a line in the self-hosting docs saying that setting them turns tasks on would help.tasks/*are registered only on a server built with the code tools on. If a user turns the code tools off in the dashboard while a task is running, the nexttasks/getgets method-not-found rather than "Unknown task". Clients should handle both the same, so this is just something to know.- A completed task answers from the record without the API, so a key revoked within the hour can still read the result of a call it was allowed to make. That seems fine for an hour-long TTL; I'm mentioning it so it's a known choice.
…rver's Redis store
ramazanoacar
left a comment
There was a problem hiding this comment.
Thanks Fahreddin, moving the task into the API is a good call. The server is stateless again, my note about the UPSTASH_REDIS_* names no longer applies, and the lockfile change is gone. I read the two new commits against the app-side change (merged):
- Access: each poll replays the stored request with the poller's own credential, and a stored answer is served again only after the access check. The revoked-key case from my last note is covered now too.
- Task ownership: the app treats another caller's task as unknown, which matches the
-32602here. - Cutoff: the app always sends
X-Context7-Task-Createdon a poll, so the 30-minute cutoff works from the real creation time. - Rate limits: a 429
rate_limitedkeeps the task waiting. Without the gate, that's what keeps a busy poller from ending its task early.
Approving.
Small notes (non-blocking)
cancelCodeTasktreats every answer other than 404 and 410 as done, including a 5xx, a 429 or a timeout. A cancel that didn't reach the API returns{}, and the nexttasks/getstill saysworking. Throwing an internal error when the DELETE isn'tok(or at least logging it) would let the client know.- If a poll ever comes back without
X-Context7-Task-Created,createdAtfalls back to now on every poll, so the 30-minute cutoff never fires. The app always sends it today. Falling back toCODE_TASK_TTL_MSworth of polls isn't possible without state, so a short comment that the header is required would protect it.
While a library's source is being indexed, the code tools answer with an MCP task for clients that declare the Tasks extension, so the client waits for the index and the agent gets the real result.
io.modelcontextprotocol/tasksasks/v2/codefor a task (task=1); a 202 that names one becomes aresultType: "task"answer. Every other answer and every other client stays as before.tasks/getpolls/v2/code/tasks/{id}with the poll's own credential,tasks/canceldeletes it. The server keeps no state and needs no new setup; an API without tasks names none, and the call answers with text.index_pendingends it with the API's text (not an error, for tasks and plain calls alike); after 30 minutes without an index it ends with the usual "being indexed" text.tasks/*answer-32021without the capability and-32602for an unknown task.get-upgrade-guideanddiff-code.Closes CTX7-4100