diff --git a/apps/server/src/mcp/toolkits/workflow/handlers.test.ts b/apps/server/src/mcp/toolkits/workflow/handlers.test.ts index cc7a7242ddfd6..ea758e6f62c53 100644 --- a/apps/server/src/mcp/toolkits/workflow/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/workflow/handlers.test.ts @@ -179,8 +179,9 @@ it.effect("hook paths go only to a caller at the broadest mode", () => it.effect("under an administrator's ceiling, a caller at the ceiling starts runs", () => Effect.gen(function* () { const start = { action: "start", workflow: "release", idempotencyKey: "trial" }; + const started: Array = []; const workflows = { - start: () => Effect.succeed({ runId: "run-1" }), + start: (name: string) => Effect.sync(() => (started.push(name), { runId: "run-1" })), get: () => Effect.succeed(emptyRun), }; const narrowedTo = (runtimeMode: "auto" | "approval-required") => ({ @@ -189,11 +190,13 @@ it.effect("under an administrator's ceiling, a caller at the ceiling starts runs }); expect( yield* call(start).pipe(Effect.provide(handlersWith(workflows, narrowedTo("auto")))), - ).not.toMatchObject({ code: "capability_denied" }); + ).toEqual({ steps: [], references: [] }); + expect(started).toEqual(["release"]); expect( yield* call(start).pipe( Effect.provide(handlersWith(workflows, narrowedTo("approval-required"))), ), ).toMatchObject({ code: "capability_denied" }); + expect(started).toEqual(["release"]); }), ); diff --git a/docs/internals/04_environment-auth.md b/docs/internals/04_environment-auth.md index cc67e5522de1a..a3496da612c63 100644 --- a/docs/internals/04_environment-auth.md +++ b/docs/internals/04_environment-auth.md @@ -55,7 +55,10 @@ model. `mcp-client` sessions (except the read-only thread relay and client-pairing routes restricted to [peer links](./05_remote.md#peer-links)). Every MCP tool must statically declare its access level in [`McpToolAccess.ts`](../../apps/server/src/mcp/McpToolAccess.ts), and thread-only tools must still - refuse outside callers in handlers—hiding from tool listings is only discovery. + refuse outside callers in handlers—hiding from tool listings is only discovery. A workflow run + picks its own modes, so only a caller at the broadest mode a thread may run in here (full access, + or an administrator's ceiling below it) can start or change runs, change what workflows store, or + read webhook paths. Narrower callers can still read runs. - **Peer-link client pairing.** Only a full-access peer link may mint a one-time client pairing on the linked environment (since full-access agents can already run `t3 auth pairing create`). The linked side enforces this itself, and the operation stays a human-triggered RPC/HTTP route rather diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts index 9bb56dd58f5e9..ad6d57ad1258b 100644 --- a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts +++ b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts @@ -1827,6 +1827,45 @@ layer("GitLabPullRequestCli.layer", (it) => { }), ); + it.effect("posts no line comment when the head is no longer the one the caller reviewed", () => + Effect.gen(function* () { + mockedExecute.mockReturnValueOnce( + Effect.succeed( + output( + JSON.stringify({ + iid: 7, + title: "t", + web_url: "https://gitlab.com/acme/web/-/merge_requests/7", + source_branch: "feat", + target_branch: "main", + created_at: "2026-07-01T00:00:00Z", + updated_at: "2026-07-01T00:00:00Z", + diff_refs: { base_sha: "base", head_sha: "newer-head", start_sha: "start" }, + }), + ), + ), + ); + mockedExecute.mockReturnValue(Effect.succeed(output("{}"))); + const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli; + + const refused = yield* Effect.flip( + cli.submitReview({ + cwd: "/w", + repository: "acme/web", + number: 7, + verdict: "approve", + body: "Looks right.", + expectedHeadSha: "reviewed-head", + comments: [{ path: "src/b.ts", position: { kind: "added", newLine: 12 }, body: "nit" }], + }), + ); + + expect(refused.message).toContain("the head is now newer-head, not reviewed-head"); + expect(mockedExecute).toHaveBeenCalledTimes(1); + expect(argsOfCall(0)[1]).toContain("merge_requests/7"); + }), + ); + it.effect("requests changes as a reviewer and reports what GitLab refused", () => Effect.gen(function* () { mockedExecute diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts index c23f7ebdc9049..a2f4c4f38ddf9 100644 --- a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts +++ b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts @@ -2980,6 +2980,15 @@ export const make = Effect.gen(function* () { } if (input.comments.length > 0) { const refs = yield* getDiffRefs(input); + // Line comments are placed on the head read here, so it must be the one reviewed. + if (input.expectedHeadSha !== undefined && refs.headSha !== input.expectedHeadSha) { + return yield* new GitLabMutationRefusedError({ + command: "glab", + cwd: input.cwd, + operation: "submitReview", + reasons: [`the head is now ${refs.headSha}, not ${input.expectedHeadSha}`], + }); + } const rangedFileHeaders = input.comments.flatMap((comment) => comment.startPosition !== undefined && (comment.startPosition.kind !== "context" || comment.position.kind !== "context")