Skip to content

fix(gateway): harden source provenance and resume - #1

Open
Bonchaloo wants to merge 2 commits into
update/hermes-20260803-basefrom
update/hermes-20260803-successor
Open

Bonchaloo wants to merge 2 commits into
update/hermes-20260803-basefrom
update/hermes-20260803-successor

Conversation

@Bonchaloo

Copy link
Copy Markdown
Owner

Summary

  • Fails closed on stale, copied, malformed, or cross-profile native/relay source context.
  • Validates persisted relay resume state against the live adapter, transport epoch, profile, policy, and secret boundaries.
  • Preserves one response-generation identity across delivery lanes with bounded consume-once feedback.
  • Includes the reviewed portability fixes and the undici 6.28.0 security update.

Exact scope fence

  • Base: a16f6828bfa8d0dd71704f60064bb1ad1a10d9be
  • Head: 250cd865c669c0ca590b39f1e7efa4ded81e124e
  • Commit diff SHA-256: b11ee9f7e6bfefbb77863208f9134aaec374be4d626e46a743abc87be27b079f
  • Changed paths: 41
  • Real worktree after commit: clean; index empty

This fork review PR intentionally targets the pinned snapshot branch update/hermes-20260803-base so the PR contains only the exact reviewed candidate. Current upstream main has diverged substantially. Do not retarget or merge this PR into shared main without a separate semantic rebase, refreeze, full verification, and fresh independent review.

Verification

  • Claude Opus production review: PASS
  • Claude Opus v12.1 exact-delta review: PASS
  • Independent Hermes/Codex exact-delta review: PASS
  • Mac Python matrix: 758 passed, retries disabled
  • Mac Slack causal file: 40 passed
  • WSL exact matrix: 763 passed, retries disabled
  • WSL Slack causal file: 40 passed
  • Ruff, AST, compile, and diff checks: PASS
  • Gitleaks: 0 findings
  • TUI: 1,529 passed, 1 skipped; audit 0 vulnerabilities
  • Desktop: 4,295 passed, 2 skipped; typecheck PASS; lint 0 errors
  • Signed Mac app: codesign PASS
  • Packaged-bundle and credential-free headless binary smoke: PASS

Public notarization was not performed because Apple notarization credentials were not configured.

Activation status

No installation, runtime restart, deployment, shared-main mutation, or successor activation was performed. Activation remains a separate owner-approved gate with rollback artifacts and fresh running-revision probes.

Fail closed on stale or malformed native and relay sources, validate persisted resume state against live ownership, and keep generation-scoped response feedback bounded across delivery lanes. Preserve the reviewed portability fixes and undici security update in the frozen successor candidate.
Copilot AI lite review requested due to automatic review settings August 5, 2026 17:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the gateway’s authorization and resume behavior by introducing process-local source provenance (fail-closed on copied/mutated/stale sources), validating relay resume context against the live transport/epoch/profile, and propagating a single per-response identity across all delivery lanes. It also includes portability-related test fixes and an undici security bump for the TUI.

Changes:

  • Add a process-local SourceProvenanceRegistry and relay authenticated-epoch model to bind authorization to the exact inbound transport/source object (and revoke on copy/mutation/stale epoch).
  • Introduce response_generation as a canonical per-turn/per-response identifier and thread it through streaming, media delivery, typing/status, and proxy paths.
  • Tighten Discord channel policy handling (explicit deny wins), improve noninteractive git env behavior under WSL, and expand/adjust tests to cover the new invariants.

Reviewed changes

Copilot reviewed 40 out of 41 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ui-tui/package.json Bumps undici to 6.28.0.
package-lock.json Locks undici 6.28.0 resolution/integrity.
hermes_cli/_subprocess_compat.py Extends noninteractive_git_env() to propagate GCM_INTERACTIVE into Windows helpers under WSL via WSLENV.
gateway/turn_context.py Adds response_generation to turn context.
gateway/platforms/base.py Introduces per-response _response_generation, canonical metadata helper, and adapter-owned source provenance registry.
gateway/platforms/webhook.py Uses _profile_override during source construction for webhook events (avoids post-mutation).
gateway/stream_consumer.py Adds response_generation plumb-through and stamps _response_generation on all stream sends (including draft frames).
gateway/source_provenance.py New module implementing identity+fingerprint-based provenance tracking for dataclass sources.
gateway/session.py Validates persisted SessionSource fields strictly; adds transport_route and scope/guild alias validation.
gateway/authz_mixin.py Reworks auth decisions to require live transport provenance (native + relay) and adds Discord-specific transport-bound checks.
gateway/relay/ws_transport.py Validates inbound relay payloads, tracks authenticated epoch, isolates malformed frames, and binds relay sources to provenance/epoch.
gateway/relay/adapter.py Strips private metadata before relay serialization, generation-scopes auto-thread feedback, and tightens passthrough provenance.
plugins/platforms/discord/adapter.py Makes ignored channels an explicit deny in _discord_channel_ids_allowed and adds _discord_channel_ids_ignored.
agent/lsp/workspace.py Prevents treating the system temp root as a git worktree (but preserves nested temp repos).
tests/tools/test_termux_api_detection.py Stabilizes environment detection by neutralizing audio/WSL/container probes and mocking /proc read.
tests/tools/test_execution_flag_detection.py Improves cross-platform robustness (darwin gsort, util-linux script gating) and reduces sort workload.
tests/hermes_cli/test_noninteractive_git.py Adds coverage for preserving cached credential-helper config and WSL WSLENV behavior; isolates E2E git env.
tests/gateway/test_webhook_signature_rate_limit.py Adds profile-scoped webhook provenance immutability check.
tests/gateway/test_voice_command.py Adds helper for legacy mocks and expands Discord voice authorization/provenance coverage.
tests/gateway/test_stream_consumer.py Adds assertions that all send lanes carry canonical _response_generation.
tests/gateway/test_stream_consumer_draft.py Ensures draft and fresh-final paths preserve _response_generation across frames and preference probes.
tests/gateway/test_session.py Adds tests for scope/guild alias validation and fail-closed behavior.
tests/gateway/test_send_voice_reply_notify.py Ensures auto-TTS voice reply metadata includes _response_generation.
tests/gateway/test_restart_resume_pending.py Adds extensive relay resume validation coverage and asserts response generation UUID behavior.
tests/gateway/test_relay_upstream_authz.py Expands relay trust model tests (copy/mutation/epoch revocation; channel policy precedence).
tests/gateway/test_queued_native_image_session_key.py Ensures queued native image follow-ups use the pending event’s response generation.
tests/gateway/test_proxy_mode.py Hardens aiohttp patching approach and asserts proxy path preserves response_generation.
tests/gateway/test_post_stream_media_delivery.py Verifies post-stream media + runtime footer lanes preserve _response_generation.
tests/gateway/test_multiplex_profile_authz.py Ensures Discord adapter auth checks attach concrete transport provenance under multiplexing.
tests/gateway/test_multiplex_http_routing.py Tightens non-Discord chat_type/profile roundtrip and validates malformed chat_type fail-closed.
tests/gateway/test_multiplex_adapter_registry.py Ensures secondary sources are profiled before provenance registration in adapter handlers.
tests/gateway/test_discord_bot_auth_bypass.py Updates tests to use real DiscordAdapter-built sources (transport provenance).
tests/gateway/test_clarify_progress_leak.py Asserts clarify path sends include _response_generation in metadata.
tests/gateway/test_authz_multiplex_scope_isolation.py Expands scope-isolation tests and adds Discord channel/user/role/bot grant invariants.
tests/gateway/relay/test_ws_transport.py Adds epoch revocation and malformed-frame isolation coverage.
tests/gateway/relay/test_relay_threads.py Adds generation-scoped feedback tests and private-metadata stripping assertions.
tests/gateway/relay/test_relay_slack_prompt_dm_root.py Adds deep provenance/epoch/callback/transport mutation denial coverage through Slack DM normalization.
tests/gateway/relay/test_relay_passthrough.py Ensures passthrough sources require live epoch/registry and authorize only when bound.
tests/agent/lsp/test_workspace.py Adds tests for temp-root boundary behavior and symlink alias handling.
tests/agent/lsp/test_install_and_lint_fixes.py Prevents LSP short-circuiting the direct tsc branch in this test.
gateway/run.py Threads response_generation through agent execution and related delivery paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gateway/relay/ws_transport.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 250cd865c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gateway/authz_mixin.py Outdated
Comment on lines +447 to +448
if source.platform != Platform.DISCORD:
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow relay resume for every fronted platform

When a resume-pending session came from any relay-fronted platform other than Discord (for example Slack, which the relay wire path stamps as platform=slack plus transport_route=relay), this guard returns None before the existing fronts_platform() check can validate the live relay adapter. _schedule_resume_pending_sessions then skips the entry as unreconstructable, so interrupted Slack/Telegram relay conversations are not auto-resumed after restart and remain pending until the user sends another message.

Useful? React with 👍 / 👎.

@Bonchaloo

Copy link
Copy Markdown
Owner Author

v12.5 final candidate pushed.

  • Commit: 893ecefc8f05552fa1baa50bce7982d301d2c373
  • Complete base-relative patch SHA-256: 543b5c9261edb9773a45978808665eeb8fc6438a059e2d60aaeff98488258a9d
  • Tree: 881bac967e647aae05654d98f799087f34f264cb
  • Focused provenance/authorization/resume/Matrix: 201/201 passed
  • Exact-hash focused independent review: PASS, no P0/P1 blockers
  • Ruff, compile, diff, attribution, path fence: PASS

No installation or activation is represented by this PR update.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 893ecefc8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gateway/run.py

source = entry.origin
adapter = self._adapter_for_source(source)
adapter = self._candidate_adapter_for_restored_source(source)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include relay-routed sessions in relay reconnect resumes

When this method is called from the reconnect block with platform == Platform.RELAY, the candidates list above still filters on entry.origin.platform == platform. Persisted relay sessions keep origin.platform as the underlying platform (Slack/Discord/etc.) and only mark transport_route == "relay", so if the RelayAdapter was not ready during startup and connects later, this new restored-source path never runs for those sessions and their resume_pending turns are left stuck until a user sends another message.

Useful? React with 👍 / 👎.

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.

2 participants