Repository navigation
Commit 28b41c3
committed
feat(mcp): opt-in async index_repository with status polling (DeusData#2144)
index_repository blocks until the whole index completes. MCP clients with
a per-call deadline (Copilot for IntelliJ) give up on a large repository;
their cancel drops the daemon job's last subscriber, the daemon cancels
the worker, and every retry starts over, so the index never finishes.
Add an opt-in async mode and a status query to the same tool; the default
synchronous behaviour is unchanged:
- async: true starts the project's index job in the daemon, or joins the
one already running for it, and returns at once with its state. The
application holds one subscriber reference for an async job until its
terminal publish, so the request returning, the client cancelling or
the starting session closing no longer cancels it. Only daemon shutdown
(or the final session of a non-permanent generation) ends it. Async
requests never queue behind the physical job limit; a full daemon
answers busy. async/status are stripped from the worker args, so an
async request coalesces with an identical synchronous one.
- status: true reports the running or last job for the project
(queued/running/cancelling/succeeded/failed/cancelled, started_at,
finished_at, error summary) from a small per-project record kept in the
daemon's job registry after the job itself is reaped. An unknown
project is an error; a project indexed before this daemon generation
reports idle. No freshness key is added: index_status keeps the DeusData#1561
freshness object.
- async + status together, non-boolean values, and async with
cross-repo-intelligence are refused. In-process servers (index worker,
embedders) refuse both modes: nothing there outlives the call.
- On a temporary (non-permanent) daemon, async is refused when the
request arrives on the one-shot `cli` tool channel and that session is
the daemon's only live session: the daemon would stop and cancel the
job the moment the command exits. The error points at `daemon start`
(or an open MCP session). A long-lived MCP session stays a valid host
even when it is the only one, which is the IDE case this exists for;
status stays allowed everywhere. The daemon lifecycle is unchanged.
- New allocations go through the memory core (cbm_alloc/cbm_calloc/
cbm_mem_strdup/cbm_free); blocks returned by non-core APIs are released
with safe_free, so no file's raw allocator count grows.
- A cut-short synchronous call now offers the async alternative: in the
cancellation text the daemon or frontend delivers (including the
-32800 reply to a cancelled index_repository), and, because a timed-out
client never reads that reply, as a notice on the next index_repository
or status call for the project.
- The tool description and schema, the CLI help and the README explain
the flags, the deadline problem and the polling pattern.
No server-side timeout or budget is introduced.
Tests (deterministic, held fake worker, bounded observation waits):
async returns before completion and status observes running then
succeeded; an async job survives its session closing while a sync job in
the same shape is still cancelled; validation errors; the cancellation
reply and the next-call notice carry the advice; a lone one-shot client
of a temporary daemon is refused async while status and an MCP session
on the same daemon are allowed; in-process refusal; schema; notice
helper.
Refs DeusData#2031
Fixes DeusData#2144
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 64c23fa commit 28b41c3
10 files changed
Lines changed: 1295 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
669 | 669 | | |
670 | 670 | | |
671 | 671 | | |
672 | | - | |
| 672 | + | |
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
678 | 705 | | |
679 | 706 | | |
680 | 707 | | |
| |||
799 | 826 | | |
800 | 827 | | |
801 | 828 | | |
| 829 | + | |
802 | 830 | | |
803 | 831 | | |
804 | 832 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
385 | 401 | | |
386 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
387 | 405 | | |
388 | 406 | | |
389 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
0 commit comments