Skip to content

Commit 408ab86

Browse files
committed
fix(server): carry upstream's bootstrap guarantees into the fork's bootstrap service
Upstream added a deletion-cleanup fence and a local base branch fallback to its own bootstrap path. The fork serves that path from its own service, so neither reached users of this fork until they were ported across. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 06bcae8 commit 408ab86

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎apps/server/src/orchestration/Layers/ThreadBootstrap.ts‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { GitWorkflowService } from "../../git/GitWorkflowService.ts";
1515
import * as ProjectSetupScriptRunner from "../../project/ProjectSetupScriptRunner.ts";
1616
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
1717
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
18+
import { ThreadDeletionReactor } from "../Services/ThreadDeletionReactor.ts";
1819
import { ThreadBootstrapService, type ThreadBootstrapShape } from "../Services/ThreadBootstrap.ts";
1920

2021
const isOrchestrationDispatchCommandError = Schema.is(OrchestrationDispatchCommandError);
@@ -63,6 +64,7 @@ const makeThreadBootstrap = Effect.gen(function* () {
6364
const gitWorkflow = yield* GitWorkflowService;
6465
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
6566
const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;
67+
const threadDeletionReactor = yield* ThreadDeletionReactor;
6668
const crypto = yield* Crypto.Crypto;
6769

6870
const toDispatchCommandError = (cause: unknown, fallbackMessage: string) =>
@@ -289,7 +291,7 @@ const makeThreadBootstrap = Effect.gen(function* () {
289291

290292
const bootstrapProgram = Effect.gen(function* () {
291293
if (bootstrap?.createThread) {
292-
yield* orchestrationEngine.dispatch(
294+
const created = yield* orchestrationEngine.dispatch(
293295
{
294296
type: "thread.create",
295297
commandId: yield* serverCommandId("bootstrap-thread-create"),
@@ -306,14 +308,20 @@ const makeThreadBootstrap = Effect.gen(function* () {
306308
},
307309
options,
308310
);
311+
// The successful create is a fence in the engine command queue:
312+
// every delete for the prior incarnation committed before it.
313+
// Drain through that event before setup or turn start can own
314+
// terminals and provider sessions under the reused thread id.
315+
yield* threadDeletionReactor.drainThrough(created.sequence);
309316
createdThread = true;
310317
}
311318

312319
if (bootstrap?.prepareWorktree) {
313320
let worktreeBaseRef = bootstrap.prepareWorktree.baseBranch;
314-
// "Start from origin" is a stored default; repos without an
315-
// origin remote fall back to the local base branch instead of
316-
// failing the whole bootstrap on `git fetch origin`.
321+
// "Start from origin" is a stored default; repos without the
322+
// requested remote branch, or without an origin remote at all,
323+
// fall back to the local base branch instead of failing the whole
324+
// bootstrap on `git fetch origin`.
317325
const startFromOrigin =
318326
bootstrap.prepareWorktree.startFromOrigin === true &&
319327
(yield* gitWorkflow.remoteExists({
@@ -325,12 +333,19 @@ const makeThreadBootstrap = Effect.gen(function* () {
325333
cwd: bootstrap.prepareWorktree.projectCwd,
326334
remoteName: "origin",
327335
});
328-
const resolvedRemoteBase = yield* gitWorkflow.resolveRemoteTrackingCommit({
336+
const remoteBaseExists = yield* gitWorkflow.remoteBranchExists({
329337
cwd: bootstrap.prepareWorktree.projectCwd,
330338
refName: bootstrap.prepareWorktree.baseBranch,
331-
fallbackRemoteName: "origin",
339+
remoteName: "origin",
332340
});
333-
worktreeBaseRef = resolvedRemoteBase.commitSha;
341+
if (remoteBaseExists) {
342+
const resolvedRemoteBase = yield* gitWorkflow.resolveRemoteTrackingCommit({
343+
cwd: bootstrap.prepareWorktree.projectCwd,
344+
refName: bootstrap.prepareWorktree.baseBranch,
345+
fallbackRemoteName: "origin",
346+
});
347+
worktreeBaseRef = resolvedRemoteBase.commitSha;
348+
}
334349
}
335350
const worktree = yield* gitWorkflow.createWorktree({
336351
cwd: bootstrap.prepareWorktree.projectCwd,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ const buildAppUnderTest = (options?: {
680680
Layer.provide(gitWorkflowLayer),
681681
Layer.provide(projectSetupScriptRunnerLayer),
682682
Layer.provide(vcsStatusBroadcasterLayer),
683+
Layer.provide(threadDeletionReactorLayer),
683684
);
684685
const resourceTelemetryLayer = ResourceTelemetry.layer.pipe(
685686
Layer.provide(

0 commit comments

Comments
 (0)