Skip to content

fix(mcp): reuse the project that owns a root on unnamed re-index (#2134) - #2344

Open
DeusData wants to merge 2 commits into
mainfrom
fix/issue-2134
Open

DeusData wants to merge 2 commits into
mainfrom
fix/issue-2134

Conversation

@DeusData

Copy link
Copy Markdown
Owner

index_repository without name derived the project key from the path only. So re-indexing a root first indexed under an explicit name forked a second index with the same root_path, and the original stayed stale and was still served. The key is now resolved from the indexes on disk:

  • the derived project exists → keep it;
  • exactly one other project owns the canonical root → update that one in place;
  • several own it → fail loudly, list them and ask for name;
  • none → derived name, as before.

The resolved name is written into the daemon/worker args, so the lease key and the written index match.

Test: mcp::tool_index_repository_reuses_existing_project_for_root_issue2134 (fails before the fix, passes after, fails again with the fix reverted; also covers the ambiguous case). Proven end-to-end with the CLI binary: one project and one .db after an unnamed re-index, where there used to be two.

Notes for review:

Fixes #2134

index_repository without `name` derived the project key from the path
alone. When the root had first been indexed under an explicit name, a
later unnamed re-index forked a second index (same root_path,
path-derived name) and left the original untouched, so the stale index
kept being served while the call reported success.

Resolve the key from the indexes on disk before any work starts:
- the path-derived project exists -> keep it (unchanged behavior);
- exactly one other project owns the canonical root -> adopt its name
  and update it in place, so existing indexes are never orphaned;
- several projects own the root -> fail loudly, name them and ask for
  `name` instead of guessing or forking again;
- none -> first index under the derived name, as before.

The resolved name is written into the args handed to the daemon job
coordinator and the supervised worker, so the project lease key and the
index actually written stay the same project.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The memory-core ratchet flagged src/mcp/mcp.c growing by 10 raw allocator
sites (784 -> 794) from index_root_owner_resolve and its caller. The owner
list buffer, which this code allocates and frees itself, now uses
cbm_realloc/cbm_free (class other). Strings handed over by other APIs
(cbm_project_name_from_path, heap_strdup, the index argument strings) are
released through safe_free, as elsewhere in the file, so no memory the core
never counted reaches cbm_free. Behaviour is unchanged; mcp.c is back at its
baseline of 784.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>

This branch has not been deployed

No deployments
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.

index_repository without name silently creates a duplicate index

1 participant