@@ -28,10 +28,12 @@ import {
2828 ProviderUploadFeedbackInput ,
2929 ThreadId ,
3030 TurnId ,
31+ type ProjectId ,
3132 type ProviderInstanceId ,
3233 type ProviderDriverKind ,
3334 type ProviderRuntimeEvent ,
3435 type ProviderSession ,
36+ type ServerSettings as ServerSettingsValue ,
3537} from "@t3tools/contracts" ;
3638import { expandAssistantCitationsForProvider } from "@t3tools/shared/assistantCitations" ;
3739import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
@@ -867,22 +869,26 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
867869 const agentAccessSettings = Effect . fn ( "ProviderService.agentAccessSettings" ) (
868870 function * ( threadId : ThreadId ) {
869871 const settings = yield * serverSettings . getSettings ;
870- const overridden = Object . values ( settings . projectSettingsOverrides ) . some (
871- ( entry ) =>
872- entry . enableAgentBrowserAccess !== undefined ||
873- entry . enableAgentDeviceAccess !== undefined ,
872+ const entries = Object . values ( settings . projectSettingsOverrides ) ;
873+ const browserOverridden = entries . some (
874+ ( entry ) => entry . enableAgentBrowserAccess !== undefined ,
874875 ) ;
875- if ( ! overridden ) {
876- return {
877- browser : settings . enableAgentBrowserAccess ,
878- device : settings . enableAgentDeviceAccess ,
879- } ;
880- }
876+ const deviceOverridden = entries . some ( ( entry ) => entry . enableAgentDeviceAccess !== undefined ) ;
877+ const environment = {
878+ browser : settings . enableAgentBrowserAccess ,
879+ device : settings . enableAgentDeviceAccess ,
880+ } ;
881+ if ( ! browserOverridden && ! deviceOverridden ) return environment ;
881882 // Provider-only runtimes may omit orchestration. An unresolved project
882- // must not bypass an explicit project override.
883- if ( Option . isNone ( projectionQuery ) ) return { browser : false , device : false } ;
883+ // must not bypass an explicit project override, but a capability no
884+ // project overrides keeps its environment value.
885+ const denied = {
886+ browser : browserOverridden ? false : environment . browser ,
887+ device : deviceOverridden ? false : environment . device ,
888+ } ;
889+ if ( Option . isNone ( projectionQuery ) ) return denied ;
884890 const thread = yield * projectionQuery . value . getThreadShellById ( threadId ) ;
885- if ( Option . isNone ( thread ) ) return { browser : false , device : false } ;
891+ if ( Option . isNone ( thread ) ) return denied ;
886892 const resolved = resolveProjectSettings ( settings , thread . value . projectId ) . settings ;
887893 return {
888894 browser : resolved . enableAgentBrowserAccess ,
@@ -2227,10 +2233,30 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
22272233 ) ;
22282234
22292235 const runStopAll = Effect . fn ( "runStopAll" ) ( function * ( ) {
2230- const continueAfterRestart = yield * serverSettings . getSettings . pipe (
2231- Effect . map ( ( settings ) => settings . continueThreadsAfterServerUpdate ) ,
2232- Effect . orElseSucceed ( ( ) => false ) ,
2236+ // Continuation is project-scopable, so decide it per session's project;
2237+ // without orchestration the environment value is all there is.
2238+ const stopSettings = yield * serverSettings . getSettings . pipe (
2239+ Effect . map ( Option . some ) ,
2240+ Effect . orElseSucceed ( ( ) => Option . none < ServerSettingsValue > ( ) ) ,
22332241 ) ;
2242+ const continueAfterRestartFor = Effect . fn ( "continueAfterRestartFor" ) ( function * (
2243+ threadId : ThreadId ,
2244+ ) {
2245+ if ( Option . isNone ( stopSettings ) ) return false ;
2246+ const settings = stopSettings . value ;
2247+ const overridden = Object . values ( settings . projectSettingsOverrides ) . some (
2248+ ( entry ) => entry . continueThreadsAfterServerUpdate !== undefined ,
2249+ ) ;
2250+ if ( ! overridden || Option . isNone ( projectionQuery ) ) {
2251+ return settings . continueThreadsAfterServerUpdate ;
2252+ }
2253+ const thread = yield * projectionQuery . value
2254+ . getThreadShellById ( threadId )
2255+ . pipe ( Effect . orElseSucceed ( ( ) => Option . none < { projectId : ProjectId } > ( ) ) ) ;
2256+ if ( Option . isNone ( thread ) ) return settings . continueThreadsAfterServerUpdate ;
2257+ return resolveProjectSettings ( settings , thread . value . projectId ) . settings
2258+ . continueThreadsAfterServerUpdate ;
2259+ } ) ;
22342260 const properties = yield * Ref . modify ( turnAnalytics , ( state ) => {
22352261 const completed : Array < Readonly < Record < string , unknown > > > = [ ] ;
22362262 for ( const [ sessionKey , session ] of state . sessions ) {
@@ -2256,15 +2282,20 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
22562282 ) ,
22572283 ) . pipe ( Effect . map ( ( sessionsByAdapter ) => sessionsByAdapter . flatMap ( ( sessions ) => sessions ) ) ) ;
22582284 yield * Effect . forEach ( activeSessions , ( session ) =>
2259- Effect . flatMap ( nowIso , ( lastRuntimeEventAt ) =>
2260- upsertSessionBinding ( session , session . threadId , {
2261- ...( continueAfterRestart && session . status === "running" && session . activeTurnId
2285+ Effect . gen ( function * ( ) {
2286+ const continueAfterRestart =
2287+ session . status === "running" && session . activeTurnId
2288+ ? yield * continueAfterRestartFor ( session . threadId )
2289+ : false ;
2290+ const lastRuntimeEventAt = yield * nowIso ;
2291+ yield * upsertSessionBinding ( session , session . threadId , {
2292+ ...( continueAfterRestart && session . activeTurnId
22622293 ? { continueAfterServerUpdate : session . activeTurnId }
22632294 : { } ) ,
22642295 lastRuntimeEvent : "provider.stopAll" ,
22652296 lastRuntimeEventAt,
2266- } ) ,
2267- ) ,
2297+ } ) ;
2298+ } ) ,
22682299 ) . pipe ( Effect . asVoid ) ;
22692300 yield * Effect . forEach ( currentAdapters , ( [ , adapter ] ) => adapter . stopAll ( ) ) . pipe ( Effect . asVoid ) ;
22702301 yield * McpSessionRegistry . revokeAllActiveMcpCredentials ( ) ;
0 commit comments