• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacklok / toolhive-studio / 29571051485

17 Jul 2026 09:44AM UTC coverage: 71.713% (+0.5%) from 71.204%
29571051485

Pull #2475

github

samuv
fix(chat): harden Effect runtime adapters after external review

Make readiness and runtime retrieval atomic, type adapter programs against
ChatServices, and tighten domain-error narrowing plus agent/settings edge cases.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pull Request #2475: refactor(chat): migrate main-process chat to Effect domain services

5476 of 8187 branches covered (66.89%)

871 of 1363 new or added lines in 42 files covered. (63.9%)

1 existing line in 1 file now uncovered.

8153 of 11369 relevant lines covered (71.71%)

137.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/main/src/chat/runtime/managed-runtime.ts
1
import { Effect, Layer, ManagedRuntime } from 'effect'
2
import { ChatLoggerLayer, ChatLogLevelLayer } from './logging'
3
import { ThreadsRepository } from '../threads/threads-repository'
4
import { ThreadsService } from '../threads/threads-service'
5
import { LegacyStoreService } from '../settings/legacy-store-service'
6
import {
7
  SettingsRepository,
8
  SettingsService,
9
} from '../settings/settings-service'
10
import { ThreadSettingsService } from '../settings/thread-settings-service'
11
import { AgentsService } from '../agents/agents-service'
12
import { PricingService } from '../pricing/pricing-service'
13
import { StreamRegistryService } from '../streaming/stream-registry-service'
14
import { ChatStreamService } from '../streaming/chat-stream-service'
15
import { McpService } from '../mcp/mcp-service'
16
import { ProvidersService } from '../providers/providers-service'
17
import { TitleService } from '../streaming/title-service'
18
import {
19
  getManagedRuntimeInstance,
20
  setManagedRuntime,
21
  type AnyChatRuntime,
22
} from './runtime-ref'
23

24
const ChatLiveLayer = Layer.mergeAll(
12✔
25
  ChatLoggerLayer,
26
  ChatLogLevelLayer,
27
  ThreadsRepository.Default,
28
  ThreadsService.Default,
29
  LegacyStoreService.Default,
30
  SettingsRepository.Default,
31
  SettingsService.Default,
32
  ThreadSettingsService.Default,
33
  AgentsService.Default,
34
  PricingService.Default,
35
  McpService.Default,
36
  ProvidersService.Default,
37
  TitleService.Default,
38
  StreamRegistryService.Default,
39
  ChatStreamService.Default
40
)
41

42
export type ChatServices = Layer.Layer.Success<typeof ChatLiveLayer>
43

44
export type ChatRuntime = ManagedRuntime.ManagedRuntime<ChatServices, never>
45

46
export { getManagedRuntime, getManagedRuntimeInstance } from './runtime-ref'
47

48
export function getManagedRuntimeOrThrow(): ChatRuntime {
NEW
49
  const runtime = getManagedRuntimeInstance()
×
NEW
50
  if (!runtime) {
×
NEW
51
    throw new Error('Chat runtime has not been initialized')
×
52
  }
NEW
53
  return runtime as ChatRuntime
×
54
}
55

56
export async function initializeChatRuntime(): Promise<void> {
57
  if (getManagedRuntimeInstance()) return
121!
58
  const runtime = ManagedRuntime.make(ChatLiveLayer) as AnyChatRuntime
121✔
59
  setManagedRuntime(runtime)
121✔
60
  await runtime.runPromise(Effect.void)
121✔
61
}
62

63
export async function disposeChatRuntime(): Promise<void> {
64
  const runtime = getManagedRuntimeInstance()
241✔
65
  if (!runtime) return
241✔
66
  setManagedRuntime(null)
121✔
67
  await runtime.dispose()
121✔
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc