GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(server): dispatch tools refuse unfilled briefs and misplaced mod… · mediavee/t3code@4de457f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • mcp
      • OrchestratorMcpService.test.ts
      • OrchestratorMcpService.ts
      • advertisedJsonSchema.test.ts
      • advertisedJsonSchema.ts
      • toolkits/project
        • handlers.test.ts
        • handlers.ts
        • tools.ts
    • orchestration-v2/testkit/fixtures
      • multi_turn
        • muse_transcript.ndjson
      • muse_permission
        • muse_transcript.ndjson
      • muse_subagent_approval
        • muse_transcript.ndjson
      • muse_subagent_interrupt
        • muse_transcript.ndjson
      • muse_workflow
        • muse_transcript.ndjson
      • simple
        • muse_transcript.ndjson
      • subagent_v2
        • muse_transcript.ndjson
      • turn_interrupt
        • muse_transcript.ndjson
    • provider
      • agentContextBudget.json
  • packages
    • contracts/src
      • orchestratorMcp.test.ts
      • orchestratorMcp.ts
    • provider-core/src/server
      • runtimeInstructions.test.ts
      • runtimeInstructions.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.test.ts
+84-1Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4864,7 +4864,7 @@ describe("OrchestratorMcpService provider resolution", () => {
48644864

48654865
it.effect("accepts the inherited options it reports back as a delegate target", () =>
48664866
Effect.gen(function* () {
4867-
// t3_thread_launch keeps a model selection as given, so a thread can hold an option its model lacks.
4867+
// A thread's selection can hold an option its model lacks, as from an older launch.
48684868
const inherited = {
48694869
instanceId: codexInstanceId,
48704870
model: "gpt-5.4",
@@ -4953,6 +4953,89 @@ describe("OrchestratorMcpService provider resolution", () => {
49534953
}),
49544954
);
49554955

4956+
it.effect("refuses an unfilled brief before anything starts, unless sent on purpose", () =>
4957+
Effect.gen(function* () {
4958+
const commands: Array<unknown> = [];
4959+
const task = {
4960+
id: taskId,
4961+
threadId: parentThreadId,
4962+
origin: "app_owned",
4963+
childThreadId,
4964+
providerInstanceId: codexInstanceId,
4965+
model: "gpt-5.4",
4966+
status: "running",
4967+
result: null,
4968+
};
4969+
const dependencies = Layer.mergeAll(
4970+
NodeServices.layer,
4971+
NodeCrypto.layer,
4972+
Layer.mock(ThreadManagementService.ThreadManagementService)({
4973+
hasReceipt: () => Effect.succeed(false),
4974+
assertProviderInstanceEnabled: () => Effect.void,
4975+
getThreadRecords: (threadId) =>
4976+
Effect.succeed(
4977+
threadId === parentThreadId
4978+
? parentProjection(commands.length > 0 ? [task] : [])
4979+
: childProjection,
4980+
),
4981+
dispatch: (command) =>
4982+
Effect.sync(() => {
4983+
commands.push(command);
4984+
return {
4985+
sequence: 1,
4986+
storedEvents: [{ event: { type: "subagent.updated", payload: task } }],
4987+
} as never;
4988+
}),
4989+
}),
4990+
ServerSettings.layerTest(),
4991+
providerRegistryLayer([
4992+
providerSnapshot({
4993+
instanceId: codexInstanceId,
4994+
driver: ProviderDriverKind.make("codex"),
4995+
model: "gpt-5.4",
4996+
}),
4997+
]),
4998+
adapterRegistryLayer([codexInstanceId]),
4999+
Layer.mock(ProjectService.ProjectService)({ getById: () => Effect.succeedNone }),
5000+
Layer.mock(SecretRequests.SecretRequests)({}),
5001+
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
5002+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
5003+
);
5004+
yield* Effect.gen(function* () {
5005+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
5006+
for (const [brief, match] of [
5007+
["Review this.\n\n<<BRIEF>>", "<<BRIEF>>"],
5008+
["$(cat brief.md)", "$(cat brief.md)"],
5009+
["Do {{ task_name }} now.", "{{ task_name }}"],
5010+
["$(< brief.md)", "$(< brief.md)"],
5011+
["`cat brief.md`", "`cat brief.md`"],
5012+
] as const) {
5013+
const error = yield* service
5014+
.delegateTask(scope, { task: brief, mode: "async" })
5015+
.pipe(Effect.flip);
5016+
assert.equal(error.code, "invalid_request");
5017+
assert.include(error.message, JSON.stringify(match));
5018+
assert.include(error.message, "allowLiteralTemplates: true");
5019+
}
5020+
assert.lengthOf(commands, 0);
5021+
5022+
// Commands a worker is asked to run are not file substitutions.
5023+
yield* service.delegateTask(scope, {
5024+
task: 'Run `git worktree add "$(mktemp -d)/wt"`, then fill {{ secrets["KEY"].value }}.',
5025+
mode: "async",
5026+
clientRequestId: "delegate-commands",
5027+
});
5028+
yield* service.delegateTask(scope, {
5029+
task: "Explain the `<<BRIEF>>` placeholder in `$(cat brief.md)`.",
5030+
allowLiteralTemplates: true,
5031+
mode: "async",
5032+
clientRequestId: "delegate-literal",
5033+
});
5034+
assert.lengthOf(commands, 2);
5035+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));
5036+
}),
5037+
);
5038+
49565039
it.effect("validates options against the model a target names by alias", () =>
49575040
Effect.gen(function* () {
49585041
const dependencies = Layer.mergeAll(
Collapse file

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts
+27-10Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
ThreadId,
6565
isOrchestrationV2WorkActive,
6666
latestProviderTurnForAttempt,
67+
literalTemplateRefusal,
6768
resolveProjectProviderInstanceEnabled,
6869
SECRET_REQUEST_UNSAVED_NOTE,
6970
} from "@t3tools/contracts";
@@ -483,7 +484,7 @@ function providerConstraints(
483484
return constraints;
484485
}
485486

486-
/** t3_thread_launch keeps a selection as given, so it can hold options its model does not have. */
487+
/** A thread's selection can hold options its model lacks, as from t3_thread_configure or an older launch. */
487488
function knownOptions(
488489
options: ReadonlyArray<ProviderOptionSelection> | undefined,
489490
descriptors: ReadonlyArray<ProviderOptionDescriptor> | undefined,
@@ -527,6 +528,25 @@ function invalidOptionSelections(
527528
return problems;
528529
}
529530

531+
/** delegate_task and t3_thread_launch accept the same option selections for a model. */
532+
export const requireAdvertisedOptions = (
533+
provider: ServerProvider,
534+
model: string,
535+
options: ReadonlyArray<ProviderOptionSelection> | undefined,
536+
) => {
537+
const descriptors = advertisedModel(provider, model)?.capabilities?.optionDescriptors;
538+
const requested = withLegacyUltracodeEffort(descriptors, options);
539+
const invalid = requested === undefined ? [] : invalidOptionSelections(requested, descriptors);
540+
return invalid.length === 0
541+
? Effect.void
542+
: Effect.fail(
543+
failure(
544+
"invalid_request",
545+
`Model ${model} on provider ${provider.instanceId} rejected options: ${invalid.join(" ")}`,
546+
),
547+
);
548+
};
549+
530550
function taskStatusForRun(
531551
run: Pick<OrchestrationV2Run, "status" | "restartCancelledBackgroundWork"> | undefined,
532552
): OrchestratorMcpDelegateTaskResult["status"] {
@@ -1785,15 +1805,7 @@ const make = Effect.gen(function* () {
17851805
const advertised = advertisedModel(provider, model);
17861806
const descriptors = advertised?.capabilities?.optionDescriptors;
17871807
const requestedOptions = withLegacyUltracodeEffort(descriptors, input.target?.options);
1788-
if (requestedOptions !== undefined) {
1789-
const invalid = invalidOptionSelections(requestedOptions, descriptors);
1790-
if (invalid.length > 0) {
1791-
return yield* failure(
1792-
"invalid_request",
1793-
`Model ${model} on provider ${instanceId} rejected options: ${invalid.join(" ")}`,
1794-
);
1795-
}
1796-
}
1808+
yield* requireAdvertisedOptions(provider, model, input.target?.options);
17971809

17981810
const inheritsOptions =
17991811
instanceId === inheritedSelection.instanceId &&
@@ -2898,6 +2910,11 @@ const make = Effect.gen(function* () {
28982910
};
28992911
}),
29002912
delegateTask: Effect.fn("OrchestratorMcpService.delegateTask")(function* (callerScope, input) {
2913+
const templateRefusal =
2914+
input.allowLiteralTemplates === true
2915+
? undefined
2916+
: literalTemplateRefusal("task", input.task);
2917+
if (templateRefusal !== undefined) return yield* failure("invalid_request", templateRefusal);
29012918
const environmentId =
29022919
input.target === undefined
29032920
? undefined
Collapse file

‎apps/server/src/mcp/advertisedJsonSchema.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/advertisedJsonSchema.test.ts
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as Schema from "effect/Schema";
33
import { Tool } from "effect/ai";
44

55
import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
6+
import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
7+
import { ProjectToolkit } from "./toolkits/project/tools.ts";
68
import { ThemeToolkit } from "./toolkits/theme/tools.ts";
79

810
it("drops JSON noise, merges tagged unions, and keeps null where it is required", () => {
@@ -59,3 +61,28 @@ it("advertises only string enum values, which Gemini requires", () => {
5961

6062
expect(enumValues.filter((value) => typeof value !== "string")).toEqual([]);
6163
});
64+
65+
it("advertises the key-checked dispatch objects without allOf or open additionalProperties", () => {
66+
const keys: Array<string> = [];
67+
const open: Array<unknown> = [];
68+
const collect = (node: unknown): void => {
69+
if (Array.isArray(node)) return node.forEach(collect);
70+
if (typeof node !== "object" || node === null) return;
71+
for (const [key, value] of Object.entries(node)) {
72+
keys.push(key);
73+
if (key === "additionalProperties" && (value === true || JSON.stringify(value) === "{}"))
74+
open.push(value);
75+
collect(value);
76+
}
77+
};
78+
const propertiesOf = (tool: Tool.Any) =>
79+
advertisedJsonSchema(tool).properties as Record<string, unknown>;
80+
const { target } = propertiesOf(OrchestratorToolkit.tools.delegate_task);
81+
const { modelSelection } = propertiesOf(ProjectToolkit.tools.t3_thread_launch);
82+
collect([target, modelSelection]);
83+
84+
expect(keys).not.toContain("allOf");
85+
expect(open).toEqual([]);
86+
expect(target).toMatchObject({ properties: { model: {}, options: {} } });
87+
expect(modelSelection).toMatchObject({ required: ["model"] });
88+
});
Collapse file

‎apps/server/src/mcp/advertisedJsonSchema.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/advertisedJsonSchema.ts
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type JsonObject = { [key: string]: Json };
77
const isNullSchema = (value: Json) =>
88
Predicate.isObject(value) && value.type === "null" && Object.keys(value).length === 1;
99

10+
const isEmptyObject = (value: Json) => Predicate.isObject(value) && Object.keys(value).length === 0;
11+
1012
const isBareAnyOf = (value: Json): value is { anyOf: Array<Json> } =>
1113
Predicate.isObject(value) && Array.isArray(value.anyOf) && Object.keys(value).length === 1;
1214

@@ -77,7 +79,8 @@ const compact = (schema: Json, optional: boolean): Json => {
7779
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
7880
let result: JsonObject = {};
7981
for (const [key, value] of Object.entries(schema)) {
80-
if (key === "additionalProperties" && value === true) continue;
82+
// `{}` permits any value, as `true` does; a rest record renders it, and Gemini rejects both.
83+
if (key === "additionalProperties" && (value === true || isEmptyObject(value))) continue;
8184
if (SAFE_INTEGER_BOUNDS[key] === value) continue;
8285
if (isNonStringEnum(key, value)) continue;
8386
result[key] =
@@ -90,6 +93,15 @@ const compact = (schema: Json, optional: boolean): Json => {
9093
)
9194
: compact(value, false);
9295
}
96+
if (Array.isArray(result.allOf)) {
97+
// A rest record adds `{type:"object"}` once its open `additionalProperties` is gone.
98+
const allOf = result.allOf.filter(
99+
(entry) =>
100+
!(Predicate.isObject(entry) && entry.type === "object" && Object.keys(entry).length === 1),
101+
);
102+
if (allOf.length === 0) delete result.allOf;
103+
else result.allOf = allOf;
104+
}
93105
if (Array.isArray(result.anyOf)) {
94106
const branches = result.anyOf
95107
.flatMap((branch) => (isBareAnyOf(branch) ? branch.anyOf : [branch]))
@@ -103,7 +115,7 @@ const compact = (schema: Json, optional: boolean): Json => {
103115

104116
/**
105117
* The input schema T3 advertises for a tool. Drops JSON noise that every thread pays for:
106-
* `additionalProperties: true`, safe-integer bounds, nested `anyOf`, JSON-string fallbacks, and
118+
* open `additionalProperties` and the `allOf` it leaves empty, safe-integer bounds, nested `anyOf`, JSON-string fallbacks, and
107119
* the `null` branch of optional properties. A tagged union of objects becomes one object.
108120
* Decoding still uses the full schema, so each tag's own required fields still apply.
109121
*/
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/project/handlers.test.ts
+73-3Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const clientLaunchHarness = (input: {
6666
readonly hostedAppUrl?: string;
6767
/** The orchestrator refuses the new thread's mode, as under a managed ceiling. */
6868
readonly refusedByCeiling?: true;
69+
/** The caller is a linked environment. */
70+
readonly linked?: true;
6971
}) => {
7072
const projectId = ProjectId.make("project:client-target");
7173
const modelSelection = {
@@ -115,6 +117,7 @@ const clientLaunchHarness = (input: {
115117
label: "Claude Code",
116118
access: input.runtimeModeCeiling,
117119
hostedAppUrl: input.hostedAppUrl,
120+
...(input.linked === undefined ? {} : { linked: true }),
118121
},
119122
issuedAt: 0,
120123
capabilities: new Set(["orchestration" as const]),
@@ -401,7 +404,9 @@ it.effect("a launch with a model its provider does not advertise creates no thre
401404
name: "Opus",
402405
aliases: ["opus"],
403406
isCustom: false,
404-
capabilities: null,
407+
capabilities: {
408+
optionDescriptors: [{ id: "fastMode", label: "Fast", type: "boolean" }],
409+
},
405410
}
406411
: { slug: "gpt-5.4", name: "GPT", isCustom: false, capabilities: null },
407412
],
@@ -434,12 +439,12 @@ it.effect("a launch with a model its provider does not advertise creates no thre
434439
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
435440
),
436441
);
437-
const launchWith = (instanceId: string, model: string) =>
442+
const launchWith = (instanceId: string, model: string, extra: object = {}) =>
438443
toolkit
439444
.handle("t3_thread_launch", {
440445
title: "Fix",
441446
projectId,
442-
modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model },
447+
modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model, ...extra },
443448
})
444449
.pipe(
445450
Stream.unwrap,
@@ -459,6 +464,17 @@ it.effect("a launch with a model its provider does not advertise creates no thre
459464
),
460465
});
461466
}
467+
expect(
468+
yield* launchWith("claudeAgent", "claude-opus", {
469+
options: [{ id: "effort", value: "max" }],
470+
}),
471+
).toMatchObject({
472+
code: "invalid_request",
473+
message: expect.stringContaining("Unknown option effort; supported options: fastMode."),
474+
});
475+
expect(String(yield* launchWith("claudeAgent", "claude-opus", { effort: "max" }))).toContain(
476+
'Unknown key "effort" in modelSelection.',
477+
);
462478
expect(launched).toHaveLength(0);
463479

464480
expect(yield* launchWith("claudeAgent", "Opus")).toMatchObject({
@@ -471,6 +487,60 @@ it.effect("a launch with a model its provider does not advertise creates no thre
471487
}),
472488
);
473489

490+
it.effect("a launch whose message still holds a placeholder creates no thread", () =>
491+
Effect.gen(function* () {
492+
const launchWith = Effect.fn("test.launchWith")(function* (
493+
params: { readonly message: string; readonly allowLiteralTemplates?: true },
494+
linked?: true,
495+
) {
496+
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
497+
const { projectId, dependencies } = clientLaunchHarness({
498+
runtimeModeCeiling: "full-access",
499+
launched,
500+
...(linked === undefined ? {} : { linked }),
501+
});
502+
const toolkit = yield* ProjectToolkit.pipe(
503+
Effect.provide(
504+
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(
505+
Layer.provide(dependencies),
506+
),
507+
),
508+
);
509+
const result = yield* toolkit
510+
.handle("t3_thread_launch", {
511+
title: "Review",
512+
projectId,
513+
...params,
514+
...(linked === undefined
515+
? {}
516+
: {
517+
delegatedFrom: {
518+
environmentId: EnvironmentId.make("environment-origin"),
519+
threadId: ThreadId.make("thread-origin"),
520+
title: "Origin",
521+
},
522+
}),
523+
})
524+
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));
525+
return { result: result.at(-1)?.result, launched };
526+
});
527+
528+
for (const message of ["Review.\n\n<<BRIEF>>", "$(cat x)"]) {
529+
const refused = yield* launchWith({ message });
530+
expect(refused.result).toMatchObject({
531+
code: "invalid_request",
532+
message: expect.stringContaining("pass allowLiteralTemplates: true"),
533+
});
534+
expect(refused.launched).toHaveLength(0);
535+
}
536+
const literal = yield* launchWith({ message: "$(cat x)", allowLiteralTemplates: true });
537+
expect(literal.launched[0]?.initialMessage?.text).toBe("$(cat x)");
538+
// The origin's delegate_task already checked a linked environment's delegated brief.
539+
const delegated = yield* launchWith({ message: "<<BRIEF>>" }, true);
540+
expect(delegated.launched).toHaveLength(1);
541+
}),
542+
);
543+
474544
it.effect("a launch retried with the same clientRequestId replays the first one", () =>
475545
Effect.gen(function* () {
476546
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.