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 @@ -8,6 +8,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f

### Fixed

- **Sessions run on omp 18.22.** omp now ends a run once and pauses between loops; the runner maps that onto the same `agent_end`/`session_settled` frames as before, so completion, notifications and background-work settlement behave as they did.
- **GitHub workflow watches no longer regress to stale run states.** Workflow updates retain GitHub's run timestamp and ignore older snapshots for the same or an earlier attempt, so a delayed `queued` response cannot follow a newer `in_progress` delivery.
- **Keep sidebar transcript results aligned with expandable hits on every linked host.** Each daemon now searches its own active conversations, ignoring abandoned branches and pre-compaction messages.

Expand Down
78 changes: 39 additions & 39 deletions runner/bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runner/omp-build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"repo": "ompweb-dev/oh-my-pi",
"tag": "v18.20.0-int.202611131515.g11d9dc7"
"tag": "v18.22.0-int.202611171027.gec3956c"
}
42 changes: 21 additions & 21 deletions runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
"build": "bun scripts/build-binary.ts"
},
"dependencies": {
"@oh-my-pi/pi-coding-agent": "file:./vendor/oh-my-pi-pi-coding-agent-18.20.0.tgz",
"@oh-my-pi/pi-natives": "file:./vendor/oh-my-pi-pi-natives-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-utils": "file:./vendor/oh-my-pi-pi-utils-18.20.0-int.202611131515.g11d9dc7.tgz"
"@oh-my-pi/pi-coding-agent": "file:./vendor/oh-my-pi-pi-coding-agent-18.22.0.tgz",
"@oh-my-pi/pi-natives": "file:./vendor/oh-my-pi-pi-natives-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-utils": "file:./vendor/oh-my-pi-pi-utils-18.22.0-int.202611171027.gec3956c.tgz"
},
"devDependencies": {
"@types/bun": "1.4.4",
"typescript": "7.0.2"
},
"overrides": {
"@oh-my-pi/omp-stats": "file:./vendor/oh-my-pi-omp-stats-18.20.0.tgz",
"@oh-my-pi/omptype": "file:./vendor/oh-my-pi-omptype-18.20.0.tgz",
"@oh-my-pi/pi-agent-core": "file:./vendor/oh-my-pi-pi-agent-core-18.20.0.tgz",
"@oh-my-pi/pi-ai": "file:./vendor/oh-my-pi-pi-ai-18.20.0.tgz",
"@oh-my-pi/pi-catalog": "file:./vendor/oh-my-pi-pi-catalog-18.20.0.tgz",
"@oh-my-pi/pi-coding-agent": "file:./vendor/oh-my-pi-pi-coding-agent-18.20.0.tgz",
"@oh-my-pi/pi-mnemopi": "file:./vendor/oh-my-pi-pi-mnemopi-18.20.0.tgz",
"@oh-my-pi/pi-natives": "file:./vendor/oh-my-pi-pi-natives-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-darwin-arm64": "file:./vendor/oh-my-pi-pi-natives-darwin-arm64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-darwin-x64": "file:./vendor/oh-my-pi-pi-natives-darwin-x64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-linux-arm64": "file:./vendor/oh-my-pi-pi-natives-linux-arm64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-linux-x64": "file:./vendor/oh-my-pi-pi-natives-linux-x64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-win32-arm64": "file:./vendor/oh-my-pi-pi-natives-win32-arm64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-natives-win32-x64": "file:./vendor/oh-my-pi-pi-natives-win32-x64-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-tui": "file:./vendor/oh-my-pi-pi-tui-18.20.0.tgz",
"@oh-my-pi/pi-utils": "file:./vendor/oh-my-pi-pi-utils-18.20.0-int.202611131515.g11d9dc7.tgz",
"@oh-my-pi/pi-wire": "file:./vendor/oh-my-pi-pi-wire-18.20.0.tgz",
"@oh-my-pi/snapcompact": "file:./vendor/oh-my-pi-snapcompact-18.20.0.tgz"
"@oh-my-pi/omp-stats": "file:./vendor/oh-my-pi-omp-stats-18.22.0.tgz",
"@oh-my-pi/omptype": "file:./vendor/oh-my-pi-omptype-18.22.0.tgz",
"@oh-my-pi/pi-agent-core": "file:./vendor/oh-my-pi-pi-agent-core-18.22.0.tgz",
"@oh-my-pi/pi-ai": "file:./vendor/oh-my-pi-pi-ai-18.22.0.tgz",
"@oh-my-pi/pi-catalog": "file:./vendor/oh-my-pi-pi-catalog-18.22.0.tgz",
"@oh-my-pi/pi-coding-agent": "file:./vendor/oh-my-pi-pi-coding-agent-18.22.0.tgz",
"@oh-my-pi/pi-mnemopi": "file:./vendor/oh-my-pi-pi-mnemopi-18.22.0.tgz",
"@oh-my-pi/pi-natives": "file:./vendor/oh-my-pi-pi-natives-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-darwin-arm64": "file:./vendor/oh-my-pi-pi-natives-darwin-arm64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-darwin-x64": "file:./vendor/oh-my-pi-pi-natives-darwin-x64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-linux-arm64": "file:./vendor/oh-my-pi-pi-natives-linux-arm64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-linux-x64": "file:./vendor/oh-my-pi-pi-natives-linux-x64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-win32-arm64": "file:./vendor/oh-my-pi-pi-natives-win32-arm64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-natives-win32-x64": "file:./vendor/oh-my-pi-pi-natives-win32-x64-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-tui": "file:./vendor/oh-my-pi-pi-tui-18.22.0.tgz",
"@oh-my-pi/pi-utils": "file:./vendor/oh-my-pi-pi-utils-18.22.0-int.202611171027.gec3956c.tgz",
"@oh-my-pi/pi-wire": "file:./vendor/oh-my-pi-pi-wire-18.22.0.tgz",
"@oh-my-pi/snapcompact": "file:./vendor/oh-my-pi-snapcompact-18.22.0.tgz"
}
}
2 changes: 1 addition & 1 deletion runner/src/commands/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function sessionState(session: AgentSession) {
sessionName: session.sessionName,
autoCompactionEnabled: session.autoCompactionEnabled,
queuedMessageCount: session.queuedMessageCount,
hasPendingAsyncWork: session.hasPendingAsyncWork(),
hasPendingAsyncWork: session.wakeSources !== undefined,
isSettled: isSessionSettled(session),
queuedMessages: {
steering: [...queued.steering],
Expand Down
2 changes: 1 addition & 1 deletion runner/src/commands/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const sessionCommands: CommandTable = {
async edit_message(ctx, args) {
const { session } = ctx;
const entryId = requiredString("edit_message", args, "entryId");
if (session.isBusyForSnapshot || session.hasPendingAsyncWork()) {
if (session.isBusyForSnapshot || session.isRunActive) {
throw new CommandError("Cannot edit while the agent is running", "session_busy");
}
const entry = session.sessionManager.getEntry(entryId);
Expand Down
97 changes: 13 additions & 84 deletions runner/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* switches to full until the message ends, then back to delta.
*
* Events that are not plain AgentSession events:
* session_settled {type} the session went quiet after activity ({@link SessionSettleWatcher})
* agent_end {type, messages, isTerminal, yielded, awaitingAsyncWork?} one per stopped model loop: omp's `agent_pause` is `isTerminal: false`, the run's `agent_end` `isTerminal: true`, both via omp's `toWireEvent`
* session_settled {type} the session went quiet after activity (omp's `RpcSessionSettleWatcher`)
* available_commands_update {type, commands} at subscribe, on command-metadata change, after a session change
* session_info_update {type, title?, sessionId} the session name changed (TUI /rename, auto title, host rename)
* notice (source "session-persistence") {type, level, message, source} store failure (error) or session moved to a new file (warning)
Expand All @@ -20,10 +21,10 @@
*/
import type { AssistantMessage, AssistantMessageEvent } from "@oh-my-pi/pi-ai";
import { formatPersistenceFailure, formatPersistenceNotice } from "@oh-my-pi/pi-coding-agent/modes/persistence-failure";
import { RpcSessionSettleWatcher, watchedScheduledTurnProbe } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-session-settle";
import type { AgentSession, AgentSessionEvent } from "@oh-my-pi/pi-coding-agent/session/agent-session";
import { isSessionSettled, waitForSessionSettlement } from "@oh-my-pi/pi-coding-agent/session/session-settle";
import { toWireEvent, type WireSessionEvent } from "@oh-my-pi/pi-coding-agent/session/loop-end-wire";
import { buildAvailableSlashCommands } from "@oh-my-pi/pi-coding-agent/slash-commands/available-commands";
import { logger } from "@oh-my-pi/pi-utils";
import type { CommandContext, CommandTable } from "./commands/types";
import { onClientQueueChange, stampClientMessageId } from "./correlation";

Expand Down Expand Up @@ -115,7 +116,9 @@ class SessionEventForwarder {
return this.#filter ? Array.from(this.#filter) : null;
}

forward(event: AgentSessionEvent): void {
forward(sessionEvent: AgentSessionEvent): void {
// Loop pauses and the run's end go out as per-loop `agent_end` frames (isTerminal/yielded), the shape ompweb reads.
const event = toWireEvent(sessionEvent);
const messageId = this.#stamp(event);
if (this.#filter && !this.#filter.has(event.type)) return;
if (event.type === "message_update" && this.#messageUpdates === "delta") {
Expand All @@ -130,7 +133,7 @@ class SessionEventForwarder {
this.#output(messageId === undefined ? event : { ...event, messageId });
}

#stamp(event: AgentSessionEvent): string | undefined {
#stamp(event: WireSessionEvent): string | undefined {
switch (event.type) {
case "message_start": {
const messageId = this.#mintMessageId();
Expand Down Expand Up @@ -161,79 +164,9 @@ class SessionEventForwarder {
}
}

async function nextMacrotask(): Promise<void> {
const { promise, resolve } = Promise.withResolvers<void>();
setImmediate(resolve);
await promise;
}

/**
* Emits `session_settled` once per stretch of agent activity, after the final run yields and background work
* that could wake the session has drained. Re-checks on every terminal `agent_end` and after session transitions.
*/
class SessionSettleWatcher {
/** Agent activity since the last `session_settled`. */
#active = false;
#checking = false;
#recheck = false;
readonly #session: AgentSession;
readonly #output: (frame: object) => void;
readonly #scheduledTurn: () => boolean;

constructor(session: AgentSession, output: (frame: object) => void, scheduledTurn: () => boolean) {
this.#session = session;
this.#output = output;
this.#scheduledTurn = scheduledTurn;
}

observe(event: AgentSessionEvent): void {
if (event.type === "agent_start") this.#active = true;
else if (event.type === "agent_end" && event.isTerminal !== false) void this.check();
}

/** Record activity no `agent_start` announces (a reported pending goal turn), so its stretch still settles. */
markActive(): void {
this.#active = true;
}

/**
* Settle the current stretch of activity if the session is quiet, waiting out background work that will wake
* it. A live run is left alone: its own terminal `agent_end` triggers the next check.
*/
async check(): Promise<void> {
if (this.#checking) {
this.#recheck = true;
return;
}
this.#checking = true;
try {
do {
this.#recheck = false;
// Two hops: prompt_result frames for this yield are written one macrotask after it, and
// session_settled must follow them.
await nextMacrotask();
await nextMacrotask();
if (this.#active) {
await waitForSessionSettlement(this.#session, {
isCurrent: () => this.#active,
scheduledTurn: this.#scheduledTurn,
});
}
} while (this.#recheck);
if (!this.#active || !isSessionSettled(this.#session, this.#scheduledTurn)) return;
this.#active = false;
this.#output({ type: "session_settled" });
} catch (error) {
logger.warn("ompweb: session settle check failed", { error: String(error) });
} finally {
this.#checking = false;
}
}
}

interface HostEvents {
forwarder: SessionEventForwarder;
settle: SessionSettleWatcher;
settle: RpcSessionSettleWatcher;
emitCommands(): Promise<void>;
}

Expand All @@ -244,7 +177,7 @@ const scheduledTurns = new WeakMap<AgentSession, () => boolean>();
export function subscribeHostEvents(session: AgentSession, send: CommandContext["send"]): () => void {
const event = (frame: object) => send({ t: "event", event: frame });
const forwarder = new SessionEventForwarder(event);
const settle = new SessionSettleWatcher(session, event, () => scheduledTurns.get(session)?.() ?? false);
const settle = new RpcSessionSettleWatcher(session, event, () => scheduledTurns.get(session)?.() ?? false);
const emitCommands = async () => {
event({ type: "available_commands_update", commands: await buildAvailableSlashCommands(session) });
};
Expand Down Expand Up @@ -282,19 +215,15 @@ export function subscribeHostEvents(session: AgentSession, send: CommandContext[
*/
export function scheduledTurnProbe(session: AgentSession, pending: () => boolean): () => boolean {
scheduledTurns.set(session, pending);
return () => {
const isPending = pending();
if (isPending) bridges.get(session)?.settle.markActive();
return isPending;
};
return watchedScheduledTurnProbe(pending, () => bridges.get(session)?.settle);
}

/** Re-check settlement where no terminal `agent_end` will (an abandoned goal turn, a prompt that settled without a run). */
/** Re-check settlement where no run `agent_end` will (an abandoned goal turn, a prompt that settled without a run). */
export function checkSettled(session: AgentSession): void {
void bridges.get(session)?.settle.check();
}

/** After new/switch/branch/fork/open session: the detached run sends no terminal `agent_end`, and the command catalog may differ. */
/** After new/switch/branch/fork/open session: the detached run sends no `agent_end`, and the command catalog may differ. */
export async function afterSessionChange(session: AgentSession): Promise<void> {
const bridge = bridges.get(session);
if (!bridge) return;
Expand Down
4 changes: 2 additions & 2 deletions runner/src/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GoalController {
readonly #session: AgentSession;
/** Active tool set before goal mode added `goal`; restored when the goal ends. */
#previousTools: string[] | undefined;
/** Continuation turns submitted whose terminal `agent_end` has not arrived. */
/** Continuation turns submitted whose run has not reached its `agent_end`. */
#pendingContinuationTurns = 0;
#previousContinuationActivity: string | undefined;
/** A continuation turn made no new progress; wait for the host before continuing. */
Expand Down Expand Up @@ -307,7 +307,7 @@ export class GoalController {
}
return;
}
if (event.type !== "agent_end" || event.isTerminal === false) return;
if (event.type !== "agent_end") return;
if (this.#pendingContinuationTurns > 0) {
this.#pendingContinuationTurns--;
const activity = goalContinuationActivity(event.messages);
Expand Down
13 changes: 6 additions & 7 deletions runner/src/prompt-results.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* `prompt_result` reporting: every accepted `prompt`/`abort_and_prompt` not answered with `agentInvoked: false`
* gets exactly one `{t:"prompt_result", id, agentInvoked, status, sessionSettled, error?}` once the work it caused
* has yielded: at once for local-only slash commands and failures, else after the terminal `agent_end` of the run
* the prompt started or joined. The host correlates on the cmd `id` instead of guessing who owns an `agent_end`.
* has yielded: at once for local-only slash commands and failures, else once the run the prompt started or joined
* yields (`agent_pause` with `yielded`, or `agent_end`). The host correlates on the cmd `id` instead of guessing who owns an `agent_end`.
*/
import type { AgentMessage } from "@oh-my-pi/pi-agent-core";
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
Expand Down Expand Up @@ -109,7 +109,7 @@ export class PromptResults {

/**
* Mark every open prompt aborted after a session transition: transitions detach the agent before aborting it,
* so the interrupted run never publishes a terminal `agent_end` for them.
* so the interrupted run never publishes an `agent_end` for them.
*/
abortOpen(): void {
for (const [ticket, open] of this.#open) {
Expand All @@ -119,16 +119,15 @@ export class PromptResults {
}
}

/** Track run boundaries; call after the event was sent so `prompt_result` follows its `agent_end`. */
/** Track run boundaries; call after the event was sent so `prompt_result` follows its yield. */
observe(event: AgentSessionEvent): void {
if (event.type === "agent_start") {
this.#agentStarts++;
this.#refusalAtRunStart = this.#session.costCapRefusal;
return;
}
if (event.type !== "agent_end" || this.#open.size === 0) return;
// Older sessions omit `yielded`; only their terminal ends were yields.
if (!(event.yielded ?? event.isTerminal !== false)) return;
if (this.#open.size === 0) return;
if (event.type !== "agent_end" && (event.type !== "agent_pause" || !event.yielded)) return;
// A request the cost gate refused during this run is its outcome, whatever message ended it.
const outcome = this.#costCapOutcome(this.#refusalAtRunStart) ?? runOutcome(event.messages);
// A still-queued steer/follow-up has not been read by the agent yet.
Expand Down
20 changes: 20 additions & 0 deletions runner/test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("host events bridge", () => {

const types = events.map(event => event.type);
expect(types.indexOf("session_settled")).toBeGreaterThan(types.lastIndexOf("agent_end"));
expect(events.filter(event => event.type === "agent_end")).toMatchObject([{ isTerminal: true, yielded: true }]);

const assistantEnd = events.find(event => event.type === "message_end" && JSON.stringify(event).includes("scripted reply"));
const updates = events.filter(event => event.type === "message_update");
Expand All @@ -73,6 +74,25 @@ describe("host events bridge", () => {
});
});

it("sends a loop paused on background work as a non-terminal agent_end, and the run's end as the terminal one", async () => {
const { session, events, waitFor } = await bridged([{ content: ["started the job"] }, { content: ["job done"] }]);
const job = Promise.withResolvers<string>();
session.asyncJobManager?.register("bash", "wait", () => job.promise, { ownerId: session.getAgentId() });
await session.prompt("go");
await session.waitForIdle();

const ends = () => events.filter(event => event.type === "agent_end");
const paused = { isTerminal: false, yielded: true, awaitingAsyncWork: true };
expect(ends()).toMatchObject([paused]);
expect(events.some(event => event.type === "session_settled")).toBe(false);

// The job's result resumes the run; its loop ends the run.
job.resolve("done");
await waitFor("session_settled");
expect(ends()).toMatchObject([paused, { isTerminal: true, yielded: true }]);
expect(events.some(event => event.type === "agent_pause")).toBe(false);
});

it("reports session renames", async () => {
const { session, events, waitFor } = await bridged();
session.sessionManager.setSessionName("renamed", "user");
Expand Down
Loading