Skip to content

fix(cli): share session runtime with HTTP listeners - #11410

Merged
marius-kilocode merged 1 commit into
mainfrom
jungle-cobbler
Jun 18, 2026
Merged

fix(cli): share session runtime with HTTP listeners#11410
marius-kilocode merged 1 commit into
mainfrom
jungle-cobbler

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Remote session prompts enter the CLI through RemoteSender, which executes SessionPrompt on AppRuntime. HTTP abort and session-control requests enter through Server.listen(). Those two entry points currently build separate Effect service graphs, so they do not share the same SessionRunState, BackgroundJob, SessionStatus, Bus, or EventV2Bridge instances. An abort can therefore reach the correct directory and return success while looking in a listener-local runner map that does not contain the active AppRuntime session or its subagents.

This is complementary to #11404, not an alternative to it. #11404 fixes the directory dimension: Agent Manager can move a session mapping from directory A to directory B while the runner remains owned by A, so the extension must abort every possible owning directory. This change fixes the service-instance dimension: even when abort targets the correct directory, a runner created through AppRuntime is invisible to a listener built with a separate memo map. #11404 does not reconnect those service graphs, and this change does not discover moved directory owners. Both fixes are required for their respective paths.

The split was introduced in b7a7ecf449 (refactor: kilo compat for v1.14.34), when the native Effect HTTP listener began constructing the complete route graph with Layer.makeMemoMapUnsafe(). AppRuntime continued using the process-wide memo map, so stateful session services diverged between remote-session ingress and HTTP control routes. Later listener lifecycle refactors preserved that separation.

The listener now keeps transport, routing, authentication, CORS, and shutdown state fresh per listener while obtaining application services from the shared AppLayer through the process-wide memo map. V2 session handlers likewise consume the shared EventV2Bridge instead of creating another bridge. Kilo-specific composition lives under src/kilocode/, leaving only narrow hooks in shared upstream files.

@kilo-code-bot

kilo-code-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (8 files)
  • .changeset/share-server-session-runtime.md
  • packages/opencode/src/kilocode/server/httpapi/server.ts
  • packages/opencode/src/kilocode/server/listener.ts
  • packages/opencode/src/server/routes/instance/httpapi/handlers/v2.ts
  • packages/opencode/src/server/routes/instance/httpapi/server.ts
  • packages/opencode/src/server/server.ts
  • packages/opencode/test/kilocode/server/listener-runtime.test.ts
  • script/check-opencode-promise-facades.ts

Verified the key correctness points:

  • v2Handlers switching from SessionV2.defaultLayer to SessionV2.layer drops the local EventV2Bridge.defaultLayer; both call sites still satisfy EventV2Bridge.Service (createRoutes provides it at server.ts:238, createListenerRoutes gets it via AppLayer which includes EventV2Bridge.defaultLayer at app-runtime.ts:123).
  • createListenerRoutes intentionally omits the app-service layers (Account/Agent/Config/Session/SessionRunState/EventV2Bridge/InstanceLayer/Observability); those now come from AppLayer through the shared process-wide memoMap in KiloListener.build, which is exactly the fix.
  • Layer.fresh(listenerLayer).pipe(Layer.provide(AppLayer)) keeps listener transport (HttpServer/NodeHttpServer/WebSocketTracker/ConfigProvider) fresh per listener while reusing memoized app services; AppLayer stays owned by AppRuntime's scope so closing the listener scope does not double-close or leak it.
  • New integration test exercises the real listener→AppRuntime abort path rather than duplicating logic; the AppRuntime reference count (3 = import + 2 calls) matches the check-opencode-promise-facades allowlist entry.
  • Fork hygiene is clean: new code lives under src/kilocode/ and shared-file edits (v2.ts, httpapi/server.ts, server.ts) are minimal and marked with kilocode_change.

Fix these issues in Kilo Cloud


Reviewed by glm-5.2-20260616 · 762,286 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit bbd520d into main Jun 18, 2026
23 checks passed
@marius-kilocode
marius-kilocode deleted the jungle-cobbler branch June 18, 2026 10:41
NJ-2020 pushed a commit to NJ-2020/kilocode that referenced this pull request Jul 4, 2026
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
fix(cli): share session runtime with HTTP listeners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants