Skip to content

TR-1350: a tenant deletes its own repo, DELETE /v1/repos/{id} - #8

Merged
ashish-bagri merged 1 commit into
mainfrom
factory/TR-1350
Nov 15, 2026
Merged

ashish-bagri merged 1 commit into
mainfrom
factory/TR-1350

Conversation

@ashish-bagri

Copy link
Copy Markdown
Member

Ticket: https://linear.app/glassflow/issue/TR-1350

The cell side (TR-1199, LoreClient.delete_repo) needs a tenant route to drop a repo.

What changed

  • DELETE /v1/repos/{id} with a tenant key that has the ingest scope. 204 when deleted.
  • The delete is the same code as the admin delete: admin::remove_source (live-run 409, source lock 409, DELETE FROM sources which cascades documents and chunks, then repo::remove_repo_dirs for mirror and checkout). admin::delete_source is now a thin wrapper over it.
  • 404 for an unknown id, another tenant's id and a source that is not a repo (the same ownership and kind check as put_bundle, sync_repo and repo_progress). 403 without the ingest scope, 401 for a wrong key.
  • 409 while an index run of the repo is live (written in the last 90 seconds) or its source lock is held.
  • docs/usage.md lists the route.

Tests (tests/admin_delete.rs, 5 new)

  • a_tenant_deletes_its_repo_with_what_the_admin_delete_removes: 204, rows, repo dir gone, notes source and key kept, other tenant untouched, second delete is 404
  • a_tenant_cannot_delete_an_unknown_repo_or_another_tenants: both 404, the other tenant's rows and dir intact, a non-repo source is 404
  • deleting_a_repo_needs_an_ingest_key_of_its_tenant: read-only key 403, wrong key 401
  • a_repo_with_a_live_run_is_a_409_for_its_tenant_too: 409, then 204 once the run is stale
  • a_repo_whose_lock_is_held_is_a_409_for_its_tenant: 409, then 204 after the lock is dropped

Checks (Docker, rust:1.95-trixie, head afb662d)

  • cargo fmt --all -- --check: ok
  • cargo clippy --all-targets -j 2 -- -D warnings: clean
  • cargo test --all-targets --no-fail-fast -j 2: 35 binaries, 699 passed, 2 failed, 4 ignored. The 2 failures are tests/cli_search.rs (onnxruntime cpuid warning on stderr, arm64 Docker VM only; file untouched). One earlier run also failed tests/mcp.rs lists_the_four_tools_and_describes_the_server (31 s under load); it passes alone and in the final full run.
  • Each new test fails when its code is broken, then passes restored: no ownership and kind check (404 test), read scope instead of ingest (403 test), live-run check off (409 test), source lock not taken (lock test), remove_repo_dirs dropped (204 test), and the kind filter alone removed from delete_repo (404 test).

No assumptions.

@ashish-bagri

Copy link
Copy Markdown
Member Author

factory/review — pass (TR-1350, head afb662d)

Verdict: pass. No finding blocks; all three are P3 notes.

remove_source is the admin delete body moved out and shared, so the tenant route and the admin route can't drift apart. The route checks scope before it looks the repo up, so a key without ingest gets 403 for any id, and another tenant's repo looks the same as an unknown one.

Verified (rust:1.95-trixie, pgvector pg17, on the head)

  • cargo fmt --all -- --check: clean. cargo clippy --all-targets -- -D warnings: clean.
  • cargo test --all-targets --no-fail-fast: 699 passed, 2 failed, 4 ignored. The 2 failures are tests/cli_search.rs (no_hits_is_a_note_on_stderr_and_still_success, plain_output_is_path_lines_score_symbols_and_three_snippet_lines), which always fail on arm64 and are not touched by this PR.
  • Mutations, run against tests/admin_delete.rs, each one restored afterwards:
    • 204 changed to 200: 3 tests fail.
    • Owner and kind filter dropped from delete_repo: a_tenant_cannot_delete_an_unknown_repo_or_another_tenants fails.
    • source_has_live_run check dropped from remove_source: 2 tests fail.
    • Scope check dropped from delete_repo: deleting_a_repo_needs_an_ingest_key_of_its_tenant fails.
  • Premise: hold_sources is the in-process lock, and source_has_live_run reads index_runs, which RunWriter::start writes (src/repo/sync.rs:366) for pushes, syncs and lore index.

Findings (none blocking)

  • F1 P3 src/http/admin.rs (remove_source): a lore index Job takes the advisory lock at src/cli/index.rs:131, loads the embedder (seconds to minutes), and only then writes its run row. A DELETE in that window passes both source_has_live_run and hold_sources, because the in-process SourceLocks does not see another process. The source is deleted and the Job then fails ("source vanished"). Nothing is corrupted, and the admin delete already had this window. A fix: remove_source also tries pg_try_advisory_lock on the source's key, on a short-lived dedicated connection because the lock is session-scoped. Then 409 if it is held. Or say in docs/usage.md that a Job still loading its embedder is not seen.
  • F2 P3 src/http/admin.rs:226: the 409 text says "a push to this source is running", but for this route the run can be a sync or a Job. The docs already say "a push, a sync, or a lore index Job".
  • F3 P3 src/repo/mod.rs:312 (remove_repo_dirs): a failed remove_dir_all is only logged as a warning, so a tenant can get 204 while the mirror and checkout stay on disk. This is the same as the admin delete. Now that the 204 reaches a tenant and the docs promise both are removed, it may be worth saying so in the docs or retrying.

Not verified

  • The pg_try_advisory_lock race was not reproduced end to end. It is read from the code and confirmed by a second-model read.
  • Not run on amd64.

— ashish-crew-reviewer

@ashish-bagri
ashish-bagri merged commit 5ee103d into main Nov 15, 2026
2 checks passed
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