fix(server): recover runless native child provider turns #14434
Closedkiiwee(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/14434/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
juliusmarminge closed this
juliusmarminge added labelstriage:keep-open
juliusmarminge reopened this
- apps/server/src/orchestration-v2/EventSink.ts line 399OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +395,21 @@395+ AND thread_id = ${input.threadId}396+ LIMIT 1397+ `;398+ const current = rows[0];399+ if (400+ current === undefined ||401+ current.status !== input.expectedStatus ||402+ current.active_attempt_id !== input.activeAttemptId403+ ) {404+ return {405+ committed: false as const,406+ storedEvents: [] as ReadonlyArray<OrchestrationV2StoredEvent>,407+ };408+ }409+410+ const normalized = yield* normalizeEvents(411+ input.guardPendingUserInputCancellations === true412+ ? yield* guardUserInputCancellations(input.events)413+ : input.events,414+ );415+ const storedEvents = yield* eventStore.append({@@ -0,0 +287,21 @@287+ ).pipe(Effect.ignoreCause({ log: true }));288+289+ const recheckAndBind = Effect.gen(function* () {290+ // The projection was read before the potentially slow git work291+ // above; a concurrent binding (for example from the UI) could have292+ // attached the thread in the meantime. Re-check before committing so293+ // the race cannot leave a second, untracked worktree.294+ const recheck = yield* loadThread(scope);295+ if (recheck.thread.worktreePath !== null) {296+ return yield* alreadyInWorktree(recheck.thread.worktreePath);297+ }298+ // Mirror the up-front archived check: the thread may have been299+ // archived during the slow git work, and an archived thread must300+ // not be bound to a fresh worktree it can never use.301+ if (recheck.thread.archivedAt !== null) {302+ return yield* failure(303+ "invalid_request",304+ `Thread '${scope.threadId}' was archived while the worktree was being created; the handoff was rolled back.`,305+ );306+ }307+ yield* threadManagement@@ -0,0 +32,21 @@32+ success: Project,33+ failure: OrchestratorMcpFailure,34+ failureMode: "return" as const,35+ dependencies: [McpInvocationContext, ThreadManagementService, ProjectService, Crypto.Crypto],36+};37+const ProjectListTool = Tool.make("t3_project_list", {38+ ...shared,39+ description:40+ "List registered projects in this environment. Pages use the current project snapshot and may shift between calls.",41+ parameters: Schema.Struct({42+ cursor: Schema.optional(NonNegativeInt),43+ limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),44+ }),45+ success: Schema.Struct({46+ projects: Schema.Array(Project),47+ nextCursor: Schema.NullOr(NonNegativeInt),48+ }),49+})50+ .annotate(Tool.Readonly, true)51+ .annotate(Tool.Destructive, false);52+const ProjectReadTool = Tool.make("t3_project_read", {apps/server/src/project/ProjectService.ts line 500OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +483,21 @@483+ Effect.mapError(484+ (cause) =>485+ new ProjectOperationError({ operation: "delete-thread", projectId, cause }),486+ ),487+ ),488+ { concurrency: 1, discard: true },489+ );490+ });491+492+ const deleteProject: ProjectService["Service"]["delete"] = Effect.fn("ProjectService.delete")(493+ function* (input) {494+ const { projectId } = input;495+ // A deleted row still reaches commit, so a retried command id replays its496+ // receipt and any other command id is rejected as not found.497+ const existing = yield* readRow(projectId, { includeDeleted: true });498+ if (Option.isNone(existing)) {499+ return yield* new ProjectNotFoundError({ projectId });500+ }501+502+ if (existing.value.deletedAt === null) {503+ yield* deleteChildThreads(input);apps/server/src/project/ProjectService.ts line 397OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +380,21 @@380+ ...(input.defaultModelSelection === undefined381+ ? {}382+ : { defaultModelSelection: input.defaultModelSelection }),383+ ...(input.autoPull === undefined ? {} : { autoPull: input.autoPull }),384+ ...(input.projectIcon === undefined ? {} : { projectIcon: input.projectIcon }),385+ ...(input.faviconPath === undefined ? {} : { faviconPath: input.faviconPath }),386+ ...(input.defaultThreadEnvMode === undefined387+ ? {}388+ : { defaultThreadEnvMode: input.defaultThreadEnvMode }),389+ ...(input.scripts === undefined ? {} : { scripts: input.scripts }),390+ });391+ if (workspaceRoot !== previousRoot) {392+ yield* projectEnrichment.invalidate([previousRoot, workspaceRoot]);393+ }394+ return yield* readCommitted(input.projectId);395+ },396+ );397+398+ const bootstrap: ProjectService["Service"]["bootstrap"] = Effect.fn("ProjectService.bootstrap")(399+ function* (input) {400+ const existing = yield* getByWorkspaceRoot(input.workspaceRoot);apps/server/src/mcp/OrchestratorMcpService.ts line 1481OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1468,21 @@1468+ Effect.catch((error) =>1469+ Effect.logWarning("orchestrator-mcp.delegate-task.wake-policy-failed", {1470+ taskId,1471+ outcome:1472+ error._tag === "OrchestratorCommandPreviouslyRejectedError"1473+ ? "previously_rejected"1474+ : "dispatch_failed",1475+ error,1476+ }),1477+ ),1478+ Effect.catchCause((cause) =>1479+ Effect.logWarning("orchestrator-mcp.delegate-task.wake-policy-failed", {1480+ taskId,1481+ outcome: "defect",1482+ cause,1483+ }),1484+ ),1485+ );1486+ return yield* readTask(scope, taskId, true, true);1487+ }),1488+ taskStatus: (scope, taskId) => readTask(scope, taskId, false, true),apps/server/src/mcp/WorktreeMcpService.ts line 247OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +227,21 @@227+ cwd: projectCwd,228+ refName: baseRef,229+ fallbackRemoteName: "origin",230+ })231+ .pipe(asOperationFailed(`Unable to resolve the remote-tracking commit of '${baseRef}'`));232+ worktreeBaseRef = resolvedRemoteBase.commitSha;233+ }234+235+ const ids = yield* handoffIds(scope);236+237+ // uninterruptibleMask: only the potentially slow worktree creation itself238+ // stays interruptible (restore). From the moment it succeeds, through the239+ // binding, continuation queue, setup script launch, and result240+ // construction, there is no interruptible gap: a client cancel can241+ // therefore neither orphan the created worktree before the rollback is242+ // armed, nor skip setting up a worktree the thread was just bound to243+ // (once the binding commits, the scheduled session detach can sever this244+ // request's connection and interrupt the fiber).245+ return yield* Effect.uninterruptibleMask((restore) =>246+ Effect.gen(function* () {247+ const worktree = yield* restore(
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed