Repository navigation
feat(channels): warn before a recycle backend's session is restarted - #17678
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check on a live deepseek session that the warning arrives before the restart notice. One turn that jumps from below 60% to 70% or more skips the warning band, so no warning is sent. [DESIGN-REVIEWED] 338ee7b Description read[DESCRIPTION-READ] cf7d65be07968519c593dfaad3b462624aa46823df32dc40902fd68b42dfa87d That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Issue #11948 is What this change shipsInventory (6 items) — 6 justifiedIntent: before Crew restarts a deepseek-class session at the context threshold, tell the channel user so they can wrap up or send
[FIRST-PRINCIPLES-REVIEWED] 338ee7b Description read[DESCRIPTION-READ] 232d91420c16fbc9a5e94be218944919008d19996e8d58caad8660b0d8ef2cd7 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Dispositions for the review round on
|
ecac0e4 to
b7fa4da
Compare
b7fa4da to
e363620
Compare
e363620 to
c4fd9a3
Compare
c4fd9a3 to
9600bc6
Compare
9600bc6 to
338ee7b
Compare
UX Review (Opus 5.5) — ⏭️ skippedRevision |
iamwhatever
left a comment
There was a problem hiding this comment.
Approving (crew-pr-reviewer). On a backend that recycles instead of compacting (deepseek today), the user got no warning before the agent forgot the conversation. Now one notice arrives inside [threshold - margin, threshold) of the session's live autocompact_pct. That is the value the recycle fires at, not the channel's 80% soft threshold, which would land after the restart. Harness-managed backends keep their silence. Both lanes PASS. CI is green and the base is main.
Problem / Motivation
Goal: A user on a backend Crew restarts at the context threshold (deepseek today) is told once, before the restart, that the agent is about to forget the conversation and that
/newlets them start fresh on their own terms.On a backend in
ACP_BACKENDS_CONTEXT_RECYCLE, Crew restarts the session when context crossessession.autocompact_pct. The chat keeps working and the agent loses what it remembered. Every messaging surface suppresses its soft-threshold nudge for any backend that cannot take/compact, so this user gets no warning at all — only the after-the-fact restart notice.Why it matters
The restart discards the agent's working memory of the conversation. Users on Discord, Telegram, Teams, Webex, Feishu, WeCom, WeChat, iMessage and WhatsApp currently have no chance to wrap up, save what matters, or start fresh themselves before that happens.
Not a goal
What changed (motivation → approach → change)
Symptom: no warning before a recycle. Root cause: the soft-branch gate
compact_unsupported_backend(provider)treats "cannot take/compact" as one population, which covers both kas (correctly silent) and deepseek (wrongly silent).Approach, per the issue's plan, with one deliberate deviation:
messaging.commands.recycle_backend(provider)answers only for the recycle arm, read through the existingcompact_refusal_arm— no surface reads a membership itself.messaging.commands.context_recycle_warning(new_command)/context_recycle_warning_zh()hold the warning once (English, plus the shared Chinese wording for Feishu/WeCom/WeChat), stating the same facts as the recycle arm ofcompact_unsupported_reply, before the fact, offering/new(!newon Discord) and never/compact.soft_threshold_pct.recycle_warning_duefires in[autocompact_pct - CONTEXT_WARN_MARGIN_PCT, autocompact_pct). The channel soft default is 80 and the recycle default is 70, so the issue's literal step 1 (drop the suppression at the soft threshold) would warn after the restart, i.e. never in practice. At or past the threshold the recycle is already scheduled, so no "soon" is promised there.CONTEXT_WARN_MARGIN_PCTis the same margin the session manager already logs its own pre-threshold warning at.messaging.commands.recycle_warning_should_sendholds the band-and-latch rule once: one warning per fill (the existingawaitinglatch), cleared outside the band so the next fill after a restart warns again, and a turn that may not speak (WhatsApp mute/unprompted) does not spend it. Each of the nine surfaces'_maybe_noticeasks it for a recycle backend, sends in its own words, and returns.The issue gate was a capability boundary set in #8156/#11942; this PR adds a user-facing message, which is the reason the issue carries
needs-human.Backwards compatibility
Compatible: only adds a message on recycle backends; harness-managed, unclassified and compactable backends take exactly the code path they take on main.
Removes nothing: no key, function, path or record is removed or tightened.
Tests
test/test_context_recycle_warning.py(47 cases), driving each surface's_maybe_noticeagainst a minimal dispatcher stand-in:/new(!newon Discord) and no/compact— per surface;recycle_warning_dueband edges and the live per-session threshold; a threshold read that raises answersFalse;recycle_backendisNonefor kas, an unknown id and a provider with no answer.Red on base
4a241ce599(first revision of the file): 33 failed / 18 passed (the 18 are the kas and at-threshold pins, already true on main). Mutations, each reddening named tests: dropping the band's upper bound (test_no_warning_once_the_recycle_threshold_is_reached[*]), treating every/compact-refusing backend as recycle (test_a_harness_managed_backend_still_gets_nothing[*]), removing the re-arm inrecycle_warning_should_send(9 failed,test_the_next_fill_after_a_restart_warns_again[*]), and ignoringmay_speak(test_a_muted_whatsapp_conversation_is_not_warned_and_keeps_its_one_warning). Only this file was run locally; CI runs the rest.Manual verification
Not run against a live deepseek session or real channel transports from this host; coverage is the per-surface unit matrix above. A live check would be: deepseek backend on Telegram,
session.autocompact_pct70, drive context to ~65% and confirm one warning arrives before the restart notice.Related Issues
Closes #11948
Decision for the owner
The decision is whether Crew should warn deepseek-class users before restarting their session at the context threshold, and when. This draft warns once per fill on all nine channel surfaces, keyed to the recycle threshold minus the existing 10-point margin rather than the channel soft threshold, because the soft threshold (80) sits above the recycle (70) and a warning keyed to it would arrive after the restart.
Pattern harvest
Not generalizable: the gap came from one capability predicate standing in for two populations, and #11942 already moved the choice into the single
compact_refusal_armreader that this PR reuses.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.