Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
- Catch up missed conversation entries incrementally after reconnecting or returning to the page, including during active runs. Restore quiet partial responses and live tool output without duplicating history or overwriting newer updates.
- Send prompts with image attachments in full again: commands reach OMP as one unchunked JSONL record. Protocol-v2 `rpc_chunk` framing is outbound-only, so any prompt over 1 MiB was rejected as `Unknown command: rpc_chunk` and reset the session after the prompt-ack timeout.
- Show the **New session** fork action below agent replies as well as user prompts, so the newest message in a conversation can fork the session. omp's `branch` command accepts a user entry only, so each reply forks at the prompt that started its turn; replies with no earlier prompt keep no fork action.
- Send the first message of a new session after typing `/` or running a slash command. Opening the command list starts the session before OMP has written its file, so the pre-send history check failed with `Failed to send message: HTTP 404`. An idle session with no file now counts as having no prior history; while a run is still unsaved, the check still reports it as unknown.

---

Expand Down
19 changes: 14 additions & 5 deletions app/api/sessions/[id]/context/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ export async function GET(
const resolved = await resolveSessionPathOr404(id);
if ("response" in resolved) {
// OMP may not create the file until the first assistant message is
// committed. A live wrapper can still recover that first partial reply.
// Never replace previously confirmed history when its file is missing.
const session = sync === "1" && !cursor?.lastEntryId && leafId === undefined ? getRpcSession(id) : undefined;
if (session?.isAlive() && !existsSync(session.sessionFile)) {
// committed, so a live wrapper can exist before its file does.
const live = getRpcSession(id);
const unpersisted = live?.isAlive() && !existsSync(live.sessionFile) ? live : undefined;
// A session created ahead of its first prompt (typing "/" loads commands
// through ensure_session) is idle and has persisted nothing: its run
// boundary is empty. While a run is in flight the boundary stays unknown
// (404) — that run's unpersisted entries must not count as the next one's.
if (unpersisted && boundary === "1" && !unpersisted.isRunning()) {
return NextResponse.json({ entryIds: [] }, { headers: { "Cache-Control": "no-store" } });
}
// A live wrapper can still recover that first partial reply. Never
// replace previously confirmed history when its file is missing.
if (unpersisted && sync === "1" && !cursor?.lastEntryId && leafId === undefined) {
const response: SessionSyncResponse = {
...selectSessionHistory(buildSessionContext([]), cursor, limit),
sessionId: id,
leafId: null,
live: session.getStreamSnapshot(),
live: unpersisted.getStreamSnapshot(),
};
return NextResponse.json(response, { headers: { "Cache-Control": "no-store" } });
}
Expand Down
33 changes: 33 additions & 0 deletions lib/session-routes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,36 @@ test("sync recovers the first live reply before persistence without erasing an e
}
});
});

test("boundary is empty for an idle session created before its first prompt, unknown once a run starts", async () => {
await withAgentDir(async (dir) => {
const id = "ensured-not-prompted";
const filePath = join(dir, "2026-01-01_ensured-not-prompted.jsonl");
let emit;
const wrapper = new AgentSessionWrapper({
isAlive: true,
onFrame(listener) { emit = listener; return () => {}; },
sendCommand: async () => ({ sessionId: id, sessionFile: filePath, isStreaming: false, isCompacting: false }),
sendFrame() {},
dispose: async () => {},
}, dir);
wrapper.start();
await wrapper.send({ type: "get_state" });
globalThis.__ompSessions ??= new Map();
globalThis.__ompSessions.set(id, wrapper);
try {
const idle = await getContext(id, "boundary=1");
assert.equal(idle.status, 200);
assert.equal(idle.headers.get("Cache-Control"), "no-store");
assert.deepEqual(await idle.json(), { entryIds: [] });
assert.equal(existsSync(filePath), false);
emit({ type: "agent_start" });
assert.equal((await getContext(id, "boundary=1")).status, 404, "an in-flight unpersisted run keeps the boundary unknown");
globalThis.__ompSessions.delete(id);
assert.equal((await getContext(id, "boundary=1")).status, 404, "without a live wrapper a missing file is not found");
} finally {
await wrapper.destroyAndWait();
globalThis.__ompSessions.delete(id);
}
});
});