Skip to content

Commit c7714f4

Browse files
committed
fix: satisfy restart sentinel architecture gates
1 parent 0f81165 commit c7714f4

6 files changed

Lines changed: 12 additions & 44 deletions

src/infra/restart-sentinel-store.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import {
77
getNodeSqliteKysely,
88
} from "./kysely-sync.js";
99

10-
export type RestartSentinelLog = {
10+
type RestartSentinelLog = {
1111
stdoutTail?: string | null;
1212
stderrTail?: string | null;
1313
exitCode?: number | null;
1414
};
1515

16-
export type RestartSentinelStep = {
16+
type RestartSentinelStep = {
1717
name: string;
1818
command: string;
1919
cwd?: string | null;
2020
durationMs?: number | null;
2121
log?: RestartSentinelLog | null;
2222
};
2323

24-
export type RestartSentinelStats = {
24+
type RestartSentinelStats = {
2525
mode?: string;
2626
root?: string;
2727
requiresRestart?: boolean;
@@ -70,7 +70,7 @@ export type RestartSentinel = RestartSentinelEnvelope & {
7070
revision: number;
7171
};
7272

73-
export type RestartSentinelRowState =
73+
type RestartSentinelRowState =
7474
| { kind: "missing" }
7575
| { kind: "invalid"; revision: number }
7676
| { kind: "valid"; sentinel: RestartSentinel };
@@ -242,7 +242,7 @@ function parseRestartSentinelContinuation(value: unknown): RestartSentinelContin
242242
return null;
243243
}
244244

245-
export function parseRestartSentinelPayload(value: unknown): RestartSentinelPayload | null {
245+
function parseRestartSentinelPayload(value: unknown): RestartSentinelPayload | null {
246246
if (
247247
!isPlainRecord(value) ||
248248
!RESTART_SENTINEL_KINDS.has(value.kind as RestartSentinelPayload["kind"]) ||

src/infra/restart-sentinel.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
hasRestartSentinel,
5353
markUpdateRestartSentinelFailure,
5454
readRestartSentinel,
55-
rewriteRestartSentinelIfRevision,
5655
summarizeRestartSentinel,
5756
trimLogTail,
5857
writeRestartSentinel,
@@ -310,7 +309,7 @@ describe("restart sentinel", () => {
310309
});
311310
});
312311

313-
it("does not let stale rewrites or deletes replace a newer sentinel", async () => {
312+
it("does not let stale deletes remove a newer sentinel", async () => {
314313
await withRestartSentinelStateDir(async () => {
315314
const first = await writeRestartSentinel({
316315
kind: "restart",
@@ -325,12 +324,6 @@ describe("restart sentinel", () => {
325324
message: "new",
326325
});
327326

328-
await expect(
329-
rewriteRestartSentinelIfRevision(first.revision, (payload) => ({
330-
...payload,
331-
message: "stale rewrite",
332-
})),
333-
).resolves.toBeNull();
334327
await expect(clearRestartSentinelIfRevision(first.revision)).resolves.toBe(false);
335328
await expect(readRestartSentinel()).resolves.toEqual(newer);
336329
});

src/infra/restart-sentinel.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ import {
2020
} from "./restart-sentinel-store.js";
2121

2222
export type {
23-
RestartSentinel,
2423
RestartSentinelContinuation,
25-
RestartSentinelEnvelope,
2624
RestartSentinelPayload,
27-
RestartSentinelStats,
28-
RestartSentinelStep,
2925
} from "./restart-sentinel-store.js";
3026

3127
const sentinelLog = createSubsystemLogger("restart-sentinel");
@@ -54,27 +50,6 @@ function cloneRestartSentinelPayload(payload: RestartSentinelPayload): RestartSe
5450
return structuredClone(payload);
5551
}
5652

57-
export async function rewriteRestartSentinelIfRevision(
58-
expectedRevision: number,
59-
rewrite: (payload: RestartSentinelPayload) => RestartSentinelPayload | null,
60-
env: NodeJS.ProcessEnv = process.env,
61-
): Promise<RestartSentinel | null> {
62-
return runOpenClawStateWriteTransaction(
63-
({ db }) => {
64-
const current = readRestartSentinelRowSync(db);
65-
if (current.kind !== "valid" || current.sentinel.revision !== expectedRevision) {
66-
return null;
67-
}
68-
const nextPayload = rewrite(cloneRestartSentinelPayload(current.sentinel.payload));
69-
return nextPayload
70-
? writeRestartSentinelRowIfRevisionSync(db, nextPayload, expectedRevision)
71-
: null;
72-
},
73-
{ env },
74-
{ operationLabel: "restart-sentinel.rewrite" },
75-
);
76-
}
77-
7853
async function rewriteRestartSentinel(
7954
rewrite: (payload: RestartSentinelPayload) => RestartSentinelPayload | null,
8055
env: NodeJS.ProcessEnv = process.env,

src/infra/state-migrations.restart-sentinel.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
writeRestartSentinelRowSync,
2323
type RestartSentinelEnvelope,
2424
} from "./restart-sentinel-store.js";
25+
import type { LegacyRestartSentinelDetection } from "./state-migrations.restart-sentinel.types.js";
2526
import type { MigrationMessages } from "./state-migrations.types.js";
2627

2728
const LEGACY_RESTART_SENTINEL_FILENAME = "restart-sentinel.json";
@@ -37,11 +38,6 @@ type RestartSentinelMigrationDatabase = Pick<
3738
"gateway_restart_sentinel" | "migration_runs" | "migration_sources"
3839
>;
3940

40-
export type LegacyRestartSentinelDetection = {
41-
sourcePath: string;
42-
hasLegacy: boolean;
43-
};
44-
4541
type LegacySourceSnapshot = {
4642
buffer: Buffer;
4743
dev: number;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type LegacyRestartSentinelDetection = {
2+
sourcePath: string;
3+
hasLegacy: boolean;
4+
};

src/infra/state-migrations.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { SessionScope } from "../config/sessions/types.js";
33
import type { PluginDoctorStateMigration } from "../plugins/doctor-contract-registry.js";
44
import type { LegacyChannelPairingStateDetection } from "./state-migrations.channel-pairing.js";
55
import type { LegacyMcpOAuthDetection } from "./state-migrations.mcp-oauth.types.js";
6-
import type { LegacyRestartSentinelDetection } from "./state-migrations.restart-sentinel.js";
6+
import type { LegacyRestartSentinelDetection } from "./state-migrations.restart-sentinel.types.js";
77
import type { LegacyWorkspaceStateDetection } from "./state-migrations.workspace-setup.types.js";
88

99
export type LegacyRescuePendingDetection = {

0 commit comments

Comments
 (0)