Repository navigation
fix(mocactl): render another device's newer turn as its own on resume - #692
Conversation
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
The approach is right: comparing the replayed turn frame's id with the transcript's open turn, settling our turn on a mismatch, and settling on every terminal. The tests cover both the two-device split and the same-turn catch-up. One must-fix, inline: the open-turn ref outlives the turn it describes when that turn ends without a terminal frame, so this device's next turn is labeled as another device's.
Areas: mocactl render/useSession/app + tests. No .claude/.vscode changes. 1 commit, DCO signed. CI 17/17 green.
Assisted-By: Claude Code
| // own, rather than appending it into our still-open reply. | ||
| if (f.type === 'turn') { | ||
| const ours = openTurn.current; | ||
| openTurn.current = f.turnId; |
There was a problem hiding this comment.
must-fix: openTurn.current is only cleared by a terminal frame (L146). These paths leave it set:
attach-none: the resumed turn isturn_not_found, or anendedturn frame was caught up onturn-endwithout a terminal: a dropped stream, an abort-cancel, or "the harness ended the turn without a result"
In each case the next prompt's own turn frame (t2) is compared against the stale t1, and startsForeignTurn puts "another device's turn" between the user's prompt and their own reply. The most direct way to hit it: resume an open-detachable turn the server no longer has. attach-none with missed: true shows INTERRUPTED_TURN_NOTICE, which tells the user to send "go on". That "go on" reply is then labeled as another device's.
Suggest clearing the ref in attach-none, turn-end and turn-start, so only an attach's first turn frame is ever compared. Also add a use-session test for attach-none → submit → no notice.
There was a problem hiding this comment.
Fixed in 8f73d83 — you were right, and it was worse than one path.
The ref is now cleared on all three ways out of a turn that aren't a terminal frame:
attach-none—turn_not_found, or catching up on an already-endedturnturn-endwith no terminal — a dropped stream, or an abort reported through the end aloneturn-start— this device starting its own turn, which no catch-up of the previous one can continue
So only an attach's first turn frame is ever compared against it, as you suggested.
Your repro is now a test: resume an open detachable turn the server no longer has, get INTERRUPTED_TURN_NOTICE, take its advice and send "go on" — the reply came back with another device's turn wedged between the prompt and its answer. It failed with exactly that extra notice block before the fix. A second test covers the turn-end-without-terminal path the same way.
The existing #483 tests still hold unchanged: an attach emits attach-start, never turn-start, so clearing on turn-start leaves the two-device split alone. 17/17 in use-session.test.tsx, 181/181 across the four core suites, tsc --noEmit clean.
A resume's attach replays the session's LATEST turn (spec §4.2), which need not be the one this device left open: another device may have run a newer one while this device was away. Its frames were appended into the still-open turn, so the other device's reply read as the continuation of our half-written one, under our prompt. The transcript already records the open turn's id, so compare it against the replayed `turn` frame's id. When they differ, settle our turn where it stopped — reply final, unfinished tools marked interrupted — and show a notice before the replay so the turn that follows is not read as the answer to the prompt above it. Settling is also what keeps the live area honest: an open assistant block would swallow the other turn's text, and an unsettled tool would pin every later block in the live area for the rest of the session. For the same reason a terminal frame now settles the open detachable turn, which the resume-time marking skips: `restarting`, `owner_lost` or a cancel mid-tool could otherwise leave a result-less tool open forever. Display only: nothing new is asked of the control plane or the harness. Fixes rossoctl#483 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Review follow-up on rossoctl#483: `openTurn` was only cleared by a terminal frame, so it outlived the turn it described on every other path out of that turn. Three of them: - `attach-none` — the resumed turn is `turn_not_found`, or an already-`ended` turn frame was caught up on. The blocks are settled, the ref is not. - `turn-end` with no terminal — a dropped stream, or an abort the harness reports through the end alone. - `turn-start` — this device starting a turn of its own, which no catch-up of the previous turn can continue. In each case the next turn's own `turn` frame was compared against the stale id and `startsForeignTurn` put "another device's turn" between the user's prompt and their own reply. The most direct repro: resume an open detachable turn the server no longer has. The `attach-none` shows INTERRUPTED_TURN_NOTICE, which tells the user to send "go on" — and that reply came back labelled as another device's. Only an attach's first `turn` frame should ever be compared against the ref, which is what clearing it on these three paths leaves. Two use-session tests, one per leak path. The existing rossoctl#483 tests still hold: an attach emits `attach-start`, never `turn-start`, so the two-device split is unaffected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
8f73d83 to
1efb388
Compare
|
@ingpaolodettori-dev ready for another look — the must-fix is addressed in The ref is cleared on all three paths out of a turn that aren't a terminal frame, as you suggested:
So only an attach's first Your repro is the first of two new The second covers the Clearing on Verification on the rebased head: 198/198 across |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up review at 1efb388 (a rebase of 8f73d83 onto main 0695305).
git range-diff shows both commits are = against d9c5e7c/8f73d83, and main changed none of the six files this PR touches between the old base 38aa214 and 0695305. So the rebase changes no code.
The earlier must-fix is resolved: openTurn.current is now also cleared on turn-start, attach-none and a turn-end that has no terminal (useSession.ts), so only the first turn frame of a resume attach is compared against a non-undefined ref. There are regression tests for both leak paths (the attach-none → "go on" repro, and turn-end with no terminal from a dropped stream). The existing #483 split tests are unaffected because an attach emits attach-start, never turn-start.
No new issues. Signed-off: yes (2/2).
A detachable turn POST that meets another device's turn gets `409 turn_in_progress`, and the client queues a conflict attach plus a resend of the prompt. Quitting or switching sessions at that moment runs `retire()`, whose `clearQueue()` drops every queued prompt -- and for a 409 the queue is the only place that prompt lives, since `runTurn` skips recording it (`if (!conflicted) record()`). It was lost without a word. Note the issue's "Current state" is stale on one point: it says the prompt "has already been written to the local transcript" and so "looks answered". The rossoctl#471 final review changed that. The prompt leaves no trace at all, so the bug is durability, not disambiguation -- the session's auto-title went with it. Now the leave paths record it as a new `unsent` transcript entry before the queue is cleared, the leave overlay says the prompt will not be sent while the user can still choose to stay, and the resume shows it under a warning notice and offers it back in the input, ready on Enter. Never auto-sent: the other device's answer may have changed the question. Esc keeps today's behavior exactly. A withdrawal is the user taking their own prompt back, so it owes a later resume nothing -- hence a dedicated `unsentRecorded` flag rather than clearing `conflict`, which also decides whether a cancel withdraws or cancels remotely. Block placement needed widening for this: an unsent prompt and its notice sit below the turn above them, like a queued prompt, so the replay of the other device's reply keeps filling its own block instead of opening a second one underneath. `TranscriptStore.load` already skips record kinds it does not know, so older clients read these transcripts unchanged. Item 4 of the issue (a notice line before the other device's turn) ships in rossoctl#692 and is deliberately not repeated here. Closes rossoctl#479 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
A detachable turn POST that meets another device's turn gets `409 turn_in_progress`, and the client queues a conflict attach plus a resend of the prompt. Quitting or switching sessions at that moment runs `retire()`, whose `clearQueue()` drops every queued prompt -- and for a 409 the queue is the only place that prompt lives, since `runTurn` skips recording it (`if (!conflicted) record()`). It was lost without a word. Note the issue's "Current state" is stale on one point: it says the prompt "has already been written to the local transcript" and so "looks answered". The rossoctl#471 final review changed that. The prompt leaves no trace at all, so the bug is durability, not disambiguation -- the session's auto-title went with it. Now the leave paths record it as a new `unsent` transcript entry before the queue is cleared, the leave overlay says the prompt will not be sent while the user can still choose to stay, and the resume shows it under a warning notice and offers it back in the input, ready on Enter. Never auto-sent: the other device's answer may have changed the question. Esc keeps today's behavior exactly. A withdrawal is the user taking their own prompt back, so it owes a later resume nothing -- hence a dedicated `unsentRecorded` flag rather than clearing `conflict`, which also decides whether a cancel withdraws or cancels remotely. Block placement needed widening for this: an unsent prompt and its notice sit below the turn above them, like a queued prompt, so the replay of the other device's reply keeps filling its own block instead of opening a second one underneath. `TranscriptStore.load` already skips record kinds it does not know, so older clients read these transcripts unchanged. Item 4 of the issue (a notice line before the other device's turn) ships in rossoctl#692 and is deliberately not repeated here. Closes rossoctl#479 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Upstream since v0.10.0: mocactl fixes for unsent prompts and resumed turns (rossoctl#692, rossoctl#694) and the MOCA -> moca rename as a name (rossoctl#695). One conflict, docs/index.md: upstream's renamed table, with our template onboarding row. The rename touches prose only where a deployment depends on it: no Secret, ConfigMap, label, selector, env var, image or config path, and no provenance record or stream name changes; ocp-sbx and ocp-combined render byte-identically to b6b15a6. mocactl's sandbox-service contract test now covers the template lifecycle methods SandboxApiClient added (retire, tags, edit, owner, quota), each checked against docs/api/openapi.yaml. Typecheck, lint, Go, harness 817, control-plane 1184, relay 228, knative-server 443, mocactl 1718 (with --testTimeout=30000), the sbx and onboarding shell suites pass. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Problem
A resume's attach replays the session's latest turn (spec §4.2), which need not be the turn
this device left open — another device may have run a newer one while this device was away. Those
frames were appended into the still-open turn, so the other device's reply rendered as the
continuation of our half-written one, sitting under our prompt.
Fixes #483 (follow-up to #471).
Fix
The transcript already records the open turn's id, so compare it against the replayed
turnframe's id. When they differ:
another device's turn) before the replay, so what follows is not read as theanswer to the prompt above it
Settling is also what keeps the live area honest: an open assistant block would swallow the other
turn's text, and an unsettled tool would pin every later block in the live area for the rest of the
session. For the same reason a terminal frame now settles the open detachable turn, which the
resume-time interrupted marking skips —
restarting,owner_lostor a cancel mid-tool couldotherwise leave a result-less tool open forever.
Display only: nothing new is asked of the control plane or the harness.
Changes
render/blocks.tsopenTurnId(transcript),startsForeignTurn(state),OTHER_DEVICE_TURN_NOTICEviews/useSession.tsturnframe; settles on a terminalapp.tsxattachTesting
Written test-first; each test was watched failing for the right reason before the implementation
(reverting the
app.tsxwiring reproduced the bug asOUR HALFTHEIR REPLYin the rendered frame).blocks.test.ts—openTurnIdacross prompt+turn / bare turn / finished / pre-detachabletranscripts;
startsForeignTurnsettles and notices; the other turn renders as its ownuse-session.test.tsx— the split on a newer turn; a regression guard that the catch-up on ourown turn still continues in place (feat: detachable turns — re-attach to a running turn after mocactl quits (#471) #481 I1); a still-open tool is interrupted on
owner_lost,restartingandcancelledapp.test.tsx— the whole resume path, transcript id through to rendered blocksvitest runinpackages/mocactl: 1669 passed. Three failures (LeaveTurnOverlay,CredentialsOverlay, trailing-slash onboarding) arewaitFor/timeout flakes under load that alsoreproduce on a clean
maintree.tsc --noEmitclean; prettier clean.Assisted-By: Claude Code