Skip to content

Commit 56feb5c

Browse files
fix(session,server,tui,core,enterprise,sdk): wave 7–11 hardening — audits, security, SSE, DB, lifecycle
Two adversarial audit rounds (opus + deepseek: O-01..O-40, O2-01..O2-47, D-01..D-27, D2-01..D2-08, 12 drifts) remediated by six parallel lanes per wave with fix-on-sight and two-consecutive-zero-change-pass loops. - security: file-taint symlink containment (check-vs-use TOCTOU), webfetch SSRF guards (hex/mapped IPv6, DNS pinning, body caps, DNS-before-permission), shell containment, lock ordering, secret env blocklist - server: /event directory filter, desync latch reset, proxy stream-failure handling, /sync/steal + history bounds, sse-frame byte cap + 5xx buffering, share-id entropy, host-header proxy caveat - core: event read path (readAllAfter O(N²), tombstone N+1, expression index + migration 20260917225834), projector hot paths (migration 20260917212851), retry TX coverage, listener isolation - session/processor: abort semantics (error + interrupted metadata), retry text dedup, errored-turn drops, deltaLock terminal sites, tool-part settle, compaction drop, share trim/metadata merge - tui/cli: context-usage selector sharing, stream.transport eager sort removal, acp lifecycle, help snapshot - mcp/enterprise/lsp/sdk: OAuth transport close, catalog names, rate limiting, chunked body caps, ws-pool busy eviction, process caps, broken-set lsp Evidence: full opencode suite 3756 tests / 0 fail (264 files, 670s); core 1120/0; tui 207/0; typecheck exit 0 for core/opencode/tui/server/enterprise/sdk; prettier clean.
1 parent 15315be commit 56feb5c

127 files changed

Lines changed: 4346 additions & 824 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/core/schema.json‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"version": "7",
33
"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"],
66
"ddl": [
77
{
88
"name": "workspace",
@@ -544,6 +544,16 @@
544544
"entityType": "columns",
545545
"table": "event"
546546
},
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+
},
547557
{
548558
"type": "text",
549559
"notNull": false,
@@ -2087,6 +2097,28 @@
20872097
"entityType": "indexes",
20882098
"table": "session_message"
20892099
},
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+
},
20902122
{
20912123
"columns": [
20922124
{

‎packages/core/src/background-job.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * as BackgroundJob from "./background-job"
22

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"
44
import { Identifier } from "./id/id"
55
import { makeGlobalNode } from "./effect/app-node"
66

@@ -87,13 +87,18 @@ export type WaitResult = {
8787
timedOut: boolean
8888
}
8989

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+
9095
export interface Interface {
9196
readonly list: () => Effect.Effect<Info[]>
9297
readonly get: (id: string) => Effect.Effect<Info | undefined>
9398
readonly start: (input: StartInput) => Effect.Effect<Info>
9499
readonly extend: (input: ExtendInput) => Effect.Effect<boolean>
95100
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>
97102
readonly promote: (id: string) => Effect.Effect<Info | undefined>
98103
readonly cancel: (id: string) => Effect.Effect<Info | undefined>
99104
}
@@ -336,8 +341,11 @@ export const make = Effect.gen(function* () {
336341

337342
const waitForPromotion: Interface["waitForPromotion"] = Effect.fn("BackgroundJob.waitForPromotion")(function* (id) {
338343
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 })
340345
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
341349
return yield* Deferred.await(job.promoted)
342350
})
343351

‎packages/core/src/cross-spawn-spawner.ts‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import { filesystem, path } from "./effect/app-node-platform"
2929

3030
const toError = (err: unknown): Error => (err instanceof globalThis.Error ? err : new globalThis.Error(String(err)))
3131

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+
3235
const toTag = (err: NodeJS.ErrnoException): PlatformError.SystemErrorTag => {
3336
switch (err.code) {
3437
case "ENOENT":
@@ -284,8 +287,12 @@ export const make = Effect.gen(function* () {
284287
proc.on("spawn", () => {
285288
resume(Effect.succeed([proc, signal]))
286289
})
287-
return Effect.sync(() => {
290+
return Effect.suspend(() => {
288291
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)
289296
})
290297
})
291298

@@ -315,10 +322,15 @@ export const make = Effect.gen(function* () {
315322
command: ChildProcess.StandardCommand,
316323
proc: NodeChildProcess.ChildProcess,
317324
signal: NodeJS.Signals,
325+
exited: Effect.Effect<boolean>,
318326
) =>
319327
Effect.suspend(() => {
320328
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+
)
322334
})
323335

324336
const timeout =
@@ -335,9 +347,8 @@ export const make = Effect.gen(function* () {
335347
) => Effect.Effect<A, E, R>,
336348
) => {
337349
const signal = opts?.killSignal ?? "SIGTERM"
338-
if (Predicate.isUndefined(opts?.forceKillAfter)) return f(command, proc, signal)
339350
return Effect.timeoutOrElse(f(command, proc, signal), {
340-
duration: opts.forceKillAfter,
351+
duration: opts?.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER,
341352
orElse: () => f(command, proc, "SIGKILL"),
342353
})
343354
}
@@ -389,15 +400,13 @@ export const make = Effect.gen(function* () {
389400
return yield* Effect.void
390401
}
391402
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)))
393404
const sig = command.options.killSignal ?? "SIGTERM"
394405
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+
})
401410
return yield* Effect.ignore(escalated)
402411
}),
403412
)
@@ -427,11 +436,10 @@ export const make = Effect.gen(function* () {
427436
kill: (opts?: ChildProcess.KillOptions) => {
428437
const sig = opts?.killSignal ?? "SIGTERM"
429438
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)))
431440
const attempt = send(sig).pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid)
432-
if (!opts?.forceKillAfter) return attempt
433441
return Effect.timeoutOrElse(attempt, {
434-
duration: opts.forceKillAfter,
442+
duration: opts?.forceKillAfter ?? DEFAULT_FORCE_KILL_AFTER,
435443
orElse: () => send("SIGKILL").pipe(Effect.andThen(Deferred.await(signal)), Effect.asVoid),
436444
})
437445
},

‎packages/core/src/database/migration.gen.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

‎packages/core/src/database/schema.gen.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default {
8383
\`seq\` integer NOT NULL,
8484
\`type\` text NOT NULL,
8585
\`data\` text NOT NULL,
86+
\`tombstone_digest\` text,
8687
CONSTRAINT \`fk_event_aggregate_id_event_sequence_aggregate_id_fk\` FOREIGN KEY (\`aggregate_id\`) REFERENCES \`event_sequence\`(\`aggregate_id\`) ON DELETE CASCADE
8788
);
8889
`)
@@ -275,6 +276,9 @@ export default {
275276
yield* tx.run(
276277
`CREATE INDEX \`session_message_session_time_created_id_idx\` ON \`session_message\` (\`session_id\`,\`time_created\`,\`id\`);`,
277278
)
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+
)
278282
yield* tx.run(`CREATE INDEX \`session_project_idx\` ON \`session\` (\`project_id\`);`)
279283
yield* tx.run(`CREATE INDEX \`session_workspace_idx\` ON \`session\` (\`workspace_id\`);`)
280284
yield* tx.run(`CREATE INDEX \`session_parent_idx\` ON \`session\` (\`parent_id\`);`)

0 commit comments

Comments
 (0)