@@ -632,6 +632,8 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
632 | 632 | ProviderAdapter.ProviderAdapterV2Error | Cause.Done |
633 | 633 | >(); |
634 | 634 | const pendingPrompts = new Map<string, PendingPiPrompt>(); |
| 635 | + // Bumped when a dialog opens or settles; lifecycle deadlines restart from it. |
| 636 | + let promptActivity = 0; |
635 | 637 | // Custom answers waiting for their ask_user_question follow-up input, keyed by title prefix. |
636 | 638 | // FIFO per prefix: the extension asks each follow-up right after its own select is answered. |
637 | 639 | const customAnswerFollowUps = new Map<string, string[]>(); |
@@ -967,10 +969,14 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
967 | 969 | ) |
968 | 970 | return yield* protocolError("Pi transport closed during status reset"); |
969 | 971 | 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. |
971 | 974 | 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); |
974 | 980 | return yield* new PiRpcTimeoutError({ |
975 | 981 | operation: String(record["type"]), |
976 | 982 | timeoutMs: PI_SESSION_TIMEOUT_MS, |
@@ -1762,6 +1768,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
1762 | 1768 | ) { |
1763 | 1769 | const pending = Array.from(pendingPrompts.values()); |
1764 | 1770 | pendingPrompts.clear(); |
| 1771 | + promptActivity++; |
1765 | 1772 | customAnswerFollowUps.clear(); |
1766 | 1773 | yield* Effect.forEach(pending, (prompt) => cancelPrompt(prompt, resolvedAt), { |
1767 | 1774 | discard: true, |
@@ -1979,6 +1986,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
1979 | 1986 | customAnswerRoute: askUser?.customAnswerRoute, |
1980 | 1987 | }; |
1981 | 1988 | pendingPrompts.set(String(requestId), pending); |
| 1989 | + promptActivity++; |
1982 | 1990 | yield* emit({ |
1983 | 1991 | type: "runtime_request.updated", |
1984 | 1992 | driver: PI_PROVIDER, |
@@ -2761,6 +2769,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
2761 | 2769 | const pending = pendingPrompts.get(requestId); |
2762 | 2770 | if (pending === undefined || pending !== event["pending"]) return; |
2763 | 2771 | pendingPrompts.delete(requestId); |
| 2772 | + promptActivity++; |
2764 | 2773 | yield* cancelPrompt(pending, yield* DateTime.now); |
2765 | 2774 | return; |
2766 | 2775 | } |
@@ -3776,6 +3785,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
3776 | 3785 | DateTime.toEpochMillis(answeredAt) >= pending.expiresAt |
3777 | 3786 | ) { |
3778 | 3787 | pendingPrompts.delete(String(requestInput.requestId)); |
| 3788 | + promptActivity++; |
3779 | 3789 | yield* cancelPrompt(pending, answeredAt); |
3780 | 3790 | return yield* protocolError( |
3781 | 3791 | `Pi extension request ${requestInput.requestId} has expired`, |
@@ -3801,6 +3811,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( |
3801 | 3811 | ...response, |
3802 | 3812 | }); |
3803 | 3813 | pendingPrompts.delete(String(requestInput.requestId)); |
| 3814 | + promptActivity++; |
3804 | 3815 | if (pending.expirationFiber !== null) yield* Fiber.interrupt(pending.expirationFiber); |
3805 | 3816 | if (pending.method === "confirm" && requestInput.decision === "acceptForSession") { |
3806 | 3817 | sessionApprovals.add(pending.approvalKey); |
|