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): a session switch answered near its deadline keeps a full window · pingdotgg/t3code@2a0af3e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/provider-pi/src/server
    • adapter.test.ts
    • adapter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/provider-pi/src/server/adapter.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/adapter.test.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,12 +2096,15 @@ describe("PiAdapterV2", () => {
20962096
const dialog = yield* takeEvent((event) => event.type === "runtime_request.updated");
20972097
assert.isTrue(dialog.type === "runtime_request.updated");
20982098
if (dialog.type !== "runtime_request.updated") return;
2099-
yield* TestClock.adjust("2 minutes");
2099+
yield* TestClock.adjust("119 seconds");
21002100
yield* runtime.respondToRuntimeRequest({
21012101
requestId: dialog.runtimeRequest.id,
21022102
decision: "accept",
21032103
});
21042104
yield* fake.takeRequest("extension_ui_response");
2105+
// An answer just before a deadline still leaves Pi a whole window to finish the switch.
2106+
yield* TestClock.adjust("59 seconds");
2107+
assert.isUndefined(resumed.pollUnsafe());
21052108
yield* TestClock.adjust("1 minute");
21062109
const failure = yield* Fiber.join(resumed).pipe(Effect.flip);
21072110
assert.include(String(failure.cause), "switch_session failed: timed out");
Collapse file

‎packages/provider-pi/src/server/adapter.ts‎

Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/adapter.ts
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
632632
ProviderAdapter.ProviderAdapterV2Error | Cause.Done
633633
>();
634634
const pendingPrompts = new Map<string, PendingPiPrompt>();
635+
// Bumped when a dialog opens or settles; lifecycle deadlines restart from it.
636+
let promptActivity = 0;
635637
// Custom answers waiting for their ask_user_question follow-up input, keyed by title prefix.
636638
// FIFO per prefix: the extension asks each follow-up right after its own select is answered.
637639
const customAnswerFollowUps = new Map<string, string[]>();
@@ -967,10 +969,14 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
967969
)
968970
return yield* protocolError("Pi transport closed during status reset");
969971
yield* Deferred.await(reset.ready);
970-
// Session hooks can wait on the user, so only time without an open dialog counts.
972+
// Session hooks can wait on the user: time out only after a full window with no dialog
973+
// open and none opened or answered, so Pi keeps a whole window after the last answer.
971974
const deadline = Effect.gen(function* () {
972-
do yield* Effect.sleep(Duration.millis(PI_SESSION_TIMEOUT_MS));
973-
while (pendingPrompts.size > 0);
975+
let activity: number;
976+
do {
977+
activity = promptActivity;
978+
yield* Effect.sleep(Duration.millis(PI_SESSION_TIMEOUT_MS));
979+
} while (pendingPrompts.size > 0 || promptActivity !== activity);
974980
return yield* new PiRpcTimeoutError({
975981
operation: String(record["type"]),
976982
timeoutMs: PI_SESSION_TIMEOUT_MS,
@@ -1762,6 +1768,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
17621768
) {
17631769
const pending = Array.from(pendingPrompts.values());
17641770
pendingPrompts.clear();
1771+
promptActivity++;
17651772
customAnswerFollowUps.clear();
17661773
yield* Effect.forEach(pending, (prompt) => cancelPrompt(prompt, resolvedAt), {
17671774
discard: true,
@@ -1979,6 +1986,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
19791986
customAnswerRoute: askUser?.customAnswerRoute,
19801987
};
19811988
pendingPrompts.set(String(requestId), pending);
1989+
promptActivity++;
19821990
yield* emit({
19831991
type: "runtime_request.updated",
19841992
driver: PI_PROVIDER,
@@ -2761,6 +2769,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
27612769
const pending = pendingPrompts.get(requestId);
27622770
if (pending === undefined || pending !== event["pending"]) return;
27632771
pendingPrompts.delete(requestId);
2772+
promptActivity++;
27642773
yield* cancelPrompt(pending, yield* DateTime.now);
27652774
return;
27662775
}
@@ -3776,6 +3785,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
37763785
DateTime.toEpochMillis(answeredAt) >= pending.expiresAt
37773786
) {
37783787
pendingPrompts.delete(String(requestInput.requestId));
3788+
promptActivity++;
37793789
yield* cancelPrompt(pending, answeredAt);
37803790
return yield* protocolError(
37813791
`Pi extension request ${requestInput.requestId} has expired`,
@@ -3801,6 +3811,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
38013811
...response,
38023812
});
38033813
pendingPrompts.delete(String(requestInput.requestId));
3814+
promptActivity++;
38043815
if (pending.expirationFiber !== null) yield* Fiber.interrupt(pending.expirationFiber);
38053816
if (pending.method === "confirm" && requestInput.decision === "acceptForSession") {
38063817
sessionApprovals.add(pending.approvalKey);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — 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.