Skip to content

feat(channels): warn before a recycle backend's session is restarted - #17678

Merged
iamwhatever merged 1 commit into
mainfrom
fix/recycle-context-warning-11948
Oct 8, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/recycle-context-warning-11948

Conversation

@buluoray

@buluoray buluoray commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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 /new lets them start fresh on their own terms.

On a backend in ACP_BACKENDS_CONTEXT_RECYCLE, Crew restarts the session when context crosses session.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

  • Changing when the recycle fires, or the post-restart notice.
  • Changing the harness-managed (kas) path: it keeps its suppression, because its context shrinks on its own.
  • Slack: it has no soft-threshold nudge on main, so there is nothing to split there.
  • The dashboard chat surface.

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:

  1. messaging.commands.recycle_backend(provider) answers only for the recycle arm, read through the existing compact_refusal_arm — no surface reads a membership itself.
  2. 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 of compact_unsupported_reply, before the fact, offering /new (!new on Discord) and never /compact.
  3. Deviation: the warning is keyed to the session's live recycle threshold, not the channel's soft_threshold_pct. recycle_warning_due fires 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_PCT is the same margin the session manager already logs its own pre-threshold warning at.
  4. messaging.commands.recycle_warning_should_send holds the band-and-latch rule once: one warning per fill (the existing awaiting latch), 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_notice asks 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_notice against a minimal dispatcher stand-in:

  • recycle backend inside the band: exactly one warning across two turns, containing /new (!new on Discord) and no /compact — per surface;
  • harness-managed backend (kas) at 65/85/99%: nothing, no compaction — per surface;
  • recycle backend at/above the threshold: nothing — per surface;
  • below-band reading re-arms, so a second fill warns again — per surface;
  • muted WhatsApp conversation does not spend its one warning;
  • recycle_warning_due band edges and the live per-session threshold; a threshold read that raises answers False;
  • recycle_backend is None for 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 in recycle_warning_should_send (9 failed, test_the_next_fill_after_a_restart_warns_again[*]), and ignoring may_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_pct 70, 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_arm reader that this PR reuses.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Issue #11948 is needs-human. A maintainer should confirm that warning recycle-backend users once per fill, at autocompact_pct − 10, is the behaviour they want.

What this change ships

Inventory (6 items) — 6 justified

Intent: before Crew restarts a deepseek-class session at the context threshold, tell the channel user so they can wrap up or send /new themselves. This is an ADDITION.

  1. On nine channels (Discord, Feishu, iMessage, Teams, Telegram, Webex, WeCom, WeChat, WhatsApp), a user on a recycle backend now gets one warning before the restart, where before they got nothing. — justified
  2. The warning fires 10 points below the session's restart threshold, not at the channel's soft threshold (80). — justified
  3. The warning comes back on the next fill after a restart, and a muted WhatsApp turn does not use it up. — justified
  4. On a recycle backend the warning offers /new (!new on Discord) and never mentions /compact; the Chinese surfaces share one wording. — justified
  5. kas and backends that can compact behave exactly as they do on main. — justified
  6. The providers spec adds an exception to "notices decline silently" and cites Warn before a recycle backend's session is restarted at the context threshold #11948. — justified

[FIRST-PRINCIPLES-REVIEWED] 338ee7b

Description read

[DESCRIPTION-READ] 232d91420c16fbc9a5e94be218944919008d19996e8d58caad8660b0d8ef2cd7

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 338ee7b

Verdict parsed from the review's SHA-scoped output markers for commit 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 338ee7b

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc: <one-sentence reason>

@buluoray

buluoray commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Dispositions for the review round on ecac0e4a84, addressed in b7fa4da0b9:

  • GPT 6.1 BLOCKING / Semgrep test-autouse-shared-monkeypatch (test/test_context_recycle_warning.py:176): fixed — the autouse fixture now requests _floor_monkeypatch.
  • Comment History Gate ((#11948) and "used to" in the test module docstring): fixed — docstring states current behaviour only.
  • First Principles item 4 (oversized defensive branches): taken — recycle_warning_due now calls sessions.effective_autocompact_pct() directly inside the existing try; the getattr/callable/bool branches and their tests are removed.
  • Design suggestion (nine copies of warn-and-re-arm): taken — the band-and-latch rule lives once in messaging.commands.recycle_warning_should_send; each surface keeps only its own send call.
  • Design check: a single turn jumping from below 60% to 70%+ gets no warning: acknowledged, not changed. In that case the recycle fires on the same reading and the existing post-restart notice is what the user sees; a pre-warning on that turn would announce something already happening. Widening the band trades this for earlier, more frequent warnings, which is the owner's call recorded under "Decision for the owner".
  • First Principles item 1 (no recorded decision for the new default warning): left for the owner by design — this is the needs-human decision the draft exists to put in front of them. No override posted.

@buluoray
buluoray force-pushed the fix/recycle-context-warning-11948 branch from ecac0e4 to b7fa4da Compare October 7, 2026 09:57
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 7, 2026
@buluoray
buluoray force-pushed the fix/recycle-context-warning-11948 branch from b7fa4da to e363620 Compare October 7, 2026 10:19
@buluoray
buluoray marked this pull request as ready for review October 7, 2026 18:20
@buluoray
buluoray requested a review from a team as a code owner October 7, 2026 18:20
@buluoray
buluoray requested a review from CrysisDeu October 7, 2026 18:20
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 7, 2026
@buluoray
buluoray force-pushed the fix/recycle-context-warning-11948 branch from e363620 to c4fd9a3 Compare October 7, 2026 19:47
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 7, 2026
@buluoray
buluoray force-pushed the fix/recycle-context-warning-11948 branch from c4fd9a3 to 9600bc6 Compare October 7, 2026 21:47
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 7, 2026
@buluoray
buluoray force-pushed the fix/recycle-context-warning-11948 branch from 9600bc6 to 338ee7b Compare October 8, 2026 00:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 338ee7ba8ca3cda742bb351c699b03c0f2d08fdc touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 8, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 8, 2026 01:23
@iamwhatever
iamwhatever merged commit 1e90fba into main Oct 8, 2026
102 checks passed
@iamwhatever
iamwhatever deleted the fix/recycle-context-warning-11948 branch October 8, 2026 01:24
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn before a recycle backend's session is restarted at the context threshold

2 participants