GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(pi): restoring a Pi session no longer deadlocks on an extension's startup confirm by juliusmarminge · Pull Request #30996 · pingdotgg/t3code

fix(pi): restoring a Pi session no longer deadlocks on an extension's startup confirm #30996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
juliusmarminge wants to merge 16 commits into main
base: main
Loading
Loading
from fix/issue-30926
+547 −45
Open

fix(pi): restoring a Pi session no longer deadlocks on an extension's startup confirm #30996

Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7e7f8cc
test: reproduce Pi resume confirm deadlock and unsolicited wake (#30926)
juliusmarminge Nov 4, 2026
8e3c999
fix: deliver Pi resume confirms and hold the work they start (#30926)
juliusmarminge Nov 4, 2026
ef83567
fix: narrow Pi resume answer and wake handling to the resume path (#3…
juliusmarminge Nov 4, 2026
a4a6412
test: assert resumed Pi work is offered exactly once (#30926)
juliusmarminge Nov 4, 2026
eff4e0c
Merge remote-tracking branch 'origin/main' into fix/issue-30926
juliusmarminge Nov 10, 2026
44083b6
test: stub the runtime request lane in the outbox notification test
juliusmarminge Nov 10, 2026
2146c6f
Merge remote-tracking branch 'github/main' into fix/issue-30926
juliusmarminge Nov 11, 2026
4eb2955
fix(pi): drop buffering of native work started during a resume switch
juliusmarminge Nov 11, 2026
bee5e83
Merge remote-tracking branch 'origin/main' into fix/issue-30926
juliusmarminge Nov 11, 2026
4d7542d
fix(pi): abort work a session switch hook starts before T3 owns the t…
juliusmarminge Nov 11, 2026
5d3e88c
fix(pi): hold work a resumed session starts until a T3 turn admits it
juliusmarminge Nov 11, 2026
5fc7286
test(pi): replay fixtures expect the resume admission command
juliusmarminge Nov 11, 2026
6718a37
fix(pi): a restore waiting on a startup dialog no longer times out
juliusmarminge Nov 11, 2026
c9293c1
Merge remote-tracking branch 'origin/main' into fix/issue-30926
juliusmarminge Nov 22, 2026
62f0a8c
fix(pi): hold startup work of a session resumed at spawn until a turn…
juliusmarminge Nov 22, 2026
2a0af3e
fix(pi): a session switch answered near its deadline keeps a full window
juliusmarminge Nov 22, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

87 changes: 56 additions & 31 deletions 87 apps/server/src/orchestration-v2/EffectOutbox.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,15 @@ export class EffectOutboxError extends Schema.TaggedError<EffectOutboxError>()(

const isEffectOutboxError = Schema.is(EffectOutboxError);

export interface EffectClaimFilter {
readonly excludeRestartContinuations?: boolean;
readonly effectType?: OrchestrationEffectRequestV2["type"];
}

export interface EffectOutboxV2Shape {
readonly awaitAvailable: Effect.Effect<void>;
/** Wakes on any notification without taking one from the shared workers. */
readonly awaitAnyAvailable: Effect.Effect<void>;
readonly notifyAvailable: (count?: number) => Effect.Effect<void>;
/** Persist rows only. Notify workers after the surrounding transaction commits. */
readonly enqueue: (
Expand All @@ -221,11 +228,12 @@ export interface EffectOutboxV2Shape {
{ readonly requeued: number; readonly cancelled: number },
EffectOutboxError
>;
readonly claimNext: (input: {
readonly workerId: string;
readonly excludeRestartContinuations?: boolean;
}) => Effect.Effect<Option.Option<OrchestrationEffectV2>, EffectOutboxError>;
readonly nextClaimableAt: Effect.Effect<Option.Option<DateTime.Utc>, EffectOutboxError>;
readonly claimNext: (
input: EffectClaimFilter & { readonly workerId: string },
) => Effect.Effect<Option.Option<OrchestrationEffectV2>, EffectOutboxError>;
readonly nextClaimableAt: (
filter?: EffectClaimFilter,
) => Effect.Effect<Option.Option<DateTime.Utc>, EffectOutboxError>;
readonly succeed: (input: {
readonly effectId: string;
readonly workerId: string;
Expand Down Expand Up @@ -292,6 +300,7 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
const available = yield* Queue.dropping<void>(64);
const anyAvailable = yield* Queue.sliding<void>(1);
const cancellationSignals = new Map<string, Deferred.Deferred<void>>();
const settledSignals = new Map<string, Deferred.Deferred<void>>();
const signalSettled = (effectIds: ReadonlyArray<string>) =>
Expand All @@ -306,14 +315,17 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
{ discard: true },
);
const notifyAvailable = (count = 1) =>
Queue.offerAll(
available,
Array.from({ length: Math.min(64, Math.max(0, Math.floor(count))) }, () => undefined),
).pipe(Effect.asVoid);
count < 1
? Effect.void
: Queue.offerAll(
available,
Array.from({ length: Math.min(64, Math.floor(count)) }, () => undefined),
).pipe(Effect.andThen(Queue.offer(anyAvailable, undefined)), Effect.asVoid);
// Retry backoff must block later effects so turns cannot race a pending rollback.
// A runtime request answer may pass a running turn start, which can be blocked on that answer.
const claimableCandidatePredicate = (
availableBefore?: string,
excludeRestartContinuations = false,
availableBefore: string | undefined,
{ excludeRestartContinuations = false, effectType }: EffectClaimFilter = {},
) =>
sql`
${
Expand All @@ -322,6 +334,12 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
: sql`candidate.available_at <= ${availableBefore}`
}
AND candidate.status = 'pending'
AND ${
excludeRestartContinuations
? sql`candidate.effect_type != 'provider-runtime.continue'`
: sql`1 = 1`
}
AND ${effectType === undefined ? sql`1 = 1` : sql`candidate.effect_type = ${effectType}`}
AND NOT EXISTS (
SELECT 1
FROM orchestration_v2_effect_outbox AS active
Expand All @@ -347,6 +365,11 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
(
candidate.effect_type != 'thread-title.generate'
AND active.effect_type != 'thread-title.generate'
AND NOT (
active.status = 'running'
AND candidate.effect_type = 'runtime-request.respond'
AND active.effect_type = 'provider-turn.start'
)
)
)
)
Expand Down Expand Up @@ -420,6 +443,7 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
Effect.mapError((cause) => new EffectOutboxError({ operation: "get", effectId, cause })),
),
awaitAvailable: Queue.take(available),
awaitAnyAvailable: Queue.take(anyAvailable),
notifyAvailable,
listByCommandId: (commandId) =>
sql<EffectRow>`
Expand Down Expand Up @@ -519,7 +543,7 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
),
// The worker polls for the next effect even when there is no work to claim.
claimNext: Effect.fnUntraced(
function* ({ workerId, excludeRestartContinuations = false }) {
function* ({ workerId, ...filter }) {
const now = yield* DateTime.now;
const nowIso = DateTime.formatIso(now);
// Idle claims return empty; tracing their full SQL on every poll overwhelms useful traces.
Expand All @@ -534,8 +558,7 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
WHERE effect_id = (
SELECT candidate.effect_id
FROM orchestration_v2_effect_outbox AS candidate
WHERE ${claimableCandidatePredicate(nowIso, excludeRestartContinuations)}
AND ${excludeRestartContinuations ? sql`candidate.effect_type != 'provider-runtime.continue'` : sql`1 = 1`}
WHERE ${claimableCandidatePredicate(nowIso, filter)}
ORDER BY candidate.available_at ASC, candidate.created_at ASC, candidate.effect_id ASC
LIMIT 1
)
Expand All @@ -549,23 +572,25 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
},
Effect.mapError((cause) => new EffectOutboxError({ operation: "claim", cause })),
),
nextClaimableAt: Effect.gen(function* () {
const rows = yield* sql<{ readonly available_at: string | null }>`
SELECT MIN(candidate.available_at) AS available_at
FROM orchestration_v2_effect_outbox AS candidate
WHERE ${claimableCandidatePredicate()}
`.pipe(NodeSqliteClient.readOnly, Effect.withTracerEnabled(false));
const availableAt = rows[0]?.available_at;
if (availableAt === undefined || availableAt === null) return Option.none();
const parsed = DateTime.make(availableAt);
if (Option.isNone(parsed)) {
return yield* new EffectOutboxError({
operation: "next-claimable",
cause: `Invalid available_at timestamp: ${availableAt}`,
});
}
return parsed;
}).pipe(
// Idle workers read this deadline after every empty claim, like claimNext.
nextClaimableAt: Effect.fnUntraced(
function* (filter) {
const rows = yield* sql<{ readonly available_at: string | null }>`
SELECT MIN(candidate.available_at) AS available_at
FROM orchestration_v2_effect_outbox AS candidate
WHERE ${claimableCandidatePredicate(undefined, filter)}
`.pipe(NodeSqliteClient.readOnly, Effect.withTracerEnabled(false));
const availableAt = rows[0]?.available_at;
if (availableAt === undefined || availableAt === null) return Option.none();
const parsed = DateTime.make(availableAt);
if (Option.isNone(parsed)) {
return yield* new EffectOutboxError({
operation: "next-claimable",
cause: `Invalid available_at timestamp: ${availableAt}`,
});
}
return parsed;
},
Effect.mapError((cause) =>
isEffectOutboxError(cause)
? cause
Expand Down
54 changes: 38 additions & 16 deletions 54 apps/server/src/orchestration-v2/EffectWorker.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ export interface OrchestrationEffectWorkerV2Shape {
Option.Option<DateTime.Utc>,
OrchestrationEffectWorkerError
>;
/** The runtime request lane claims only answers, which running turn starts can block on. */
readonly awaitRuntimeRequestWork: Effect.Effect<void>;
readonly runRuntimeRequestOnce: Effect.Effect<boolean, OrchestrationEffectWorkerError>;
readonly nextRuntimeRequestClaimableAt: Effect.Effect<
Option.Option<DateTime.Utc>,
OrchestrationEffectWorkerError
>;
readonly drain: (maxEffects?: number) => Effect.Effect<number, OrchestrationEffectWorkerError>;
}

Expand Down Expand Up @@ -739,10 +746,8 @@ export const layerWithOptions = (

// The worker probes for work repeatedly, including when the outbox is empty.
const runOnce = Effect.fnUntraced(
function* (excludeRestartContinuations = false) {
const claimExit = yield* Effect.exit(
outbox.claimNext({ workerId, excludeRestartContinuations }),
);
function* (filter: EffectOutbox.EffectClaimFilter = {}) {
const claimExit = yield* Effect.exit(outbox.claimNext({ workerId, ...filter }));
yield* increment(orchestrationEffectClaimsTotal, {
result: Exit.isFailure(claimExit)
? "error"
Expand Down Expand Up @@ -841,7 +846,7 @@ export const layerWithOptions = (
}
return true;
},
(effect, _excludeRestartContinuations?: boolean) =>
(effect, _filter?: EffectOutbox.EffectClaimFilter) =>
effect.pipe(
Effect.mapError((cause) =>
isOrchestrationEffectWorkerError(cause)
Expand All @@ -851,19 +856,26 @@ export const layerWithOptions = (
),
);

return OrchestrationEffectWorkerV2.of({
awaitWork: outbox.awaitAvailable,
runOnce: runOnce(),
runRecoveryOnce: runOnce(true),
nextClaimableAt: outbox.nextClaimableAt.pipe(
const nextClaimableAt = (filter?: EffectOutbox.EffectClaimFilter) =>
outbox.nextClaimableAt(filter).pipe(
Effect.mapError(
(cause) =>
new OrchestrationEffectWorkerError({
operation: "next-claimable",
cause,
}),
),
),
);
const runtimeRequestFilter = { effectType: "runtime-request.respond" } as const;

return OrchestrationEffectWorkerV2.of({
awaitWork: outbox.awaitAvailable,
runOnce: runOnce(),
runRecoveryOnce: runOnce({ excludeRestartContinuations: true }),
nextClaimableAt: nextClaimableAt(),
awaitRuntimeRequestWork: outbox.awaitAnyAvailable,
runRuntimeRequestOnce: runOnce(runtimeRequestFilter),
nextRuntimeRequestClaimableAt: nextClaimableAt(runtimeRequestFilter),
drain: Effect.fn("EffectWorker.drain")(function* (maxEffects = Number.MAX_SAFE_INTEGER) {
let completed = 0;
while (completed < maxEffects && (yield* runOnce())) {
Expand Down Expand Up @@ -899,9 +911,11 @@ export const runDaemonWithOptions = (options: OrchestrationEffectDaemonOptions =
? Math.max(1, Math.floor(requestedLivenessPollIntervalMs))
: DEFAULT_EFFECT_WORKER_LIVENESS_POLL_INTERVAL_MS;
// Notifications wake promptly; availableAt persists retry timing, and liveness polling recovers missed wakeups.
const runWorker = Effect.gen(function* () {
const runWorker = Effect.fnUntraced(function* (
lane: Pick<OrchestrationEffectWorkerV2Shape, "awaitWork" | "runOnce" | "nextClaimableAt">,
) {
while (true) {
const outcome = yield* worker.runOnce.pipe(
const outcome = yield* lane.runOnce.pipe(
Effect.map((worked) => (worked ? ("worked" as const) : ("idle" as const))),
Effect.catchCause((cause) =>
Effect.logWarning("Orchestration effect worker failed", cause).pipe(
Expand All @@ -919,7 +933,7 @@ export const runDaemonWithOptions = (options: OrchestrationEffectDaemonOptions =
continue;
}

const nextClaimableAt = yield* worker.nextClaimableAt.pipe(
const nextClaimableAt = yield* lane.nextClaimableAt.pipe(
Effect.catchCause((cause) =>
Effect.logWarning(
"Failed to read the next orchestration effect deadline",
Expand All @@ -936,14 +950,22 @@ export const runDaemonWithOptions = (options: OrchestrationEffectDaemonOptions =
},
});
yield* Effect.raceFirst(
worker.awaitWork.pipe(Effect.as("notified" as const)),
lane.awaitWork.pipe(Effect.as("notified" as const)),
Effect.sleep(Duration.millis(sleepMs)).pipe(Effect.as("scheduled" as const)),
);
}
});

// Turn starts can occupy every ordinary worker while they wait on the answers this lane delivers.
return yield* Effect.all(
Array.from({ length: concurrency }, () => runWorker),
[
...Array.from({ length: concurrency }, () => runWorker(worker)),
runWorker({
awaitWork: worker.awaitRuntimeRequestWork,
runOnce: worker.runRuntimeRequestOnce,
nextClaimableAt: worker.nextRuntimeRequestClaimableAt,
}),
],
{
concurrency: "unbounded",
discard: true,
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.