Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c540421
wiki: log merges of #115 #127 #137 #139 #141 #142 #143
claude Oct 2, 2026
5a6efcd
wiki: decision models and Ollama model research (#148)
claude Oct 2, 2026
aaa033c
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 2, 2026
97992d7
wiki: Hermes model roles, memory embedders and Jev plugins (#148, #149)
claude Oct 2, 2026
f1a3427
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 2, 2026
af2d08f
docs: default local Ollama to qwen3:8b and document Ollama cloud (#148)
claude Oct 2, 2026
9c6f11b
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 2, 2026
45f9ef1
wiki: fix Hermes Jev plugin count and update providers after #152
claude Oct 2, 2026
84e91ab
feat(config): per-role provider chains via models.chat and models.com…
claude Oct 2, 2026
9fd71b7
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 2, 2026
c00a4c7
test, docs: cover models.compress through Agent; clarify omitted-role…
claude Oct 2, 2026
b5a20f1
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 3, 2026
b054cc7
feat(plugins): entry settings, host model access and before_llm_call …
claude Oct 3, 2026
d6b712a
fix(plugins): deep-copy hook messages, honor run abort in models.chat…
claude Oct 3, 2026
ab5df46
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 3, 2026
2b01b6d
wiki: ingest Ollama System One/Clef check; record model roles and plu…
claude Oct 3, 2026
e010ef8
wiki: index one-liners match model roles and plugin host features
claude Oct 3, 2026
4640db2
wiki: bump index updated date
claude Oct 3, 2026
98a2c2b
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 3, 2026
b8266bc
feat(examples): decision_lane plugin for game_bridge action selection
claude Oct 3, 2026
bab4850
fix(decision_lane): zero off-criteria answers, require numeric thresh…
claude Oct 3, 2026
e0237cc
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
c59f5d1
wiki: record the decision_lane prototype (#159)
claude Oct 4, 2026
ca1c05f
wiki: decision_lane egress mentions the Bearer key
claude Oct 4, 2026
dcbb9e6
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
2074964
fix(agent): tools_enabled filters plugin tools; guard hooks fail clos…
claude Oct 4, 2026
4f97ea2
fix(loop): emit tool_call_end for last-turn skipped calls so transcri…
claude Oct 4, 2026
1b2d4d9
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
4840336
wiki: record #161 (plugin-tool allowlist, fail-closed guard hooks, la…
claude Oct 4, 2026
0b3d485
wiki: move the #161 fixed note out of the open-holes list
claude Oct 4, 2026
d7e1e95
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
0930c7d
fix: http_request status, terminal_timeout_ms, .. path guard, OpenAI …
claude Oct 4, 2026
09fc444
fix(openai): treat a null tool-call id as missing; correct http_reque…
claude Oct 4, 2026
1294e6a
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
07d0d3b
docs: webhook binds loopback by default; drop stale version from over…
claude Oct 4, 2026
0608068
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
16c4bdb
refactor(providers): share HTTP/error helpers in providers/http.ts (#…
claude Oct 4, 2026
53962b9
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
fe394bd
fix: Ctrl+C/Esc cancel, atomic config update, test tmp cleanup (#133)
claude Oct 4, 2026
84f62a4
fix: on cancel, drop the unanswered user line and do not reprint the …
claude Oct 4, 2026
3cfddb1
fix: keep this turn's reply when a cancel lands during tools
claude Oct 4, 2026
8c5fe08
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
b941191
wiki: map #113 phase children and related issues
claude Oct 4, 2026
39aade9
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 4, 2026
4c8b180
feat(config): global ~/.lich/config.json merged under the project con…
claude Oct 4, 2026
dc815f3
fix(config): read the legacy user config only when ~/.lich/config.jso…
claude Oct 4, 2026
36f8f87
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 5, 2026
146619b
feat(config): lich init --global and a "save as global" wizard step (…
claude Oct 5, 2026
2faf90c
fix(wizard): write the config once, plugins included, when work_dir i…
claude Oct 5, 2026
eff0ea1
fix(wizard): store absolute plugin paths when writing ~/.lich/config.…
claude Oct 5, 2026
558e3d1
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 5, 2026
eaadb01
feat(config): named profiles in ~/.lich/profiles (#117)
claude Oct 5, 2026
ae7e9d8
fix(profiles): profile over the home config, stable errors, guard lis…
claude Oct 5, 2026
2d64bbf
fix(profiles): keep the legacy base at home; disk_usage skips denied …
claude Oct 5, 2026
e63bd5a
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 5, 2026
4957452
wiki: config layers page after #170-#172
claude Oct 5, 2026
0d9590e
wiki: scope config writer and error-path claims on lich-config
claude Oct 5, 2026
99fd78a
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 5, 2026
b95516b
fix(gateway): one session queue, LRU eviction, telegram-only /start, …
claude Oct 5, 2026
53d8118
fix(gateway): enforce max_conversations on store; doc webhook 502
claude Oct 5, 2026
f175158
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 5, 2026
33dbf68
feat(gateway): GatewayPolicy and declared adapter capabilities (#144)
claude Oct 5, 2026
79fa83d
Merge remote-tracking branch 'origin/main' into claude/open-issues-pr…
claude Oct 8, 2026
13551c8
feat(serve): queue frames per session on each connection (#144)
claude Oct 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- `lich serve` queues frames per session on each connection instead of
per connection (#144). A long `prompt.submit` no longer holds up other
sessions or session-less frames such as `health` on the same socket. Frames
for one session keep their order; replies across sessions may interleave,
so clients match them by JSON-RPC `id` (Ossuary already does).
- Gateway (#144): sender allowlists and the gateway toolset are one
`GatewayPolicy`, built from config at startup (`src/gateway/access.ts`).
Platform adapters declare `capabilities` (`{ kind: "text", max_reply_chars }`);
Expand Down
13 changes: 9 additions & 4 deletions docs/architecture/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ about it from the next `session.clear` or `prompt.submit` failing with
`not_found`. Evicted transcripts stay on disk and can be resumed again.

`prompt.submit` runs the server Agent with that bag's history and
`AgentRunOptions.session` (one JSONL file per serve session). Runs are serialized
so AgentEvent fan-out stays correctly tagged with `session_id`. While a run is
`AgentRunOptions.session` (one JSONL file per serve session). Runs of one
session are serialized; different sessions run concurrently. Each run's events
arrive through its own `on_event` and are tagged with that run's `session_id`. While a run is
in flight, `prompt.abort` aborts it via `AbortSignal`. The submit result mirrors
`AgentRunResult` (`reply`, `usage`, `session_path`, `turns_used`, `stopped_reason`).

Expand Down Expand Up @@ -113,8 +114,12 @@ same WebSocket that issued `prompt.submit` while the call is still in flight.
do not assume `file://` / `app://` behavior here.
- Frame size capped at ~1 MiB (`maxPayload`).
- `health` returns `{ status: "ok", version }` (`LICH_VERSION` from `src/version.ts`).
- Frames are handled per-connection in arrival order: pipelined requests get
in-order replies even when earlier requests hit slower filesystem awaits.
- Frames are queued per session within a connection: frames whose
`params.session_id` match are handled in arrival order and get in-order
replies, while other sessions, and frames that name no session (such as
`health`, `session.list` or `session.create`), do not wait behind them.
Replies from different sessions can therefore interleave; match them by
JSON-RPC `id`.
`prompt.abort` is dispatched immediately so it can cancel an in-flight
`prompt.submit` on the same socket instead of waiting behind that run.
A submit already accepted on that socket, but still waiting behind another
Expand Down
31 changes: 25 additions & 6 deletions src/serve/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ function attach_client(
prompts: ServePromptService | undefined,
inflight: Set<Promise<void>>,
): void {
// Serialize frames per connection: pipelined requests get in-order replies,
// and the tail catch keeps any rejection from becoming an unhandled one.
// prompt.abort is not on that tail. It must run while prompt.submit is still
// Serialize frames per session on this connection: frames for one session_id
// get in-order replies, while different sessions (and session-less frames
// such as health or session.list) no longer wait behind each other's runs.
// Replies across lanes can interleave; clients match them by JSON-RPC id.
// prompt.abort is on no lane. It must run while prompt.submit is still
// awaiting the model; waiting would deadlock a hung run with its own cancel.
let tail: Promise<void> = Promise.resolve();
const tails = new Map<string, Promise<void>>();
const track = (chain: Promise<void>): void => {
inflight.add(chain);
void chain.finally(() => {
Expand All @@ -256,12 +258,29 @@ function attach_client(
// Arm the controller before this frame waits on `tail`, so prompt.abort
// (which skips the tail) can cancel a submit that has not started yet.
const prepared = arm_queued_submit(data, prompts);
const chain = tail.then(() => run_frame(data, prepared));
tail = chain;
const lane = frame_lane(data);
const chain = (tails.get(lane) ?? Promise.resolve()).then(() => run_frame(data, prepared));
Comment thread
Moikapy marked this conversation as resolved.
tails.set(lane, chain);
track(chain);
// Drop an idle lane so the map does not grow with every session ever used.
void chain.finally(() => {
if (tails.get(lane) === chain) {
tails.delete(lane);
}
});
});
}

/** Lane for a frame: its params.session_id, or "" for frames that name no session. */
function frame_lane(data: RawData): string {
const params = parse_frame_object(data)?.params;
if (typeof params !== "object" || params === null || Array.isArray(params)) {
return "";
}
const session_id = (params as { session_id?: unknown }).session_id;
return typeof session_id === "string" && session_id.length > 0 ? `session:${session_id}` : "";
}

interface PreparedSubmit {
session_id: string;
controller: AbortController;
Expand Down
64 changes: 63 additions & 1 deletion test/serve_prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,11 +1104,12 @@ describe("serve prompt over websocket", () => {
return body;
});
await started;
// Same session_id, so this frame shares the submit's lane and must wait behind it.
const health_promise = request_rpc(ws, {
jsonrpc: "2.0",
id: 4,
method: "health",
params: { note: "prompt.abort" },
params: { session_id, note: "prompt.abort" },
}).then((body) => {
order.push(4);
return body;
Expand Down Expand Up @@ -1142,6 +1143,67 @@ describe("serve prompt over websocket", () => {
}
});

it("runs different sessions on one connection concurrently, and session-less frames do not wait", async () => {
const work_dir = await make_temp_dir("serve-ws-lanes");
const session_dir = path.join(work_dir, "sessions");
let release_hang!: () => void;
const hang = new Promise<void>((resolve) => {
release_hang = resolve;
});
let hang_started!: () => void;
const started = new Promise<void>((resolve) => {
hang_started = resolve;
});
const fetch_fn: typeof fetch = async (_url, init) => {
const body = JSON.parse(String(init?.body)) as { messages: Array<{ content?: string }> };
if (body.messages.some((message) => message.content === "hang")) {
hang_started();
await hang;
}
return new Response(
JSON.stringify({
model: "mock-model",
choices: [{ message: { role: "assistant", content: "done" }, finish_reason: "stop" }],
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
}),
{ status: 200 },
);
};
const agent = mock_agent(work_dir, fetch_fn);
const server = create_serve_server({ port: 0, boot_stdout: null, session_dir, agent, version: "9.9.9" });
servers.push(server);
const boot = await server.start();
const ws = await open_ws(`ws://127.0.0.1:${boot.port}/?token=${encodeURIComponent(boot.token)}`);
try {
const create = async (id: number): Promise<string> =>
((await request_rpc(ws, { jsonrpc: "2.0", id, method: "session.create", params: { source: "test" } })).result as {
session_id: string;
}).session_id;
const a = await create(1);
const b = await create(2);
const order: string[] = [];
const slow = request_rpc(ws, { jsonrpc: "2.0", id: 3, method: "prompt.submit", params: { session_id: a, text: "hang" } }).then(
(body) => {
order.push("a");
return body;
},
);
await started;
const fast = await request_rpc(ws, { jsonrpc: "2.0", id: 4, method: "prompt.submit", params: { session_id: b, text: "hi" } });
order.push("b");
const health = await request_rpc(ws, { jsonrpc: "2.0", id: 5, method: "health" });
order.push("health");
expect(fast.result).toMatchObject({ session_id: b, stopped_reason: "final" });
expect(health.result).toBeDefined();
release_hang();
expect((await slow).result).toMatchObject({ session_id: a, stopped_reason: "final" });
expect(order).toEqual(["b", "health", "a"]);
} finally {
release_hang();
ws.close();
}
});

it("stop() aborts an in-flight prompt instead of draining the model call", async () => {
const work_dir = await make_temp_dir("serve-stop-abort");
const session_dir = path.join(work_dir, "sessions");
Expand Down
Loading