Skip to content

Persist inbound platform reply metadata - #73399

Open
ITMINDSCAPE wants to merge 2 commits into
NousResearch:mainfrom
ITMINDSCAPE:fix/persist-reply-metadata
Open

Persist inbound platform reply metadata#73399
ITMINDSCAPE wants to merge 2 commits into
NousResearch:mainfrom
ITMINDSCAPE:fix/persist-reply-metadata

Conversation

@ITMINDSCAPE

@ITMINDSCAPE ITMINDSCAPE commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Persist inbound platform correlation metadata alongside user transcript rows so gateway features can reliably resolve native replies after a restart.

Each inbound MessageEvent can now persist:

  • platform
  • chat ID
  • incoming message ID
  • replied-to message ID

platform_message_id remains a separate indexed column for deduplication and lookup.

Implementation

  • add an additive messages.platform_metadata JSON/TEXT column through the existing declarative schema reconciler
  • thread metadata through gateway, turn-context, standard agent, Codex, proxy, queued-follow-up, and early-failure persistence paths
  • preserve metadata across append, transcript replacement/compaction, export, and import
  • decode structured metadata only on raw transcript reads
  • strip platform metadata, message IDs, and the internal DB persistence marker from provider-bound message copies without mutating stored history
  • append new optional parameters after existing positional parameters to preserve API compatibility

Tests

  • tests/test_hermes_state.py: 470 passed, 1 skipped
  • focused gateway/agent/Codex/provider-projection suites: 90 passed
  • Ruff and git diff --check: passed

A full scripts/run_tests.sh run was also attempted locally. It reported 27 failures in unrelated macOS/system-integration suites. The four agent/auth failures inspected separately reproduce unchanged on a clean upstream worktree; none involve the files or behavior changed here.

@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery area/sessions Session lifecycle, resume, persistence, history P3 Low — cosmetic, nice to have needs-decision Awaiting maintainer decision before any implementation 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 Jul 28, 2026

@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 tracing the ordinary, proxy, queued-follow-up, and early-failure persistence paths. The underlying gap remains on current main: gateway/run.py:16656 forwards only event_message_id, gateway/session.py:3085 persists only the platform message ID, and the canonical messages schema at hermes_state_common.py:192 has no structured platform-metadata column.

Problems

  • hermes_state.py:7196 carries replacement metadata in a map keyed only by platform_message_id. Because the proposed metadata contains platform and chat scope, duplicate IDs from different scopes can overwrite one another during replace_messages() and restore the wrong reply target.

Suggested changes

  • Preserve by a scoped identity such as (platform, chat_id, message_id) rather than message ID alone.
  • Salvage against the current state-schema, portability, and TurnContext seams; GitHub currently reports this branch conflicting and 865 commits behind main.

This is an automated hermes-sweeper review.

Comment thread hermes_state.py
# Transcript rewrites built from that replay shape must not erase
# durable reply-correlation metadata. Carry it forward by stable
# platform id without mutating the caller's message dictionaries.
existing_platform_metadata: Dict[str, Dict[str, str]] = {}

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.

This carry-forward map is keyed only by platform_message_id, although the metadata is explicitly platform/chat scoped. A duplicate ID from another chat or platform can overwrite this entry and restore the wrong reply correlation during replace_messages(); please use a scoped key or retain row-specific metadata.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants