Skip to content

fix(discord): carry CLI handoff initiator into threads - #65505

Open
whirmill wants to merge 1 commit into
NousResearch:mainfrom
whirmill:fix/discord-handoff-initiator-current
Open

fix(discord): carry CLI handoff initiator into threads#65505
whirmill wants to merge 1 commit into
NousResearch:mainfrom
whirmill:fix/discord-handoff-initiator-current

Conversation

@whirmill

Copy link
Copy Markdown
Contributor

Summary

This is a current-main replacement for #26872 (fix(discord): add initiator to handoff threads).

The original PR attempted to read row.user_id, but normal CLI /handoff rows do not contain the Discord initiator. This replacement makes the identity explicit at request time and carries it through the handoff state row and gateway to the current Discord plugin adapter.

  • Extend CLI /handoff discord [discord_user_id] with validation.
  • Persist the explicit ID on the handoff request.
  • Pass the ID only to the Discord adapter; other platform adapters keep their existing call contract.
  • Resolve the member and add it to both direct and fallback-created Discord handoff threads.
  • Clear stale identity on subsequent handoff requests when no ID is supplied.
  • Add CLI/DB, adapter, and gateway _process_handoff regression coverage.

This branch is based on the current main and deliberately does not include the obsolete adapter paths or unrelated changes from #26873. It is also kept separate from #63459 so maintainers can coordinate the adjacent anchor/tracker work independently.

Verification

  • scripts/run_tests.sh tests/gateway/test_discord_send.py tests/hermes_cli/test_session_handoff.py -q — 35 passed
  • scripts/run_tests.sh tests/gateway/test_telegram_topic_mode.py tests/gateway/test_async_session_db.py tests/gateway/test_handoff_watcher_async_db.py -q — 62 passed
  • ruff check on all touched Python files
  • python -m py_compile on all touched Python files
  • git diff --check

Supersedes the implementation approach in #26872; the historical PR is intentionally not force-pushed.

@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/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to closed predecessor #26872 and the adjacent Discord handoff session-key fix #59467. This is a current-main replacement, not a duplicate of the closed PR.

@teknium1 teknium1 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.

Thanks for rebuilding the Discord handoff change against the current architecture. The missing initiator path is real: current main calls create_handoff_thread without identity at gateway/run.py:7787.

Problems

  • hermes_state.py:7143 repurposes sessions.user_id as handoff transport. That field is durable gateway routing/ownership metadata (hermes_state.py:2029-2044) and persisted-session /resume uses it for ownership checks (gateway/slash_commands.py:828-960). The existing TUI handoff caller still calls request_handoff without an ID (tui_gateway/server.py:6771), so this change would set that metadata to NULL.

Suggested changes

  • Carry the Discord initiator in a handoff-specific field and read that field in _process_handoff; preserve sessions.user_id.
  • Add coverage for preserving an existing user_id for both explicit-initiator CLI handoffs and the no-initiator TUI/desktop call path.

Automated hermes-sweeper review.

Comment thread hermes_state.py
" handoff_platform = ?, "
" handoff_error = NULL "
" handoff_error = NULL, "
" user_id = ? "

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.

sessions.user_id is durable gateway ownership/routing metadata, not handoff scratch state. This shared method is also called by tui_gateway/server.py without user_id, so this assignment clears existing identity. Please add a handoff-specific initiator field and leave sessions.user_id unchanged.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 18, 2026
@GottZ

GottZ commented Aug 3, 2026

Copy link
Copy Markdown

This was generated by AI during triage.

Summary

Two open PRs address distinct failures in the CLI-to-gateway handoff path: #27326 propagates the originating workspace for Codex, while #65505 carries an explicit Discord initiator into newly created handoff threads. Their diffs target separate causes and both retain salvageable implementations, but each uses a persistence path identified by its visible keep-open review as needing rework.

Related pull requests

  • fix: preserve cwd for Codex handoffs #27326 related — (+138/-15) — n/a: The diff captures the CLI cwd, stores it as handoff_cwd, and passes it to agent.session_cwd for the Codex app-server, directly targeting the wrong-workspace failure; consistent with the maintainer-bot keep-open verdict, it should be salvaged by using canonical sessions.cwd and propagating cwd through the current gateway session-context path.
  • fix(discord): carry CLI handoff initiator into threads #65505 related — (+199/-10) — n/a: The diff accepts an explicit Discord user ID and adds the resolved member to both direct and fallback-created handoff threads, but transports the ID through durable sessions.user_id; consistent with the COMMENTED keep-open review, it should use a handoff-specific field and preserve existing ownership metadata for explicit-ID and no-ID callers.

Suggested consolidation

Keep both PRs open with separate salvage paths: rework #27326 around sessions.cwd with end-to-end gateway cwd propagation, and rework #65505 around a handoff-specific initiator field with ownership-preservation coverage. They address different causes, so neither should be closed as a duplicate of the other.

Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 32 kB of PR diffs, 3 kB of issue/PR text, 1 kB of discussion (3 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

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

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists platform/discord Discord bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data 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.

4 participants