Stop → Continue: resume truncated or aborted assistant turns#49
Conversation
Backend (chatbot.py): - Capture `final.stop_reason` from each Anthropic stream and propagate it on the `done` SSE event. The frontend uses "max_tokens" to detect truncation; "end_turn" / "stop_sequence" mean the model finished cleanly. Frontend (ChatPage.tsx): - Extend Message with `stop_reason` and `stopped` flags. The `done` handler stores `stop_reason`; the AbortError catch (user clicks Stop) sets `stopped: true`. Both flags survive saveConversation/loadConversation via the untyped messages JSON column on the backend. - Render a Continue affordance below any message where `stop_reason === "max_tokens" || stopped`, hidden if a tool is still pending in the message (no orphan tool calls). - New `continueMessage(idx)` posts the conversation up to and including the partial assistant turn back to /chat/message. Anthropic's assistant-prefill behaviour means the model continues the same logical turn — no "Continue from where you stopped" nudge needed. Streamed content appends into the SAME message bubble; cost is summed onto the existing `cost_gbp`. If continue itself truncates or is stopped, the affordance comes back (user-driven, not auto-loop). Acceptance criteria: - max_tokens → Continue button appears. - User clicks Stop mid-stream → partial preserved + Continue appears. - Continue resumes in-place, single bubble, summed cost. - Out of scope: indefinitely auto-continuing — kept user-triggered. Closes #44 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Beta preview has been cleaned up because this PR was closed. |
Resolve the ChatPage.tsx conflict: the no-tool `done` branch now keeps both main's `isComplete: true` (from #47) and this branch's `stop_reason`. Also fix two issues raised in review: - continueMessage persisted the resumed turn with stale metadata: the saveConversation copy was built from the pre-continuation `messages` closure, so `stop_reason`/`stopped`/`cost_gbp` kept their old values. A reload then restored the Continue button and the pre-continuation cost. The saved copy now carries the fresh post-continuation values. - The partial turn is sent to Anthropic as an assistant prefill, which is rejected if it is empty or ends with whitespace — common for a max_tokens / Stop truncation. Trim the prefill content and bail early when nothing remains to continue from. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Pushed Merge conflict — merged Bug 1 — resumed turn persisted as still-truncated. In Bug 2 — trailing-whitespace assistant prefill. The partial turn is sent to Anthropic as a prefill, which is rejected if it's empty or ends with whitespace — common for a Verification: Not changed — flagging for a follow-up, not this PR:
|
Merge-readiness auditRan a full check on the post-fix branch ( Verified green:
Confirmed the two fixes are sound, not just plausible:
Non-blocking items left for follow-up (not fixed in this PR):
Verdict: technically safe and ready — correct on all happy paths, builds clean, conflict resolved, CI green. The remaining items are non-blocking. The one thing outstanding is a human sign-off on the conflict resolution + the two fixes — @SakshiKekre, a second look at |
Summary
A long policy analysis that hits the 16k `max_tokens` cap, or one the user kills with Stop, currently dies there — they have to start a new chat and re-explain context. This PR adds a Continue affordance below those messages that resumes from exactly where the answer stopped.
Closes #44.
Behaviour
Implementation notes
Test plan
Out of scope