Skip to content

fix(authz): align Runner, account, and MCP access checks - #1328

Merged
Robert0622 merged 4 commits into
mainfrom
codex/loopforge-authorization-guards
Nov 25, 2026
Merged

Robert0622 merged 4 commits into
mainfrom
codex/loopforge-authorization-guards

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

What changed

  • Keep Runner session renewals within the machine's existing owner scope.
  • Apply a shared enrollment policy to browser setup and registration in password, gateway, and SSO deployments.
  • Bind personal MCP writes to the signed-in user and commit imports atomically.
  • Apply source access checks when cloning roles and retain only eligible MCP dependencies.

Scope

  • Platform core / API / runner
  • Public adapter / deployment

Compatibility

The patch uses the existing database schema and Runner protocol. Password-only deployments retain first-run setup. Gateway and SSO deployments use their configured identity path for enrollment.

Validation

  • Focused Go regressions passed in the HTTP API and repository packages.
  • Targeted go vet, the public content check, and Gitleaks passed.
  • Chrome and isolated MySQL verified first-run controls, normal gateway sign-in, personal MCP saves and imports, role cloning, and same-owner renewal with a real Runner.
  • The broader macOS Go run had baseline failures and a MySQL package timeout. Selected deployment, Git, and process cases passed in Linux.

Safety

  • Public content and secret scans passed.
  • User files and unrelated changes were preserved.

crispinhu27
crispinhu27 previously approved these changes Nov 25, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 792bd12 (base main 848793b) and verified it in an isolated environment. I didn't find any blocking issues.

Scope: Runner register/renew owner scope (runners.go, RegisterRunner), first-run setup and self-registration policy (auth_register.go, LocalAccountCount), personal and project MCP writes and imports (mcp*.go, SaveMCPServers, the guard removed from project_write_access.go), role cloning and MCP dependencies (catalog.go), and the deployment docs.

Verification (Go 1.26.11 + MySQL 8.4.7, synthetic accounts and data only, each case run on both this head and the base):

  • Built the head and base platforms and ran each against its own MySQL database, then drove the same HTTP scenarios through both:
    • Runner: the bootstrap token presenting a user-bound runner ID now gets a new ID, and the original row keeps owner=bob. On base the machine was taken over with owner→0. Same-owner renewal (bind code) keeps the ID; base issued a new one. Platform runner renewal keeps its ID on both.
    • Gateway mode (AGENTFLOW_TRUST_IDENTITY_HEADERS=true) with no accounts: /api/auth/setup returns needsSetup:false, and registering returns 403 with no user created. On base the first registrant became platform admin. Header sign-in returns 200 on both. Password-only installations still get first-run setup, and the first account becomes admin.
    • MCP: a personal PUT with a forged ownerUserId is bound to the signed-in user (base stored the forged owner). An import that overwrites another user's personal MCP returns 403 and leaves the stored URL and owner unchanged. A batch import with one invalid item writes nothing. A project-MCP PUT carrying masked headers keeps the stored secret. Non-members get 403 on PUT and DELETE of another project's MCP.
    • Clone: a non-member cloning an unshared role from someone else's project gets 403 (201 on base). Cloning a shared role no longer copies the source project's MCP or headers into the target project, and the other user's personal MCP is no longer copied into the cloner's personal scope. Base copied both.
  • go test ./internal/httpapi/... ./internal/repo/... (SQLite): the set of failing tests matches base. A focused run of the remaining 7 cases (assistant workspace checkpoint, browser, workspace lease) fails identically on head and base, so they are environment issues. TestChatClarificationEdgePaths failed once in the parallel run and passed when rerun on its own. internal/repo on MySQL 8.4.7: only TestMySQLReadsObserveExternalChangesWithoutReload and TestMySQLGitSSHCredentialLifecycle fail, the same as base. The new authorization_writes_test.go passes. go vet and gofmt are clean on the touched packages.
  • CI: 16/16 checks passed.

Not verified, and not counted against this review: I didn't run a real gateway or SSO identity provider or a real Runner daemon end to end. Those were covered at the HTTP layer with header sign-in and the register API.

Intentional behavior changes: non-blocking, but worth noting in the release notes.

  • When a shared role is cloned by someone who can't write the source project, MCPs from the source project are dropped instead of copied.
  • From reading the code (not run): editableMCP now calls allowMCPServerWrite, so MCP file downloads (GET /api/mcp-servers/:id/files/*) also require write access to the owning project.
  • On gateway or SSO deployments, and on installations with AGENTFLOW_PLATFORM_ADMINS configured, the first administrator now has to be provisioned through configuration or the account command.

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Review of 792bd120: the security fixes work in a real deployment. Two P2 behavior problems should be fixed before merge.

How I tested

  • Built this head and main (848793b3) side by side. Each ran against its own fresh MySQL 8.4.7 database with the seed SQL applied. Not tested against this repo.
  • Used a scripted multi-user scenario: admin, u1, u2, u3. Project P has u1 as member and u2 as viewer. Project Q has u1 and u3 as members.
  • Started a real agentflow-runner process.
  • Checked the login page in Chromium in each auth mode.
  • go test ./internal/repo (Authorization/Runner/MCP/LocalAccount/Catalog, against real MySQL): pass, 32 tests.
  • go test ./internal/httpapi (Register/Setup/MCP/Catalog/Clone/Runner/Agent): pass.
  • go vet on both packages: clean. CI: 16/16 pass.

Results (main → this PR)

Scenario main PR
u1 creates a personal MCP with ownerUserId: 999 in the body stored as owner 999; u1 then cannot edit their own MCP (403) owner = u1; u1 can edit it (200) ✅
u2/u3 PUT or DELETE u1's personal MCP 403 403 ✅
u3 imports [valid Q item, u1's personal p1 with an evil URL] 200; the Q item is written 403; whole import rolled back, Q item absent, p1 unchanged ✅
PUT with an empty id 200 (empty) 400 ✅
P viewer PUT on a P MCP / non-member DELETE 403 / 403 403 / 403 ✅
P viewer GET /api/mcp-servers/pm1/files/x 404 403 (now requires write access; the web UI doesn't call it)
u3, not a member of P, clones a non-shared role from P into Q 201 (copied) 403 ✅
u3 clones a shared role from P into Q 201; copies P's custom MCP and references u1's personal MCP 201; neither is copied ✅ (but see P2-1)
u1, member of P and Q, clones a non-shared role into Q 201 201; mcp-clone-pm1-project-qq + p1 (u1's own) + market clone ✅
Platform bootstrap token re-registers u1's runner ID (API) adopted: owner → NULL, name → "hijack", sharing cleared new runner ID; u1's runner keeps owner, name and sharing ✅
Real runner: u1's bind code, then a new bind code with the same state file and no session — same ID, name updated, sharedProjectIds:["welcome"] kept ✅
Real runner: same state file with the platform bootstrap token — registers as a new runner-Ihp…; u1's runner untouched ✅
Fresh password install, browser first-run — setup form → admin created with isPlatformAdmin: true ✅
ALLOW_SIGNUP=false — first account is admin; second gets 403 ✅
Gateway (TRUST_IDENTITY_HEADERS) or SSO (app token + login URL) setup and register open; first account becomes admin needsSetup:false, signupEnabled:false; register 403; login page shows "contact admin" ✅
Password install with PLATFORM_ADMINS=alice first browser account becomes admin; alice can register as a normal password account nobody becomes admin via the browser; alice gets 409 ✅ (see P3-2)

P2 – should fix

  1. Cloning a shared role silently drops market MCPs (internal/httpapi/catalog.go, cloneAgentMCPServers). If the target project doesn't already have the market item, the source-project canCopyProject check decides the outcome. Reproduced: u3 (writer on Q, not a member of P) clones the shared role r-shared (deps pm1, p1, mcp-github-project-pp) into Q. The response is 201 with "mcpServers": [], and the GitHub market dependency is gone. Market definitions hold no project secrets, and u3 could install the same item into Q directly. Suggested fix: for source.MarketID != "", call installMarketMCP(h.repo, source.MarketID, projectID) instead of applying the source-project check. Dropping custom project MCPs and other users' personal MCPs is correct. The response should still tell the caller which dependencies were not copied.
  2. Any signed-in user can permanently block clone and market install for a project (mcp.go personal PUT, combined with mcpInstallID(...) in catalog.go / mcp_market.go). Install and clone IDs are deterministic, and before this PR a later write simply overwrote whatever held the ID. Reproduced: u3, who is not a member of Q, PUTs personal MCPs with the IDs mcp-clone-pm1-project-qq and mcp-github-project-qq (both 200). Afterwards u1's clone of r1 into Q returns 409 MCP 已被创建或更改 ("MCP was created or changed"), and so does POST /api/mcp-market/install {github, Q}. Neither recovers until someone removes u3's MCP. Suggested fix: reject the reserved mcp- prefix for user-supplied personal IDs, or generate personal IDs on the server.

P3 – nits

  1. localSignupOptions treats AGENTFLOW_SSO_APP_TOKEN or AGENTFLOW_SSO_LOGIN_URL alone as SSO. auth.Client.LoginURL only switches to SSO when both are set, and the app token is also used for photos and RIO headers. Verified: with only the app token set, the login page shows local password sign-in and "contact admin", and setup/register return 403. A fresh install configured this way has no browser path to create an admin. Use the same predicate as LoginURL.
  2. An allowlisted login (PLATFORM_ADMINS=alice) gets 409 该用户名已被使用 ("username already taken") although no such account exists. Blocking it is right, but the message is misleading. A dedicated message ("this account must be provisioned by an operator") would help. docs/deployment.md also mentions the account-command path only for gateway/SSO, but it now applies to password installs that set PLATFORM_ADMINS.
  3. Import changes: a payload containing the same ID twice now fails with 409 instead of last-write-wins. A platform admin can no longer import a backup that contains other users' personal MCPs. Both are acceptable, but worth a CHANGELOG line.
  4. repo.PutRunner with OwnerUserID == 0 no longer clears shared_project_ids, login_model_catalogs or default-runner prefs when it moves a user-owned row to the platform. Only tests call it today, but a comment or guard would prevent future misuse.
  5. Missing HTTP-level tests for: bootstrap token re-registering a user-owned runner ID (expect a new ID), import rollback on a 403 midway through, the 403 for cloning a non-shared role, and needsSetup:false with PLATFORM_ADMINS.

Raw request/response results for both builds and the login-page screenshots are kept outside the repo. No screenshot branch was created. This token is the PR author's account, so this is a comment, not a formal review state.

Cloning a shared role from a project the caller cannot write dropped
its market MCPs. Market entries carry no project settings, so install
them from the catalog in the target project instead.

Install IDs for market, custom and cloned MCPs are predictable. Any
signed-in user could create a personal MCP under such an ID and make
every later install or clone into that project fail with 409. When the
ID is held outside the destination, use an alternate ID keyed with the
session secret, so retries still find the same row.

Treat SSO as configured only when both the app token and login URL are
set, the same condition the login page uses, so an install with only
the app token keeps its browser setup step. Explain why a login listed
in AGENTFLOW_PLATFORM_ADMINS cannot self-register, and document it.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
crispinhu27 previously approved these changes Nov 25, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 334fd8e8 (base main 848793b). My earlier APPROVE on 792bd120 was dismissed by the push. I found no blocking issues in the two new commits (0f1b081b, 334fd8e8), and the earlier verification still holds for the unchanged code.

Scope of this round: the incremental diff 792bd120..334fd8e8. That covers market-MCP install during role clone (cloneAgentMCPServers), destinationMCPInstallID (alternate IDs when an install ID is already held outside the destination), the SSO predicate in localSignupOptions, the dedicated 403 for allowlisted admin logins, the docs and CHANGELOG, and the new tests. I also re-ran the earlier security scenarios against this head.

Verification: Go 1.26.11 and MySQL 8.4.7, synthetic accounts and data only. I built three platforms, this head, 792bd120 and base 848793b3, and drove the same HTTP scenarios through each.

  • Shared role cloned by a non-member of the source project, where the role depends on a project MCP, another user's personal MCP and the GitHub market MCP:
    • This head returns 201 with ["mcp-github-project-qq"], installed from the catalog without the source project's headers. Repeating the clone reuses the same row.
    • On 792bd120 the result was [], so the market dependency was dropped.
    • On base, the source project's MCP was copied.
  • Predictable-ID squatting, where another user first creates a personal MCP under the install ID:
    • On 792bd120, the market install returned 409 permanently, the clone returned 409, and custom installs (project and personal) returned 409.
    • On this head, all of them succeed and get an alternate ID such as mcp-github-<hmac>-project-… or mcp-clone-pm1-<hmac>-project-….
    • Repeating the market install returns 409 "already added". Repeating the clone reuses the same alternate ID.
    • The squatter can't delete the alternate row (403).
    • A project MCP from another project holding the ID is handled the same way. A 70-character custom ID stays bounded at 64 characters.
  • Signup under each auth mode, starting with no accounts:
    • App token alone, or login URL alone: password setup stays available and the first account becomes admin. On 792bd120 there was no browser path to an admin.
    • Both SSO settings, or gateway mode: needsSetup:false, and register returns 403 with no user created. On base, the first registrant became admin.
    • PLATFORM_ADMINS=Alice: registering alice returns 403 with the new "use the account command" message, while bob registers as a normal user. loopforge-account -user alice -admin creates alice, who then signs in with isPlatformAdmin:true.
    • ALLOW_SIGNUP=false: the first account becomes admin and the second gets 403.
  • Regression checks on this head:
    • A forged ownerUserId is bound to the signed-in user.
    • PUT on another user's personal MCP returns 403.
    • A mixed import returns 403 with nothing written.
    • Non-member PUT and DELETE return 403.
    • Source-project secrets never appear in GET responses.
  • go test ./internal/httpapi/... ./internal/repo/... ./internal/auth/... on head and base (SQLite): 25 identical failures on both, nearly all because the container has no bwrap. No head-only failures. All 13 new tests pass.
  • go test ./internal/repo -run 'Authoriz|Runner|MCP|LocalAccount|Catalog|Import' against MySQL 8.4.7 passes. go vet and gofmt are clean on the touched packages. CI 16/16 passed.

Earlier items: the P2s and P3s in the author's comment on 792bd120 (market MCPs dropped on clone, install-ID squatting, the partial-SSO predicate, the misleading 409 for allowlisted logins, the docs/CHANGELOG notes and the PutRunner comment) were re-run above where they are behavioral, and the behavior now matches the expected outcome.

Not verified: a real SSO identity provider or authenticating gateway end to end (covered at the HTTP layer with environment configuration), and a real Runner daemon in this round. The Runner code did not change since 792bd120 apart from a comment.

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Re-review of 334fd8e8 (fix commits 0f1b081b, 334fd8e8 on top of 792bd120): both P2s from my last review are fixed in a real deployment. LGTM, one P3 left.

How I tested

  • Built this head and ran it against a fresh MySQL 8.4.7 database. Not tested against this repo.
  • Users: admin, u1, u2, u3, u4. P: u1 member, u2 viewer. Q and R: u1 and u3 members. S and T: u1 only. u4 is a member of nothing.
  • Scripted HTTP scenario, 54 steps: 53 pass. The one failure is the P3 below.
  • Started separate instances for the auth modes and opened the login and register pages in Chromium.
  • go vet ./internal/httpapi ./internal/repo: clean. go test ./internal/httpapi (Register/Setup/MCP/Clone/Catalog/Market/Squat/Import/Runner) and go test ./internal/repo (Authorization/Runner/MCP/LocalAccount/Catalog, real MySQL): pass.
  • Trial merge with current main 1cbaa4a4 (feat(im): 把聊天发起人记入需求操作日志,并在平台管理里配置外部访问地址 #1300): no conflicts. go build ./..., vet and the same test set pass on the merge.
  • CI: 16/16 pass.

P2-1: cloning a shared role keeps market MCPs ✅

Scenario 792bd12 334fd8e
u3 (not in P) clones shared r-shared (deps: P custom pm1, u1's personal p1, P's GitHub market install) into Q 201, mcpServers: [] 201, mcpServers = one new GitHub install in Q. It's a fresh catalog install, not P's row, and P's header secret isn't copied ✅
Same clone a second time — reuses the same Q install. Q still has exactly one GitHub row ✅
R already has GitHub installed, u3 clones into R — reuses R's existing row, no duplicate ✅
pm1 / p1 copied into Q not copied still not copied ✅
u3 clones non-shared r-private; u4 (not in Q) clones into Q 403 / 403 403 / 403 ✅

P2-2: predictable install IDs can't be squatted ✅

u4 first PUTs personal MCPs with the IDs mcp-clone-pm1-project-ss, mcp-github-project-ss, mcp-custom-tool-project-ss, mcp-custom-mine-personal-<u1> and mcp-github-project-tt (all 200, as expected).

Scenario 792bd12 334fd8e
u1 clones r-private into S 409 MCP 已被创建或更改 201. pm1 is copied under mcp-clone-pm1-<hmac>-project-ss with the right URL ✅
Repeat the clone 409 201, same IDs, no new rows ✅
Market install of GitHub into T (ID squatted) 409 201 with an alternate ID; a repeat returns 409 "already added" ✅
Custom project install tool into S / custom personal install mine for u1 409 201 with alternate IDs; repeats return 409 duplicate ✅
u4's squatter rows — untouched, still owned by u4 ✅
u4 DELETE / PUT on S's alternate rows — 403 / 403 ✅

Earlier P3s

  • P3-1: SSO now needs both settings. With only AGENTFLOW_SSO_APP_TOKEN: needsSetup:true, and the first browser account becomes admin. With app token + login URL: needsSetup:false, signupEnabled:false, register returns 403, and the login page shows "请联系部署管理员创建账号" ✅
  • P3-2: with PLATFORM_ADMINS=alice, setup is needsSetup:false. alice now gets 403 该用户名是已配置的平台管理员,请由运维用账号命令创建,不能在浏览器中注册 ("this login is a configured platform admin; an operator must create it with the account command, not the browser"), and the browser register form shows the same message. bob registers as a normal user. docs/deployment.md documents both cases ✅
  • P3-3: CHANGELOG line added ✅. P3-4: PutRunner comment added ✅. P3-5: HTTP tests added for import rollback and for cloning an unshared role ✅
  • Regressions of the original fixes still hold: ownerUserId: 999 is bound to the caller, cross-user PUT returns 403, a mixed import returns 403 and is rolled back, an empty ID returns 400, and a viewer's PUT returns 403.

P3 – non-blocking

Once the keyed alternate ID is taken, repeated clones create duplicate copies. destinationMCPInstallID falls back to a random suffix when the HMAC alternate is also held by someone else. Project MCP rows (and their IDs) are listed to every signed-in user, which is already the case on main. So if a project's cloned copy is deleted, another user can claim the alternate ID, and every later clone of the same role into that project writes a new mcp-clone-pm1-<random>-project-ss row.

Reproduced: u1 deletes S's copy, u4 PUTs a personal MCP under that alternate ID, then u1 clones r-private into S twice. Both return 201, and S now has 2 copies of pm1 (…-b34c1d100d0a-…, …-e3f83ca4eed0-…). Custom installs behave the same way on the random fallback: a repeat creates a new row instead of 409.

It no longer blocks anyone, so this is cosmetic. If you want to close it, the random branch can first look up an existing row in the destination with the same base (for clones: same Name/URL from the same source; for custom: same custom-<base> prefix) before minting a new ID.

Minor: cloneAgentMCPServers calls installMarketMCP right away, outside the batched SaveMCPServers. If a later step in the same clone fails, the market install stays behind in the target. It's harmless (the row is valid and would be reused), and I didn't hit it.

Conclusion: no blocking issues, OK to merge. This token is the PR author's account, so this is a comment, not a formal approval. No screenshot branch was created; the login and register screenshots and the raw step results are kept outside the repo.

When the predictable install ID and its keyed alternate were both held by another user, every clone or custom install fell back to a random ID. A project then got a new copy of the cloned MCP on each clone, and a repeated custom install created a row instead of returning 409.

Try a fixed sequence of keyed alternates, and prefer a row the destination already holds under any candidate over a free one.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

Re-review of cd5fce1b (fixes the P3 from my review of 334fd8e8): verified in a real deployment, LGTM.

Change

destinationMCPInstallID now tries the base ID and then a fixed sequence of 8 keyed HMAC alternates. It first returns a row the destination already holds under any candidate, then the first free candidate. A random ID is used only when all candidates are taken. i=0 produces the same digest as before, so existing alternate rows are still found.

How I tested

  • Built this head and ran it against a fresh MySQL 8.4.7 database. Not tested against this repo.
  • Users and projects are the same as in my last review: u4 is a member of nothing. 70/70 steps pass. That's the previous 54 steps (P2-1 market MCP clone, P2-2 squatting, the auth-mode and import regressions) plus the new P3 steps:
Scenario 334fd8e cd5fce1
S's pm1 copy is deleted, u4 takes alt0, u1 clones r-private into S twice 2 copies of pm1 in S (random IDs) 1 copy; both clones return the same ID (alt1) ✅
u4 then deletes both the base and alt0 squats, u1 clones again — still 1 copy, reuses alt1; no fallback to base or alt0 ✅
Custom install tool2 into S: base squatted → 201 on alt0; u1 deletes it, u4 takes alt0 → install again — 201 on another alternate ✅; a repeat install returns 409 ✅; S has exactly 1 tool2 row ✅
u4 frees both tool2 squats, u1 installs tool2 again — 409; still 1 row (no new row on the base ID) ✅

No open issues from me. OK to merge. The token is the PR author's account, so this is a comment, not a formal approval.

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Follow-up fixes for the review of 792bd120. The head is now cd5fce1b.

Changes

  • 0f1b081b fixes P2-1. When a shared role is cloned by someone who can't read the source project, its market MCP dependencies are now installed into the target project from the catalog (installMarketMCP). The source project's copy and its headers are still not copied.
  • 0f1b081b fixes P2-2. Install and clone IDs are predictable. If another user already holds the predictable ID, destinationMCPInstallID now picks an alternate ID: a digest keyed with the deployment's session secret, so other users can't guess it. Market install, custom install and role clone all use it, so a squatter can no longer make them return 409 forever.
  • 0f1b081b also covers the P3s:
    • SSO now counts only when both the app token and the login URL are set, the same rule as auth.Client.LoginURL.
    • Registering a login listed in PLATFORM_ADMINS returns 403 with an explanation instead of the misleading 409.
    • Adds the PutRunner contract comment, plus docs and a CHANGELOG entry.
  • 334fd8e8 adds HTTP-level tests for import rollback and for unshared role clones.
  • cd5fce1b fixes the P3 from the re-review. If the base ID and the first keyed alternate were both taken by someone else, every clone or custom install fell back to a random ID. Each clone then added another copy of the MCP to the project, and a repeated custom install created a new row instead of returning 409. The alternates are now a fixed sequence of 8 keyed digests. A row the destination already holds under any of them wins over a free one, so repeated operations resolve to the same row. They still do after a squatter deletes their entry. A random ID is used only when all 8 are taken.

Verification

  • TestMCPInstallIDsStayStableWhenAlternatesAreSquatted is new. It fails on 334fd8e8 and passes on cd5fce1b. The MCP, clone and market tests in internal/httpapi pass, and go vet is clean.
  • Merged cd5fce1b with main cb78a499: no conflicts, and go build and go vet ./... are clean. Running go test ./internal/... ./web/ ./cmd/... fails the same set of tests as main does in the same environment (missing Docker, Chromium and ssh locally). The only extras are two browser frame-timing tests in internal/runtime and internal/httpapi. Run on their own, both passed 3 times out of 3, and this PR doesn't touch internal/runtime, so they are load-related flakes. webtest 292/292 and check-public.py pass.
  • Deployed cd5fce1b and 334fd8e8 side by side, each on a fresh MySQL 8.4.7 database. Not tested against this repository. I ran the same 21-step multi-user script against both:
Scenario 334fd8e cd5fce1
u3 (not a member) squats mcp-clone-pm1-project-dstp; u1 clones r1 into dstp 201, alternate ID 201, alternate ID
u1 deletes that copy, u3 squats the alternate too, u1 clones twice more two different random IDs, 2 copies of pm1 same ID both times, 1 copy
u3 squats the custom ID and then its first alternate; u1 custom-installs tool twice 201 / 201, 2 rows 201 / 409, 1 row
u3 squats mcp-github-project-dstp; u1 installs the GitHub market MCP twice 201 / 409 201 / 409, 1 install
u3's 5 squatting personal MCPs afterwards unchanged unchanged

Result: cd5fce1b passes 21/21. 334fd8e8 passes 17/21, and its 4 failures are exactly this P3.

  • CI: 16/16 pass on cd5fce1b.

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed cd5fce1b (base main 848793b3) and verified it in an isolated environment. I found no blocking issues.

Scope of this round: the incremental 334fd8e8..cd5fce1b. My earlier review of 334fd8e8 was dismissed by the push. The change rewrites destinationMCPInstallID (internal/httpapi/mcp_market.go): the base ID is followed by a fixed, keyed sequence of 8 alternate digests, a row the destination already holds under any candidate wins over a free one, and a random ID is used only when every candidate is taken elsewhere. It also adds TestMCPInstallIDsStayStableWhenAlternatesAreSquatted.

Verification (Go 1.26.11, synthetic data only, head cd5fce1b, previous head 334fd8e8 and base 848793b3 each in their own worktree):

  • go build ./..., go vet ./internal/...: pass on head and base.
  • go test ./internal/httpapi/ -run 'MCP|Runner|Auth|Register|Catalog' -count=1: pass. TestMCPInstallIDsStayStableWhenAlternatesAreSquatted -count=3: pass.
  • Full go test ./internal/httpapi/ -count=1: head 15 fail / 1330 pass, base 15 fail / 1321 pass, and the two failure sets are identical. They come from environment-dependent cases (workspace checkpoints, browser stream, SSH checkout, run stream). TestChatClarificationEdgePaths is flaky on both sides (1 in 5 runs each) and is not caused by this change.
  • A throwaway test file (head worktree only, deleted afterwards) covered 9 candidates staying distinct and ≤64 chars, alternate #1 matching what 334fd8e8 produced so existing rows are still found, the destination holding several candidates, both nil and empty keys, and cross-user listing.

Bug fixed by this commit, reproduced over HTTP: a squatter takes the base ID, the install goes to the alternate, the squatter deletes the base row, and the install runs again. On 334fd8e8 that second POST returned 201 and created a duplicate row, so repeated clones stopped finding their copy. On cd5fce1b it returns 409 with a single row, which is the intended behaviour.

Non-blocking notes (no action required for this PR):

  • If every candidate is taken by other users, the function falls back to a random ID, so a row saved there is not found again. This needs the 8 keyed IDs, which depend on the session secret, and it is the same fallback 334fd8e8 had.
  • Concurrent clones of the same role into the same project can now surface MCP 已被创建或更改,请刷新后重试 to the losing caller instead of quietly overwriting. Only one row is ever created; I saw it in 11 of 30 runs here and 14 of 30 on 334fd8e8, so it predates this commit.

Not covered: no Docker here, and I did not repeat the MySQL-backed deployment scenarios from the earlier rounds beyond what CI covers; CI core and platform-required are green on this head. CI is 16/16 on cd5fce1b, and the PR has no conflict with current main (cb78a49). This approval is for cd5fce1b only.

@Robert0622
Robert0622 merged commit 058a530 into main Nov 25, 2026
16 checks passed
@Robert0622
Robert0622 deleted the codex/loopforge-authorization-guards branch November 25, 2026 13:14
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