fix(opencode): settle pending approvals on session teardown #7173
Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/7173/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/OpenCodeAdapter.ts lines 676 to 692OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -670,0 +672,21 @@672+ const settleOpenCodePendingAsCancelled = (context: OpenCodeSessionContext) =>673+ Effect.gen(function* () {674+ const permissions = [...context.pendingPermissions.entries()];675+ context.pendingPermissions.clear();676+ yield* Effect.forEach(677+ permissions,678+ ([requestId, request]) =>679+ emit({680+ ...(yield *681+ buildEventBase({682+ threadId: context.session.threadId,683+ requestId,684+ })),685+ type: "request.resolved",686+ payload: {687+ requestType: mapPermissionToRequestType(request.permission),688+ decision: "cancel",689+ },690+ }),691+ { discard: true },692+ );apps/server/src/provider/Layers/OpenCodeAdapter.ts lines 695 to 708OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -670,0 +688,21 @@688+ decision: "cancel",689+ },690+ }),691+ { discard: true },692+ );693+ const questions = [...context.pendingQuestions.keys()];694+ context.pendingQuestions.clear();695+ yield* Effect.forEach(696+ questions,697+ (requestId) =>698+ emit({699+ ...(yield *700+ buildEventBase({701+ threadId: context.session.threadId,702+ requestId,703+ })),704+ type: "user-input.resolved",705+ payload: { answers: {} },706+ }),707+ { discard: true },708+ );
- apps/server/src/provider/Layers/OpenCodeAdapter.ts lines 675 to 708OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -670,0 +688,21 @@688+ decision: "cancel",689+ },690+ }),691+ { discard: true },692+ );693+ const questions = [...context.pendingQuestions.keys()];694+ context.pendingQuestions.clear();695+ yield* Effect.forEach(696+ questions,697+ (requestId) =>698+ emit({699+ ...(yield *700+ buildEventBase({701+ threadId: context.session.threadId,702+ requestId,703+ })),704+ type: "user-input.resolved",705+ payload: { answers: {} },706+ }),707+ { discard: true },708+ );apps/server/src/provider/Layers/OpenCodeAdapter.ts line 674OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -668,3 +668,7 @@668668669669 const emit = (event: ProviderRuntimeEvent) =>670670 Queue.offer(runtimeEvents, event).pipe(Effect.asVoid);671+672+ const settleOpenCodePendingAsCancelled = (context: OpenCodeSessionContext) =>673+ Effect.gen(function* () {674+ const permissions = [...context.pendingPermissions.entries()];
- apps/server/src/provider/Layers/OpenCodeAdapter.ts line 652Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -668,3 +668,4 @@668668669669 const emit = (event: ProviderRuntimeEvent) =>670670 Queue.offer(runtimeEvents, event).pipe(Effect.asVoid);671+apps/server/src/provider/Layers/OpenCodeAdapter.ts line 1728Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1626,3 +1667,4 @@16261667 threadId,16271668 });16281669 }1670+ yield* settleOpenCodePendingAsCancelled(context);
- @@ -670,0 +694,21 @@694+ }),695+ { discard: true },696+ );697+ const questions = [...context.pendingQuestions.keys()];698+ yield* Effect.forEach(699+ questions,700+ (requestId) =>701+ Effect.gen(function* () {702+ yield* emit({703+ ...(yield* buildEventBase({704+ threadId: context.session.threadId,705+ requestId,706+ })),707+ type: "user-input.resolved",708+ payload: { answers: {} },709+ });710+ context.pendingQuestions.delete(requestId);711+ }),712+ { discard: true },713+ );714+ });
- apps/server/src/provider/Layers/OpenCodeAdapter.ts line 1019OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -956,3 +1001,19 @@9561001 }95710029581003 case "permission.asked": {1004+ if (!(yield* Ref.get(context.acceptingRequests))) {1005+ yield* emit({1006+ ...(yield* buildEventBase({1007+ threadId: context.session.threadId,1008+ turnId,1009+ requestId: event.properties.id,1010+ raw: event,1011+ })),1012+ type: "request.resolved",1013+ payload: {1014+ requestType: mapPermissionToRequestType(event.properties.permission),1015+ decision: "cancel",1016+ },1017+ });1018+ break;1019+ }
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -653,4 +709,8 @@653709 // the remaining cleanups.654710 yield* Effect.forEach(655711 contexts,656- (context) => Effect.ignoreCause(stopOpenCodeContext(context)),712+ (context) =>713+ Effect.ignoreCause(714+ settleOpenCodePendingAsCancelled(context).pipe(715+ Effect.andThen(stopOpenCodeContext(context)),716+ ),@@ -976,0 +1035,21 @@1035+ }1036+ context.pendingPermissions.set(event.properties.id, event.properties);1037+ yield* emit({1038+ ...(yield* buildEventBase({1039+ threadId: context.session.threadId,1040+ turnId,1041+ requestId: event.properties.id,1042+ raw: event,1043+ })),1044+ type: "request.opened",1045+ payload: {1046+ requestType: mapPermissionToRequestType(event.properties.permission),1047+ detail:1048+ event.properties.patterns.length > 01049+ ? event.properties.patterns.join("\n")1050+ : event.properties.permission,1051+ args: event.properties.metadata,1052+ },1053+ });1054+ }),1055+ );
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
175e3795-ade8-4e05-89ee-bb0847290918You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share