GeezerVison is showing github.com — fix(session,server,tui,core,enterprise,sdk): wave 7–11 hardening — au… · anomalyco/opencode@56feb5c
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/schema.json +34-2Lines changed: 34 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "version": "7", | 3 | 3 | "dialect": "sqlite", | 4 | | - "id": "9f5f9a05-d53b-40e9-abd3-67e93c5f9829", | 5 | | - "prevIds": ["f3e4e554-6717-4c4c-87e3-4cda84056492"], | | 4 | + "id": "1c58c2e1-5cbe-4c41-b1b9-62b6e04da763", | | 5 | + "prevIds": ["9f5f9a05-d53b-40e9-abd3-67e93c5f9829"], | 6 | 6 | "ddl": [ | 7 | 7 | { | 8 | 8 | "name": "workspace", | | 544 | 544 | "entityType": "columns", | 545 | 545 | "table": "event" | 546 | 546 | }, | | 547 | + { | | 548 | + "type": "text", | | 549 | + "notNull": false, | | 550 | + "autoincrement": false, | | 551 | + "default": null, | | 552 | + "generated": null, | | 553 | + "name": "tombstone_digest", | | 554 | + "entityType": "columns", | | 555 | + "table": "event" | | 556 | + }, | 547 | 557 | { | 548 | 558 | "type": "text", | 549 | 559 | "notNull": false, | | 2087 | 2097 | "entityType": "indexes", | 2088 | 2098 | "table": "session_message" | 2089 | 2099 | }, | | 2100 | + { | | 2101 | + "columns": [ | | 2102 | + { | | 2103 | + "value": "session_id", | | 2104 | + "isExpression": false | | 2105 | + }, | | 2106 | + { | | 2107 | + "value": "json_extract(\"data\", '$.callID')", | | 2108 | + "isExpression": true | | 2109 | + }, | | 2110 | + { | | 2111 | + "value": "seq", | | 2112 | + "isExpression": false | | 2113 | + } | | 2114 | + ], | | 2115 | + "isUnique": false, | | 2116 | + "where": null, | | 2117 | + "origin": "manual", | | 2118 | + "name": "session_message_session_call_id_seq_idx", | | 2119 | + "entityType": "indexes", | | 2120 | + "table": "session_message" | | 2121 | + }, | 2090 | 2122 | { | 2091 | 2123 | "columns": [ | 2092 | 2124 | { | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/background-job.ts +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | export * as BackgroundJob from "./background-job" | 2 | 2 |
| 3 | | -import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Scope, SynchronizedRef } from "effect" | | 3 | +import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Scope, Schema, SynchronizedRef } from "effect" | 4 | 4 | import { Identifier } from "./id/id" | 5 | 5 | import { makeGlobalNode } from "./effect/app-node" | 6 | 6 |
| @@ -87,13 +87,18 @@ export type WaitResult = { | 87 | 87 | timedOut: boolean | 88 | 88 | } | 89 | 89 |
| | 90 | +/** A promoted-result waiter raced a job that is no longer retained (missing or pruned). */ | | 91 | +export class NotFoundError extends Schema.TaggedErrorClass<NotFoundError>()("BackgroundJob.NotFound", { | | 92 | + id: Schema.String, | | 93 | +}) {} | | 94 | + | 90 | 95 | export interface Interface { | 91 | 96 | readonly list: () => Effect.Effect<Info[]> | 92 | 97 | readonly get: (id: string) => Effect.Effect<Info | undefined> | 93 | 98 | readonly start: (input: StartInput) => Effect.Effect<Info> | 94 | 99 | readonly extend: (input: ExtendInput) => Effect.Effect<boolean> | 95 | 100 | readonly wait: (input: WaitInput) => Effect.Effect<WaitResult> | 96 | | - readonly waitForPromotion: (id: string) => Effect.Effect<Info> | | 101 | + readonly waitForPromotion: (id: string) => Effect.Effect<Info | undefined, NotFoundError> | 97 | 102 | readonly promote: (id: string) => Effect.Effect<Info | undefined> | 98 | 103 | readonly cancel: (id: string) => Effect.Effect<Info | undefined> | 99 | 104 | } | @@ -336,8 +341,11 @@ export const make = Effect.gen(function* () { | 336 | 341 |
| 337 | 342 | const waitForPromotion: Interface["waitForPromotion"] = Effect.fn("BackgroundJob.waitForPromotion")(function* (id) { | 338 | 343 | const job = (yield* SynchronizedRef.get(state.jobs)).get(id) | 339 | | - if (!job || job.info.status !== "running" || !job.promoted) return yield* Effect.never | | 344 | + if (!job) return yield* new NotFoundError({ id }) | 340 | 345 | if (job.info.metadata?.background === true) return snapshot(job) | | 346 | + // A settled job can never be promoted; resolving its terminal snapshot avoids a waiter hang. | | 347 | + if (job.info.status !== "running") return snapshot(job) | | 348 | + if (!job.promoted) return yield* Effect.never | 341 | 349 | return yield* Deferred.await(job.promoted) | 342 | 350 | }) | 343 | 351 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/cross-spawn-spawner.ts +22-14Lines changed: 22 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,9 @@ import { filesystem, path } from "./effect/app-node-platform" | 29 | 29 |
| 30 | 30 | const toError = (err: unknown): Error => (err instanceof globalThis.Error ? err : new globalThis.Error(String(err))) | 31 | 31 |
| | 32 | +/** Teardown bound when `forceKillAfter` is unset, so a child that ignores the kill signal cannot stall scope exit. */ | | 33 | +const DEFAULT_FORCE_KILL_AFTER = "5 seconds" as const | | 34 | + | 32 | 35 | const toTag = (err: NodeJS.ErrnoException): PlatformError.SystemErrorTag => { | 33 | 36 | switch (err.code) { | 34 | 37 | case "ENOENT": | @@ -284,8 +287,12 @@ export const make = Effect.gen(function* () { | 284 | 287 | proc.on("spawn", () => { | 285 | 288 | resume(Effect.succeed([proc, signal])) | 286 | 289 | }) | 287 | | - return Effect.sync(() => { | | 290 | + return Effect.suspend(() => { | 288 | 291 | proc.kill("SIGTERM") | | 292 | + return Effect.timeoutOrElse(Deferred.await(signal), { | | 293 | + duration: command.options.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER, | | 294 | + orElse: () => Effect.sync(() => void proc.kill("SIGKILL")), | | 295 | + }).pipe(Effect.asVoid) | 289 | 296 | }) | 290 | 297 | }) | 291 | 298 |
| @@ -315,10 +322,15 @@ export const make = Effect.gen(function* () { | 315 | 322 | command: ChildProcess.StandardCommand, | 316 | 323 | proc: NodeChildProcess.ChildProcess, | 317 | 324 | signal: NodeJS.Signals, | | 325 | + exited: Effect.Effect<boolean>, | 318 | 326 | ) => | 319 | 327 | Effect.suspend(() => { | 320 | 328 | if (proc.kill(signal)) return Effect.void | 321 | | - return Effect.fail(toPlatformError("kill", new Error("Failed to kill child process"), command)) | | 329 | + return exited.pipe( | | 330 | + Effect.flatMap((done) => | | 331 | + done ? Effect.void : Effect.fail(toPlatformError("kill", new Error("Failed to kill child process"), command)), | | 332 | + ), | | 333 | + ) | 322 | 334 | }) | 323 | 335 |
| 324 | 336 | const timeout = | @@ -335,9 +347,8 @@ export const make = Effect.gen(function* () { | 335 | 347 | ) => Effect.Effect<A, E, R>, | 336 | 348 | ) => { | 337 | 349 | const signal = opts?.killSignal ?? "SIGTERM" | 338 | | - if (Predicate.isUndefined(opts?.forceKillAfter)) return f(command, proc, signal) | 339 | 350 | return Effect.timeoutOrElse(f(command, proc, signal), { | 340 | | - duration: opts.forceKillAfter, | | 351 | + duration: opts?.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER, | 341 | 352 | orElse: () => f(command, proc, "SIGKILL"), | 342 | 353 | }) | 343 | 354 | } | @@ -389,15 +400,13 @@ export const make = Effect.gen(function* () { | 389 | 400 | return yield* Effect.void | 390 | 401 | } | 391 | 402 | const send = (s: NodeJS.Signals) => | 392 | | - Effect.catch(killGroup(command, proc, s), () => killOne(command, proc, s)) | | 403 | + Effect.catch(killGroup(command, proc, s), () => killOne(command, proc, s, Deferred.isDone(signal))) | 393 | 404 | const sig = command.options.killSignal ?? "SIGTERM" | 394 | 405 | const attempt = send(sig).pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid) | 395 | | - const escalated = command.options.forceKillAfter | 396 | | - ? Effect.timeoutOrElse(attempt, { | 397 | | - duration: command.options.forceKillAfter, | 398 | | - orElse: () => send("SIGKILL").pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid), | 399 | | - }) | 400 | | - : attempt | | 406 | + const escalated = Effect.timeoutOrElse(attempt, { | | 407 | + duration: command.options.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER, | | 408 | + orElse: () => send("SIGKILL").pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid), | | 409 | + }) | 401 | 410 | return yield* Effect.ignore(escalated) | 402 | 411 | }), | 403 | 412 | ) | @@ -427,11 +436,10 @@ export const make = Effect.gen(function* () { | 427 | 436 | kill: (opts?: ChildProcess.KillOptions) => { | 428 | 437 | const sig = opts?.killSignal ?? "SIGTERM" | 429 | 438 | const send = (s: NodeJS.Signals) => | 430 | | - Effect.catch(killGroup(command, proc, s), () => killOne(command, proc, s)) | | 439 | + Effect.catch(killGroup(command, proc, s), () => killOne(command, proc, s, Deferred.isDone(signal))) | 431 | 440 | const attempt = send(sig).pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid) | 432 | | - if (!opts?.forceKillAfter) return attempt | 433 | 441 | return Effect.timeoutOrElse(attempt, { | 434 | | - duration: opts.forceKillAfter, | | 442 | + duration: opts?.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER, | 435 | 443 | orElse: () => send("SIGKILL").pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid), | 436 | 444 | }) | 437 | 445 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/database/migration.gen.ts +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { Effect } from "effect" | | 2 | +import type { DatabaseMigration } from "../migration" | | 3 | + | | 4 | +export default { | | 5 | + id: "20260917225834_wave7_l3_event_tombstone_and_shell_index", | | 6 | + up(tx) { | | 7 | + return Effect.gen(function* () { | | 8 | + yield* tx.run(`ALTER TABLE \`event\` ADD \`tombstone_digest\` text;`) | | 9 | + yield* tx.run( | | 10 | + `CREATE INDEX \`session_message_session_call_id_seq_idx\` ON \`session_message\` (\`session_id\`,json_extract("data", '$.callID'),\`seq\`);`, | | 11 | + ) | | 12 | + }) | | 13 | + }, | | 14 | +} satisfies DatabaseMigration.Migration |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/database/schema.gen.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,6 +83,7 @@ export default { | 83 | 83 | \`seq\` integer NOT NULL, | 84 | 84 | \`type\` text NOT NULL, | 85 | 85 | \`data\` text NOT NULL, | | 86 | + \`tombstone_digest\` text, | 86 | 87 | CONSTRAINT \`fk_event_aggregate_id_event_sequence_aggregate_id_fk\` FOREIGN KEY (\`aggregate_id\`) REFERENCES \`event_sequence\`(\`aggregate_id\`) ON DELETE CASCADE | 87 | 88 | ); | 88 | 89 | `) | @@ -275,6 +276,9 @@ export default { | 275 | 276 | yield* tx.run( | 276 | 277 | `CREATE INDEX \`session_message_session_time_created_id_idx\` ON \`session_message\` (\`session_id\`,\`time_created\`,\`id\`);`, | 277 | 278 | ) | | 279 | + yield* tx.run( | | 280 | + `CREATE INDEX \`session_message_session_call_id_seq_idx\` ON \`session_message\` (\`session_id\`,json_extract("data", '$.callID'),\`seq\`);`, | | 281 | + ) | 278 | 282 | yield* tx.run(`CREATE INDEX \`session_project_idx\` ON \`session\` (\`project_id\`);`) | 279 | 283 | yield* tx.run(`CREATE INDEX \`session_workspace_idx\` ON \`session\` (\`workspace_id\`);`) | 280 | 284 | yield* tx.run(`CREATE INDEX \`session_parent_idx\` ON \`session\` (\`parent_id\`);`) | |
|