Skip to content

Commit d61b552

Browse files
committed
fix(chat): recover exact pending outcomes after reconnect
Retain bounded sent and discarded dispositions under the original browser, device and pane identity. Replay them to a returning connection or an already attached successor without submitting terminal input again. Preserve uncertainty when a receipt is missing, expired or only dismissed by aging out. Keep live connection ownership and remote relay boundaries. Add ownership, retention, expiry and deferred Enter-reply regressions, plus before/after browser evidence and pinned OpenClaw ACP research. Verification: typecheck, 64 scoped unit tests and 3 receipt contracts passed. The broader 110-case pending suite and fork browser checks also passed; the final fast suite and final screenshot replay follow this commit. Refs devswha#2421.
1 parent e6e6719 commit d61b552

15 files changed

Lines changed: 461 additions & 24 deletions

‎DESIGN.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,14 @@ Alert rows of the table above from the `--droplet-*` roles in `src/styles.css`.
26032603
a stale copy that missed the removal remains explicitly resendable to preserve offline recovery.
26042604
Actions keep a
26052605
`--touch-target` touch target on phones.
2606+
Ordinary pending-message dispositions also recover across a lost socket: the bridge keeps up
2607+
to 1024 exact outcomes for ten minutes, bound to the original pane, browser resume ID and
2608+
authenticated device. Reattach replays only those outcomes, so a delivered message's saved
2609+
**Not confirmed** copy disappears without another paste or Enter. A live row owned by another
2610+
connection, a missing or expired receipt, and an ambiguous send stay unchanged. This extends
2611+
Ovis's Pi receipt-recovery pattern and follows OpenClaw's separation of request identity,
2612+
acceptance and outcome recovery ([source research](docs/codex-unconfirmed/openclaw-research.md));
2613+
it keeps Ovis's terminal send path and does not infer delivery from matching transcript text.
26062614
Sending disables that item's actions; errors stay inline. Uncertain messages offer Copy and
26072615
Discard saved copy, with no retry action. Desktop and phones share this flow.
26082616
- Accepted pending messages clear only the draft prefix acknowledged by the bridge. For agents
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Fixed
2+
- A delivered chat message no longer stays “Not confirmed” after a connection drops before its
3+
receipt arrives. The same browser and device can recover its exact outcome for up to ten minutes,
4+
without sending the message again. Missing or expired outcomes remain uncertain.

‎docs/codex-unconfirmed/README.md‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,54 @@ In `server/core/pending.ts`, a normal client's pending-message removal is sent o
2424

2525
The conservative handling avoids resending a delivered message. The unresolved behavior is presentation recovery: the bridge has successfully delivered it, but the returning page cannot recover that exact delivery outcome. Matching transcript text alone would not safely establish message identity. A possible improvement is to retain and resume the exact delivery disposition for the same authenticated browser/device and message ID, without granting permission to send anything.
2626

27-
## Validation
27+
## Original reproduction validation
2828

2929
- `bun run build`: passed.
3030
- `bun run check run bun docs/codex-unconfirmed/reproduce.ts`: passed, including the no-failure control, exact input bytes, reconnect, reload and screenshot.
3131
- No application implementation was changed. This evidence reproduces one triggering condition; it does not establish why the original browser lost confirmation.
3232
- `bun run check fast`: failed one unchanged installer test, `scripts/install-node-fallback.test.ts:299`, which expected `[ node]` and received `[]`. Workflow syntax, generated types/themes, typecheck and build passed. No installer change was made as part of this report.
3333
- Full integration/browser/native Windows suites were not run for this evidence-only branch.
34+
35+
## Fork fix
36+
37+
The fork now retains ordinary pending-message dispositions using the same browser/device resume
38+
identity as Pi's existing receipt recovery. It stores at most 1024 sent/discarded outcomes for ten
39+
minutes and replays the exact ID on reattach. If the committed Enter's reply arrives after a
40+
successor has already attached, that successor receives the outcome immediately. This does not
41+
paste or submit anything, resume a queued message,
42+
or treat matching conversation text as confirmation. Missing receipts remain uncertain.
43+
44+
The [OpenClaw research](openclaw-research.md) explains the source-backed comparison: ACPx's
45+
passive outcome journal and OpenClaw's exact request-ID reconciliation solve a similar separation
46+
between delivering a prompt and showing its outcome. Ovis keeps its existing terminal send path.
47+
48+
The fork was merged with upstream `3c679791` while preserving saved launchers, custom Codex and
49+
OMP stores, and navigation fixes. To verify the patched behavior with the same fault injection:
50+
51+
```sh
52+
EXPECT_RECEIPT_RECOVERY=1 bun run check run --build bun docs/codex-unconfirmed/reproduce.ts
53+
```
54+
55+
The check verifies one paste and Enter for each message, an exact resumed delivery receipt,
56+
the completed native-format transcript, no duplicate recovery row, and no further terminal input
57+
after reconnect and reload. It uses the same stand-in and fictional data as the original evidence.
58+
59+
| Before | After receipt recovery |
60+
| --- | --- |
61+
| ![Completed message and uncertain copy](codex-not-confirmed.png) | ![Completed message with no duplicate copy](codex-confirmed.png) |
62+
63+
The fixed run's events and assertions are in [result-fixed.json](result-fixed.json). This covers
64+
the reproduced receipt-loss case. A bridge restart or a receipt that predates retention cannot
65+
be reconstructed; an old uncertain copy still needs review and manual dismissal.
66+
67+
Receipt resumption keeps Ovis's existing direct-bridge limit: the remote-PC relay strips the
68+
browser resume ID because its shared bridge token does not identify the originating device.
69+
Routed remote sessions therefore keep the existing conservative behavior. A stale tab can also
70+
write an old saved copy after another tab settled it; after a reload and expiry of the server's
71+
receipt, that copy remains uncertain rather than being guessed delivered.
72+
73+
Coverage includes both reconnect orderings, exact message IDs, no extra input, device/browser
74+
isolation, read-only and revoked clients, retention bounds, and uncertain-row expiry. The existing
75+
110-case pending contract suite passed before the final ordering adjustment; all three targeted
76+
receipt contracts and 64 store/history/core tests passed after it. Fork browser checks also passed
77+
for saved launchers, new-session fields, worktree selection and deep-link navigation.
32.1 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Recovering a delivered message's confirmation
2+
3+
Research for [Ovis #2421](https://github.com/devswha/ovis/issues/2421), checked 30 October 2026 against primary documentation and source. OpenClaw source: `0f359b36dc48808097dae18767cf9ccb49390ccb`; acpx source: `6ce38c34f4e5aef16bf28ca8b1fb1e6650695c60` (0.21.1), with the watch contract also verified on release 0.21.0 (`c0b9dfdfad12ed4fc000b8ef2efc4b5644f1c3dc`). No live OpenClaw or Codex run was performed.
4+
5+
## What OpenClaw owns
6+
7+
OpenClaw's current default Codex route is its native Codex app-server integration. Codex through ACP is an explicit alternative using the official `@openclaw/acpx` plugin and `@agentclientprotocol/codex-acp`. The plugin revision inspected pins acpx 0.21.0 and codex-acp 2.2.2. The adapter is a separate Agent Client Protocol project: it starts Codex App Server, translates ACP requests into Codex operations, and translates events back. It is not a way to acknowledge keystrokes sent to an existing Herdr terminal. [OpenClaw routes](https://docs.openclaw.ai/tools/acp-agents), [plugin dependencies](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/extensions/acpx/package.json), [adapter architecture](https://github.com/agentclientprotocol/codex-acp/blob/ac8d9251de43ab8648a89eb0520e0c606ad78be5/README.md).
8+
9+
The ACP stack separates the OpenClaw session identity, backend session identity, request identity and completion. The harness attempt creates a persistent session, obtains an admitted transcript-entry receipt and creates a request ID from that entry plus a UUID. Assistant persistence gets its own idempotency key derived from that request. The runtime exposes `promptStarted`, events and `result` separately. An acknowledgement that transport accepted a prompt does not mean its model turn completed. [Harness admission and request identity](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/extensions/acpx/src/harness-attempt.ts#L155), [request creation](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/extensions/acpx/src/harness-attempt.ts#L255), [runtime result surface](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/extensions/acpx/src/runtime.ts#L1052).
10+
11+
## How confirmation survives a disconnected reader
12+
13+
ACPx provides passive `sessions watch` for its CLI/shared-session path. Its retained journal associates events with an exact submitting request ID and opaque cursor. A watcher can reconnect from its last cursor and observe `turn_result`, whose status is completed, cancelled or failed. Disconnecting a watcher neither sends the prompt again nor cancels it. `turn_started` means an attempt was selected; `promptStarted` indicates prompt transport acceptance; `turn_result` follows cleanup and checkpoint attempts. If the owner disappeared without recording a result, the observer gets `WATCH_OUTCOME_UNKNOWN`. It must not infer success from partial output. Retention is bounded: expired cursors fail explicitly. Custom in-process stores do not automatically publish this CLI/shared journal. This is an acpx capability; I did not establish that OpenClaw's browser uses this watch API. [Release-pinned watch contract](https://github.com/openclaw/acpx/blob/c0b9dfdfad12ed4fc000b8ef2efc4b5644f1c3dc/docs/session-watch.md), [journal implementation](https://github.com/openclaw/acpx/blob/6ce38c34f4e5aef16bf28ca8b1fb1e6650695c60/src/session/events.ts#L222).
14+
15+
OpenClaw's browser has a separate recovery mechanism. Its queued send retains the original request/idempotency key and physical conversation identity through reconnect. Tests explicitly cover reconnecting after a written frame lost its reply. Gateway admission checks the exact previous request and returns cached or in-flight state; the comparison reads the submitted message by its request-derived identity under the session/lifecycle scope and rejects conflicting input. This is stronger than matching a visible string. [Browser reconnect tests](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/ui/src/pages/chat/chat-outbox-reconnect.test.ts), [written-frame recovery](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/ui/src/pages/chat/chat-outbox-transient-recovery.test.ts#L170), [cached admission](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/src/gateway/server-methods/chat-send-pre-admission.ts#L164), [exact request comparison](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/src/gateway/server-methods/chat-send-retry-comparison.ts#L39).
16+
17+
Its pending-input UI queries exact run IDs and reconciles pending/consumed/cancelled custody receipts. A receipt or an explicitly queried absence can retire that specific projection; an unrelated empty history page cannot settle arbitrary saved input. The UI also checks the physical session before removing a browser queue copy. [Pending-input reconciliation](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/ui/src/pages/chat/chat-pending-inputs.ts#L36), [settling queue copies](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/ui/src/pages/chat/chat-pending-inputs.ts#L218).
18+
19+
Cancellation is explicit. ACPx requests cooperative session cancellation and waits briefly for a cancelled result before forced cleanup. Watching/disconnecting alone is observation. OpenClaw separately stops automatic ingress startup retries once a prepared ACP turn is accepted, so a slow answer is not a reason to dispatch the trigger again. [ACPx cancellation](https://github.com/openclaw/acpx/blob/c0b9dfdfad12ed4fc000b8ef2efc4b5644f1c3dc/docs/sessions.md#cancelling), [OpenClaw delivery rules](https://github.com/openclaw/openclaw/blob/0f359b36dc48808097dae18767cf9ccb49390ccb/docs/tools/acp-agents/delivery.md#delivery-model).
20+
21+
## Applying the lesson to Ovis
22+
23+
The transferable mechanism is exact, server-owned outcome recovery. ACP itself is not required. Ovis already has a PTY send boundary and a browser/device receipt-resume identity for Pi. Extend the presentation recovery pattern rather than replacing how a terminal receives prompts.
24+
25+
Proposed bounded change, inferred from those sources and Ovis's reproduced failure:
26+
27+
1. Retain each ordinary pending message's terminal disposition under its exact message ID, pane and authenticated browser/device resume owner. Record it before trying to notify the socket. Retain no execution authority.
28+
2. On reattach by that same owner, replay successful/withdrawn dispositions through the existing pending-message protocol. Let an exact receipt settle the corresponding recovery copy even though its old connection scope is gone.
29+
3. Reconnecting performs no paste, Enter or prompt resubmission. Do not copy OpenClaw's automatic `chat.send` retry into Ovis: its send contract differs.
30+
4. An expired, missing or unprovable receipt leaves the saved row uncertain. Text equality, agent completion and an empty snapshot are not delivery receipts. Preserve Herdr lifetime fencing and owner isolation.
31+
32+
Tests should lose the successful removal receipt, reconnect and reload, then prove the exact row disappears and terminal bytes remain a single delivery. Also cover a different resume owner/device, two same-text sends with different IDs, no receipt, retention expiry, live ownership on another connection, a replaced Herdr lifetime, duplicate receipts, and a failure after paste but before committed Enter. A before/after screenshot should use the same fictional transcript and fault boundary.
33+
34+
This repairs one proven trigger of #2421. It does not establish why the original browser lost confirmation, provide exactly-once execution across bridge restarts, or prove that a PTY Enter is a native Codex model-acceptance acknowledgement.

‎docs/codex-unconfirmed/reproduce.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { UsageService } from "../../server/usage.ts";
1414
const root = mkdtempSync(join(tmpdir(), "ovis-unconfirmed-"));
1515
const output = resolve(process.env.UI_EVIDENCE_DIR ?? "evidence/codex-unconfirmed");
1616
mkdirSync(output, { recursive: true });
17+
const recovery = process.env.EXPECT_RECEIPT_RECOVERY === "1";
1718
const codexHome = join(root, "home");
1819
const rollout = join(codexHome, "sessions", "rollout.jsonl");
1920
mkdirSync(join(codexHome, "sessions"), { recursive: true });
@@ -56,7 +57,6 @@ try {
5657
upstream.onMessage(data => {
5758
const frame = JSON.parse(String(data));
5859
if (frame.type === "input-ready" && frame.pane_id === pane) inputReady = frame.ready !== false;
59-
if (frame.type === "submit-result") console.log("submit result", frame);
6060
if (frame.type === "pending-messages") events.push(frame);
6161
if (loseReceipt && !dropped && frame.type === "pending-messages" && frame.removed?.some((x: { outcome: string }) => x.outcome === "sent")) {
6262
dropped = true;
@@ -96,18 +96,20 @@ try {
9696
const text = "Follow-up: confirm the receipt-loss reproduction.";
9797
const answer = await run(text, true);
9898
await until(() => dropped && connections >= 2, "page reconnects after losing the delivery receipt");
99-
await until(async () => await rows.filter({ hasText: text }).getAttribute("data-state") === "uncertain", "delivered message remains Not confirmed");
99+
if (recovery) await until(async () => await rows.count() === 0, "the resumed exact receipt settles the recovery copy");
100+
else await until(async () => await rows.filter({ hasText: text }).getAttribute("data-state") === "uncertain", "delivered message remains Not confirmed");
100101
await page.reload();
101102
await page.locator(".conn-live").waitFor();
102103
await panel.getByText(answer, { exact: true }).waitFor();
103104
const transcript = await (await page.request.get(`http://127.0.0.1:${server.port}/api/pane/conversation?pane_id=${encodeURIComponent(pane)}`)).json();
104105
assert.equal(transcript.source, "codex-transcript");
105106
assert.ok(JSON.stringify(transcript.turns).includes(answer));
106-
await until(async () => await rows.filter({ hasText: text }).getAttribute("data-state") === "uncertain", "Not confirmed survives reload despite completed native transcript");
107+
if (recovery) assert.equal(await rows.count(), 0, "the settled copy stays gone after reload");
108+
else await until(async () => await rows.filter({ hasText: text }).getAttribute("data-state") === "uncertain", "Not confirmed survives reload despite completed native transcript");
107109
assert.equal(bytes(), expected, "reconnect and reload never resend either message");
108-
await panel.screenshot({ path: join(output, "codex-not-confirmed.png") });
109-
const summary = { upstream: Bun.spawnSync(["git", "rev-parse", "HEAD"]).stdout.toString().trim(), agent: "byte-recording stand-in, fictional Codex-format transcript; no native Codex/model run", control: "one delivery, row removed", receiptLoss: "one delivery; sent receipt lost before browser; reconnect and reload leave uncertain row", nativeTranscript: "completed user and assistant turns visible in Chat", replayed: false, connections, pendingEvents: events };
110-
writeFileSync(join(output, "result.json"), JSON.stringify(summary, null, 2) + "\n");
110+
await panel.screenshot({ path: join(output, recovery ? "codex-confirmed.png" : "codex-not-confirmed.png") });
111+
const summary = { revision: Bun.spawnSync(["git", "rev-parse", "HEAD"]).stdout.toString().trim(), recovery, agent: "byte-recording stand-in, fictional Codex-format transcript; no native Codex/model run", control: "one delivery, row removed", receiptLoss: recovery ? "one delivery; lost sent receipt replayed after reconnect; no recovery row after reconnect or reload" : "one delivery; sent receipt lost before browser; reconnect and reload leave uncertain row", nativeTranscript: "completed user and assistant turns visible in Chat", replayed: false, connections, pendingEvents: events };
112+
writeFileSync(join(output, recovery ? "result-fixed.json" : "result.json"), JSON.stringify(summary, null, 2) + "\n");
111113
console.log(JSON.stringify(summary, null, 2));
112114
} catch (error) {
113115
if (page) console.error("UI at failure", (await page.locator("body").innerText()).slice(-4500));

0 commit comments

Comments
 (0)