Skip to content

Commit e3bf5ff

Browse files
MarcoDotIOclaude
andcommitted
fix(server): t3_project_update says why it refuses a script ID or monogram
A project change the project's own rules refuse, such as a script ID with uppercase letters or a three-letter monogram, reached agents as "The operation could not be completed." with code orchestration_error, which reads as a transient failure and hides the reason. ProjectService now returns the decider's refusal as ProjectInvalidError, so the MCP tools answer invalid_request with the reason and the HTTP API answers 400. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d51bc58 commit e3bf5ff

5 files changed

Lines changed: 53 additions & 12 deletions

File tree

‎apps/server/src/mcp/toolkits/project/handlers.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,31 @@ it.effect("deleting a project through MCP also discards its clone record", () =>
664664
expect(discarded).toEqual([harness.projectId]);
665665
}),
666666
);
667+
668+
it.effect("an update the project refuses tells the agent why", () =>
669+
Effect.gen(function* () {
670+
const harness = clientLaunchHarness({ runtimeModeCeiling: "full-access", launched: [] });
671+
const detail = "Project monograms must contain at most two characters.";
672+
const dependencies = Layer.merge(
673+
harness.dependencies,
674+
Layer.mock(Project.ProjectService)({
675+
update: (input) =>
676+
Effect.fail(new Project.ProjectInvalidError({ projectId: input.projectId, detail })),
677+
}),
678+
);
679+
const toolkit = yield* ProjectToolkit.pipe(
680+
Effect.provide(
681+
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
682+
),
683+
);
684+
685+
const refused = yield* toolkit
686+
.handle("t3_project_update", {
687+
projectId: harness.projectId,
688+
projectIcon: { kind: "monogram", text: "ABC", color: "blue" },
689+
})
690+
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));
691+
692+
expect(refused.at(-1)?.result).toMatchObject({ code: "invalid_request", message: detail });
693+
}),
694+
);

‎apps/server/src/mcp/toolkits/project/handlers.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ const isAboveCeilingError = Schema.is(OrchestratorRuntimeModeAboveCeilingError);
3737
function projectFailure(error: Project.ProjectServiceError) {
3838
if (error._tag === "ProjectOperationError") return unavailable();
3939
const message =
40-
error._tag === "ProjectNotFoundError"
41-
? "The project was not found."
42-
: error._tag === "ProjectConflictError"
43-
? "The workspace is already registered to a project."
44-
: "The project is not empty; force=true is required to delete it.";
40+
error._tag === "ProjectInvalidError"
41+
? error.detail
42+
: error._tag === "ProjectNotFoundError"
43+
? "The project was not found."
44+
: error._tag === "ProjectConflictError"
45+
? "The workspace is already registered to a project."
46+
: "The project is not empty; force=true is required to delete it.";
4547
return new OrchestratorMcpFailure({ code: "invalid_request", message });
4648
}
4749

‎apps/server/src/project/ProjectService.test.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,12 @@ it.layer(layerTest)("ProjectService", (it) => {
452452
],
453453
};
454454
const first = yield* service.update(invalid).pipe(Effect.flip);
455-
assert.equal(first._tag, "ProjectOperationError");
455+
assert.equal(first._tag, "ProjectInvalidError");
456+
assert.include(first.message, "Script IDs must be 1-24 lowercase letters");
456457
const replayed = yield* service
457458
.update({ ...invalid, scripts: [{ ...invalid.scripts[0]!, id: "valid" }] })
458459
.pipe(Effect.flip);
459-
assert.equal(replayed._tag, "ProjectOperationError");
460-
assert.include(
461-
String(replayed._tag === "ProjectOperationError" && replayed.cause),
462-
"Script ID",
463-
);
460+
assert.deepEqual(replayed, first);
464461
const receipts = yield* sql<{ readonly status: string; readonly aggregate_id: string }>`
465462
SELECT status, aggregate_id FROM orchestration_command_receipts
466463
WHERE command_id = ${invalid.commandId}

‎apps/server/src/project/ProjectService.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ export class ProjectNotEmptyError extends Schema.TaggedError<ProjectNotEmptyErro
8484
}
8585
}
8686

87+
/** A change the project's rules refuse, such as an invalid script ID: the caller's input is wrong, nothing failed. */
88+
export class ProjectInvalidError extends Schema.TaggedError<ProjectInvalidError>()(
89+
"ProjectInvalidError",
90+
{ projectId: ProjectId, detail: Schema.String },
91+
) {
92+
override get message(): string {
93+
return this.detail;
94+
}
95+
}
96+
8797
export class ProjectOperationError extends Schema.TaggedError<ProjectOperationError>()(
8898
"ProjectOperationError",
8999
{
@@ -109,6 +119,7 @@ export type ProjectServiceError =
109119
| ProjectNotFoundError
110120
| ProjectConflictError
111121
| ProjectNotEmptyError
122+
| ProjectInvalidError
112123
| ProjectOperationError;
113124

114125
export class ProjectService extends Context.Service<
@@ -292,6 +303,8 @@ export const make = Effect.gen(function* () {
292303
});
293304
case "ProjectCommandMissingProjectError":
294305
return yield* new ProjectNotFoundError({ projectId });
306+
case "ProjectCommandInvariantError":
307+
return yield* new ProjectInvalidError({ projectId, detail: rejection.detail });
295308
default:
296309
return yield* dispatchError(
297310
rejection ?? receipt.error ?? "The command was previously rejected.",

‎apps/server/src/project/http.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const failProjectMutation = Effect.fn("environment.projects.failMutation")(funct
2424
if (
2525
cause._tag === "ProjectNotFoundError" ||
2626
cause._tag === "ProjectConflictError" ||
27-
cause._tag === "ProjectNotEmptyError"
27+
cause._tag === "ProjectNotEmptyError" ||
28+
cause._tag === "ProjectInvalidError"
2829
) {
2930
return yield* failEnvironmentInvalidRequest("invalid_command");
3031
}

0 commit comments

Comments
 (0)