@@ -21,6 +21,10 @@ import {
2121
2222const encode = ( value : boolean ) => new TextEncoder ( ) . encode ( String ( value ) ) ;
2323
24+ /** A failed rollback leaves a setting changed; it is logged, not hidden. */
25+ const rollbackFailed = ( cause : unknown ) =>
26+ Effect . logWarning ( "Could not roll back a T3 Connect preference" , { cause } ) ;
27+
2428const internalError = ( message : string ) => ( cause : unknown ) =>
2529 Effect . logError ( message , { cause } ) . pipe (
2630 Effect . andThen ( Effect . fail ( new EnvironmentHttpInternalServerError ( { message } ) ) ) ,
@@ -30,9 +34,11 @@ export class CloudPreferences extends Context.Service<
3034 CloudPreferences ,
3135 {
3236 /**
33- * Saves this environment's T3 Connect preferences. Holding webhooks while
34- * offline is decided by the relay, so it is told first and put back if the
35- * local save fails.
37+ * Saves this environment's T3 Connect preferences, all or nothing. The
38+ * activity setting is saved first. Holding webhooks while offline is decided
39+ * by the relay, so the relay is told before the local copy is saved. If
40+ * either step fails, the activity setting is put back, and so is the relay
41+ * when only the local save failed.
3642 */
3743 readonly update : (
3844 input : EnvironmentCloudPreferencesRequest ,
@@ -92,15 +98,15 @@ const make = Effect.gen(function* () {
9298 Effect . tapError ( ( ) =>
9399 previous === next
94100 ? Effect . void
95- : pushHoldWebhooksWhileOffline ( previous ) . pipe ( Effect . ignore ) ,
101+ : pushHoldWebhooksWhileOffline ( previous ) . pipe ( Effect . catch ( rollbackFailed ) ) ,
96102 ) ,
97103 ) ,
98104 ) ,
99105 Effect . tapError ( ( ) =>
100106 Option . match ( previousActivity , {
101107 onNone : ( ) => secrets . remove ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
102108 onSome : ( bytes ) => secrets . set ( PUBLISH_AGENT_ACTIVITY_SECRET , bytes ) ,
103- } ) . pipe ( Effect . ignore ) ,
109+ } ) . pipe ( Effect . catch ( rollbackFailed ) ) ,
104110 ) ,
105111 ) ;
106112 }
0 commit comments