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 — Scheduled tasks: check the saving thread's MCP profile in the service… · scuttletoby/t3code@1c95c08

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • fork-seams.json
  • apps/server/src
    • fork
      • agentSlotRoutes.ts
      • launchMcpProfile.ts
      • mcpProfile.ts
      • scheduledTaskMcpProfile.test.ts
      • scheduledTaskMcpProfile.ts
    • holdWork.boot.test.ts
    • mcp/toolkits/orchestrator
      • handlers.ts
    • scheduledTasks
      • ScheduledTaskService.ts
  • docs/fork
    • README.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/fork-seams.json‎

Copy file name to clipboardExpand all lines: .github/fork-seams.json
+5-16Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,17 @@
260260
"if (slot.skipped !== null) return slot.skipped; // Fork: a skipped run is recorded",
261261
"yield* slot.end(threadId); // Fork: the slot names the run's thread",
262262
"Effect.ensuring(runSlots.ended(task.id)), // Fork: a failed run frees its slot",
263-
"runSlots.directDelivery(deliveryId, request, pendingWebhooks.invalidate), // Fork: a waiting direct delivery is stored"
264-
],
265-
"announced": {
266-
"since": "2026-11-21",
267-
"added": [
268-
"yield* runSlots.saving(task, existingTask); // Fork: the saving thread's MCP profile"
269-
]
270-
}
263+
"runSlots.directDelivery(deliveryId, request, pendingWebhooks.invalidate), // Fork: a waiting direct delivery is stored",
264+
"yield* runSlots.saving(task, existingTask); // Fork: the saving thread's MCP profile"
265+
]
271266
},
272267
"apps/server/src/mcp/toolkits/orchestrator/handlers.ts": {
273268
"why": "schedule_task from a thread whose MCP profile is narrower than \"all\" is refused when the task's runs would start a thread with more than the caller's profile, on create and on a change to a task whose runs start new threads (fork/launchMcpProfile.ts, #693). A change from such a thread to the prompt or thread of a task bound to a wider thread is refused there too, before the service uses up a webhook secretRef (#699).",
274269
"added": [
275270
"import * as LaunchMcpProfile from \"../../../fork/launchMcpProfile.ts\"; // Fork: MCP profile launch",
276271
"yield* LaunchMcpProfile.checkScheduleMcpProfile(input); // Fork: MCP profile launch",
277-
"yield* LaunchMcpProfile.checkScheduleEditMcpProfile(scheduledTaskId, bindToCurrentThread); // Fork: MCP profile launch"
278-
],
279-
"announced": {
280-
"since": "2026-11-21",
281-
"added": [
282-
"yield* LaunchMcpProfile.checkEditMcpProfile(scheduledTaskId, bindToCurrentThread, prompt); // Fork: MCP profile launch"
283-
]
284-
}
272+
"yield* LaunchMcpProfile.checkEditMcpProfile(scheduledTaskId, bindToCurrentThread, prompt); // Fork: MCP profile launch"
273+
]
285274
},
286275
"apps/server/src/mcp/toolkits/thread/handlers.ts": {
287276
"why": "t3_thread_transfer's fork from a thread whose MCP profile is narrower than \"all\" is refused when the fork would get more than the caller's profile, and run_scheduled_task_now on a task whose runs would start such a thread (fork/launchMcpProfile.ts, #693); run_scheduled_task_now refused by the agent slot gate answers slots_full (fork/agentSlotRoutes.ts, #706; the prettier-ignore keeps upstream's run_scheduled_task_now lines as they are, since a second pipe step would make the formatter reflow them).",
Collapse file

‎apps/server/src/fork/agentSlotRoutes.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/agentSlotRoutes.ts
+38-3Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { encodePendingTask } from "../scheduledTasks/webhookDedupe.ts";
2727
import type { WebhookRequest } from "../scheduledTasks/webhookTemplate.ts";
2828
import * as Scheduler from "../scheduling/Scheduler.ts";
2929
import * as SlotGate from "../slots/SlotGate.ts";
30+
import { makeScheduledTaskMcpProfiles } from "./scheduledTaskMcpProfile.ts";
3031

3132
type Refused = Extract<SlotGate.SlotAcquire, { readonly type: "refuse" }>;
3233
type FullDecision = Extract<SlotDecision, { readonly type: "refuse" }>;
@@ -317,6 +318,9 @@ export const makeScheduledRunSlots = Effect.fnUntraced(function* <W>(
317318
// The production wiring gives scheduled runs the gate; a boot test looks for this span.
318319
if (Option.isSome(gate))
319320
yield* Effect.void.pipe(Effect.withSpan("AgentSlotRoutes.scheduledRunsGated"));
321+
// Who saved each task, and the run check on it: built here, where the service's one fork
322+
// line already builds the slots, so the service needs no second build line.
323+
const profiles = yield* makeScheduledTaskMcpProfiles(threads);
320324

321325
/**
322326
* The slot each running task holds until its dispatch ends (one run per task at a time), so
@@ -472,6 +476,9 @@ export const makeScheduledRunSlots = Effect.fnUntraced(function* <W>(
472476
yield* Effect.sleep(WEBHOOK_SLOT_RETRY);
473477
const gone = yield* webhookGone(task).pipe(Effect.orElseSucceed(() => null));
474478
if (gone !== null) return yield* Effect.fail(new WebhookSkipped({ reason: gone }));
479+
// Checked again as it would start: the owner may have widened the project meanwhile.
480+
const refused = task.threadId === null ? yield* profiles.runRefusal(task) : null;
481+
if (refused !== null) return yield* Effect.fail(new WebhookSkipped({ reason: refused }));
475482
const target = yield* targetOf(task);
476483
if (target.queuesOnly) return allowed(task, () => Effect.void);
477484
const slot = yield* take(target.instanceId);
@@ -488,14 +495,36 @@ export const makeScheduledRunSlots = Effect.fnUntraced(function* <W>(
488495
task: ScheduledTask,
489496
trigger: "scheduled" | "manual" | "webhook",
490497
now: DateTime.DateTime,
491-
// The missed-run rescheduler: a run that waits is not rescheduled.
492-
_reschedule: (
498+
// The missed-run rescheduler: a run that waits is not rescheduled; a refused one is.
499+
reschedule: (
493500
task: ScheduledTask,
494501
now: DateTime.DateTime,
495502
reason: string,
496503
runError: string,
497504
) => Effect.Effect<void, E, R>,
498505
) {
506+
// A new thread wider than the profile the task was saved with starts nothing: on its schedule
507+
// a failed run with the reason (moved to its next time), "run now" fails, a webhook skips.
508+
const profileRefusal = task.threadId === null ? yield* profiles.runRefusal(task) : null;
509+
if (profileRefusal !== null) {
510+
if (trigger === "manual") {
511+
return yield* new ScheduledTaskError({ message: profileRefusal, taskId: task.id });
512+
}
513+
if (trigger === "webhook")
514+
return yield* Effect.fail(new WebhookSkipped({ reason: profileRefusal }));
515+
yield* reschedule(task, now, "MCP profile", profileRefusal).pipe(
516+
Effect.catchCause((cause) =>
517+
Effect.logWarning("Could not record a scheduled run refused for its MCP profile", {
518+
taskId: task.id,
519+
cause,
520+
}),
521+
),
522+
);
523+
return {
524+
skipped: { task, threadId: null, dispatchFailed: false },
525+
end: () => Effect.void,
526+
} as ScheduledSlot;
527+
}
499528
if (Option.isNone(gate)) return { skipped: null, end: () => Effect.void } as ScheduledSlot;
500529
const target = yield* targetOf(task);
501530
if (target.queuesOnly) return allowed(task, () => Effect.void);
@@ -556,5 +585,11 @@ export const makeScheduledRunSlots = Effect.fnUntraced(function* <W>(
556585
});
557586
yield* scheduler.register("agent-slot-notes", clearStaleNotes);
558587

559-
return { admit: admitRun, ended, directDelivery };
588+
return {
589+
admit: admitRun,
590+
ended,
591+
directDelivery,
592+
/** `ScheduledTaskService.upsert`, last before it writes the row (`scheduledTaskMcpProfile.ts`). */
593+
saving: profiles.saving,
594+
};
560595
});
Collapse file

‎apps/server/src/fork/launchMcpProfile.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/launchMcpProfile.ts
+43-9Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* Fork: a thread started by a narrower thread (`t3_thread_launch`, `create_threads`, a
33
* `schedule_task` whose runs start new threads, a `t3_thread_transfer` fork) is refused unless its
4-
* profile is within the starter's; `delegate_task` cuts a child to its parent as before.
4+
* profile is within the starter's; `delegate_task` cuts a child to its parent as before. The
5+
* scheduled task service checks a save and a run again (`scheduledTaskMcpProfile.ts`).
56
*/
67
import {
78
OrchestratorMcpFailure,
@@ -22,6 +23,7 @@ import {
2223
makeThreadMcpProfiles,
2324
} from "./claudeMcpProfile.ts";
2425
import { isEveryMcpTool, isWithinMcpProfile, type McpProfileResolved } from "./mcpProfile.ts";
26+
import { boundToWiderRefusal } from "./scheduledTaskMcpProfile.ts";
2527

2628
type Refusal = { readonly reason: string };
2729

@@ -165,16 +167,19 @@ export const checkScheduleMcpProfile = Effect.fn("LaunchMcpProfile.schedule")(fu
165167
});
166168

167169
/**
168-
* A task here whose runs, after a change (`bindToCurrentThread` as the call gives it), start a
169-
* thread wider than the caller's profile is refused, whoever made it; `done` ends the refusal.
170+
* A task here whose runs, after a change (`bindToCurrentThread` and `prompt` as the call gives
171+
* them), start a thread wider than the caller's profile is refused, whoever made it, and so is a
172+
* change to the prompt or thread of a task bound to another, wider thread; `done` ends the refusal.
170173
*/
171174
const checkTaskRuns = Effect.fn("LaunchMcpProfile.taskRuns")(function* (
172175
scheduledTaskId: ScheduledTaskId,
173176
bindToCurrentThread: boolean | undefined,
174177
done: string,
178+
prompt?: string | undefined,
175179
) {
176-
const { caller } = yield* loadCaller();
177-
if (caller === undefined || bindToCurrentThread === true) return;
180+
const { caller, threads } = yield* loadCaller();
181+
if (caller === undefined) return;
182+
const changesBound = prompt !== undefined || bindToCurrentThread !== undefined;
178183
// Upstream's orchestrator toolkit does not name this service; the server provides it to every
179184
// toolkit, and without it the task cannot be read, so the call is refused.
180185
const service = yield* Effect.serviceOption(ScheduledTasks.ScheduledTaskService);
@@ -195,6 +200,33 @@ const checkTaskRuns = Effect.fn("LaunchMcpProfile.taskRuns")(function* (
195200
);
196201
const task = tasks.find((candidate) => candidate.id === scheduledTaskId);
197202
if (task === undefined) return;
203+
// Bound to another thread: the service's rule (scheduledTaskMcpProfile.ts), here too so a refused
204+
// change does not use up the webhook secretRef it carries (the service consumes it first).
205+
if (task.threadId !== null && changesBound) {
206+
const profileFor = yield* Effect.mapError(yield* makeThreadMcpProfileReads, launcherUnknown);
207+
const own = yield* Effect.mapError(profileFor(caller), launcherUnknown);
208+
const refusal = yield* boundToWiderRefusal({
209+
profileFor,
210+
threads,
211+
own,
212+
callerId: caller.id,
213+
existing: task,
214+
next: {
215+
prompt: prompt ?? task.prompt,
216+
projectId: task.projectId,
217+
threadId:
218+
bindToCurrentThread === true
219+
? caller.id
220+
: bindToCurrentThread === false
221+
? null
222+
: task.threadId,
223+
},
224+
});
225+
if (refusal !== null) {
226+
return yield* new OrchestratorMcpFailure({ code: "capability_denied", message: refusal });
227+
}
228+
}
229+
if (bindToCurrentThread === true) return;
198230
// The service keeps the stored thread unless the call binds or unbinds it.
199231
const threadId = bindToCurrentThread === false ? null : task.threadId;
200232
if (threadId !== null) return;
@@ -207,13 +239,15 @@ const checkTaskRuns = Effect.fn("LaunchMcpProfile.taskRuns")(function* (
207239
});
208240

209241
/**
210-
* `schedule_task` changing a task here (unbind, rewrite, re-enable, pause): refused by the rule
211-
* above. Deleting it or binding it to the caller is the way out; a missing task is the service's.
242+
* `schedule_task` changing a scheduled task here (unbind, rewrite, re-enable, pause): refused by
243+
* the rules above. Deleting it or binding it to the caller is the way out; a missing task is the
244+
* service's.
212245
*/
213-
export const checkScheduleEditMcpProfile = (
246+
export const checkEditMcpProfile = (
214247
scheduledTaskId: ScheduledTaskId,
215248
bindToCurrentThread: boolean | undefined,
216-
) => checkTaskRuns(scheduledTaskId, bindToCurrentThread, "the task was not changed");
249+
prompt: string | undefined,
250+
) => checkTaskRuns(scheduledTaskId, bindToCurrentThread, "the task was not changed", prompt);
217251

218252
/** `run_scheduled_task_now` here: the run starts the task's thread now, so the same rule holds. */
219253
export const checkScheduleRunMcpProfile = (scheduledTaskId: ScheduledTaskId) =>
Collapse file

‎apps/server/src/fork/mcpProfile.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/mcpProfile.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,17 @@ export const carryMcpProfile = (resolved: McpProfileResolved): McpProfileCarried
285285
t3Tools: resolved.profile.t3Tools,
286286
});
287287

288-
type CarriedLookup =
288+
export type CarriedLookup =
289289
| { readonly ok: true; readonly name: string; readonly profile: McpProfileSet }
290290
| { readonly ok: false; readonly name: string; readonly issue: string };
291291

292292
/**
293293
* A carried profile, checked as strictly as a settings entry: a field this build does not know
294294
* could narrow the profile, so it refuses rather than being dropped. T3 tool groups it does not
295-
* know keep nothing, which only narrows.
295+
* know keep nothing, which only narrows. Also reads a profile a scheduled task was saved with
296+
* (`scheduledTaskMcpProfile.ts`).
296297
*/
297-
function readCarried(value: unknown): CarriedLookup {
298+
export function readCarried(value: unknown): CarriedLookup {
298299
const name = isRecord(value) && typeof value.name === "string" ? value.name : "";
299300
if (!isRecord(value)) return { ok: false, name, issue: "it is not an object" };
300301
const extra = Object.keys(value).filter((field) => !CARRIED_FIELDS.has(field));

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.