Skip to content

fix(gateway): include opted-in cron context in active-turn redirects - #107862

Open
KoNit-K wants to merge 2 commits into
NousResearch:mainfrom
KoNit-K:fix/discord-active-redirect-cron-context
Open

KoNit-K wants to merge 2 commits into
NousResearch:mainfrom
KoNit-K:fix/discord-active-redirect-cron-context

Conversation

@KoNit-K

@KoNit-K KoNit-K commented Sep 11, 2026 •

Copy link
Copy Markdown

What does this PR do?

An opted-in cron briefing can already be delivered to Discord and persisted in the exact reply-facing session, but an accepted active-turn redirect still built model-facing messages from the pre-delivery in-memory snapshot. A bare follow-up then reached the agent without the brief.

This PR records a session_id-scoped delivery handoff at the moment a successful attach_to_session: true persist lands. An accepted normal or priority busy redirect moves that handoff onto the running agent. _apply_active_turn_redirect then includes it as a labeled reference block in api_content (not as a new user instruction). The cached prefix, live tool state, and role alternation stay unchanged.

Related Issue

Fixes #107856

Type of Change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/cron_delivery_handoff.py — in-process pending handoff keyed by exact ; attach/drain/format helpers. Fail-open, never raises.
  • cron/scheduler_delivery.py — after a successful opted-in mirror/seed persist, record the handoff. Delivery is never reported failed because bookkeeping broke.
  • gateway/run_busy.py — / : after an accepted unquoted redirect, move same-session handoffs onto the agent. Do not rewrite / user content.
  • agent/conversation_loop.py — consume agent-scoped references into only.
  • tests/cron/test_discord_cron_followup_context.py — issue reproduction — idle attach controls plus DM/thread × normal/priority active redirects.

How to Test

  • scripts/run_tests.sh on the files in Changes Made — focused verification
  • HERMES_PYTHON=<venv-with-pytest+discord.py> scripts/run_tests.sh \
  • BEFORE (RED): 4 failed, 6 passed. Active DM/thread × normal/priority failed with: "Successful opted-in Discord delivery is durable, but the accepted active follow-up only carries the README snapshot and the user's bare question, not the cron brief". Idle attach None/False/True controls passed.
  • AFTER (GREEN): 10 passed, 0 failed on the contract file.
  • Affected suites: tests/run_agent/test_steer.py, tests/cron/test_scheduler.py, tests/cron/test_mirror_origin_fallback.py, tests/gateway/test_busy_steer_origin.py, tests/gateway/test_mirror.py — 207 passed, 0 failed.
  • scripts/run_tests.sh \

Evidence

  • BEFORE: the focused probe was RED on origin/main before this change
  • AFTER: - [x] scripts/run_tests.sh on the files in Changes Made — focused verification — 6 passed
  • CONTROL: neighboring paths listed in How to Test still pass

Checklist

Code

  • ✅ I've read the Contributing Guide
  • ✅ My commit messages follow Conventional Commits
  • ✅ I searched for existing PRs to make sure this isn't a duplicate
  • ✅ My PR contains only changes related to this fix
  • ✅ I've run relevant tests locally (see How to Test)
  • ✅ I've added tests for my changes
  • ✅ I've tested on my platform: macOS

Documentation & Housekeeping

  • ✅ Documentation update: N/A unless noted in Changes Made
  • ✅ cli-config.yaml.example: N/A
  • ✅ CONTRIBUTING.md or AGENTS.md: N/A
  • ✅ Cross-platform impact considered
  • ✅ Tool descriptions/schemas: N/A

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/cron Cron scheduler and job management comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint platform/discord Discord bot adapter sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Sep 11, 2026
@KoNit-K
KoNit-K force-pushed the fix/discord-active-redirect-cron-context branch from 179045a to 3694ec6 Compare September 17, 2026 13:55
An accepted Discord follow-up during an in-flight turn was seeing only the pre-delivery snapshot, even after the same session had already persisted the opted-in briefing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@KoNit-K
KoNit-K force-pushed the fix/discord-active-redirect-cron-context branch from 3694ec6 to 2ff0beb Compare September 18, 2026 09:35
@KoNit-K

KoNit-K commented Sep 18, 2026

Copy link
Copy Markdown
Author

Rebased onto the latest main and resolved the busy-session integration conflict. Accepted active redirects now preserve the cron-delivery handoff while retaining the current steer path. Verified with tests/cron/test_discord_cron_followup_context.py (10 passed).

KoNit-K commented Oct 1, 2026

Copy link
Copy Markdown
Author

Updated this PR on the current main as 04f5f82c21d2604aa9c3fdd1590c81b5a252019f.

Successful opted-in cron delivery now records a session-scoped handoff. Accepted normal and priority active-turn redirects transfer that handoff to the running agent, and the redirect correction adds it as labeled reference context in api_content without rewriting the cached prefix, user content, or role sequence. The current centralized priority redirect entry point was preserved during the merge.

Verification: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m pytest tests/cron/test_discord_cron_followup_context.py tests/gateway/test_busy_steer_origin.py tests/cron/test_scheduler.py tests/cron/test_mirror_origin_fallback.py -q — 143 passed. Two pre-existing runtime warnings from standalone send coroutines were emitted by adjacent scheduler/mirror tests.

There are no review threads to resolve on this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/discord Discord bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Active Discord redirects miss cron context already attached to the same session

2 participants