hermes - ✅(Solved) Fix Persist model/provider/context window metadata in gateway sessions [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#14321Fetched 2026-04-23 07:45:38
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Gateway session metadata no longer persists the active model, provider, or context window to sessions.json, even though external dashboards and session consumers still rely on that envelope metadata.

Today Hermes only updates last_prompt_tokens in SessionStore.update_session(). The final run_agent result also omits context_length, so the gateway cannot persist the full runtime envelope.

Root Cause

Without these fields, external session consumers cannot tell:

  • which model handled the session
  • which provider handled it
  • what the session context window was

That makes context-usage dashboards inaccurate or useless.

Fix Action

Fix / Workaround

Local verification

A local patch implementing this behavior now passes targeted gateway session tests.

PR fix notes

PR #14454: fix(gateway): persist runtime session metadata

Description (problem / solution / changelog)

Fixes #14321.

Root cause

The gateway only persisted last_prompt_tokens back into sessions.json after a run. SessionEntry had no fields for the active runtime envelope, SessionStore.update_session() only updated prompt tokens, and the final run_agent result did not expose the active context_length.

What changed

  • added model, model_provider, and context_tokens to gateway.session.SessionEntry
  • serialized/deserialized those fields in sessions.json
  • extended SessionStore.update_session() to persist the runtime envelope alongside last_prompt_tokens
  • exposed context_length from run_agent.py final results
  • forwarded model, provider, and context_length through gateway/run.py
  • added regression coverage for session-entry roundtrips, update semantics, and gateway persistence wiring

Tests

  • python -m pytest tests/gateway/test_session.py tests/gateway/test_status_command.py -q --tb=short
  • python -m pytest tests/gateway/test_session_info.py tests/gateway/test_session_hygiene.py -q --tb=short
  • git diff --check

Changed files

  • gateway/run.py (modified, +15/-2)
  • gateway/session.py (modified, +18/-0)
  • run_agent.py (modified, +1/-0)
  • tests/gateway/test_session.py (modified, +36/-7)
  • tests/gateway/test_status_command.py (modified, +5/-0)
RAW_BUFFERClick to expand / collapse

Summary

Gateway session metadata no longer persists the active model, provider, or context window to sessions.json, even though external dashboards and session consumers still rely on that envelope metadata.

Today Hermes only updates last_prompt_tokens in SessionStore.update_session(). The final run_agent result also omits context_length, so the gateway cannot persist the full runtime envelope.

Why this matters

Without these fields, external session consumers cannot tell:

  • which model handled the session
  • which provider handled it
  • what the session context window was

That makes context-usage dashboards inaccurate or useless.

Current behavior

  • gateway/session.py serializes token counters but not model, model_provider, or context_tokens
  • SessionStore.update_session() only updates last_prompt_tokens
  • run_agent.py final result includes model and provider, but not context_length
  • gateway/run.py only forwards last_prompt_tokens

Expected behavior

Persist these lightweight runtime metadata fields in the gateway session record:

  • model
  • model_provider
  • context_tokens (from the agent's active context_compressor.context_length)

Proposed fix

  • extend SessionEntry with model, model_provider, context_tokens
  • serialize / deserialize them in to_dict() and from_dict()
  • extend SessionStore.update_session() to accept and store them
  • expose context_length in the final run_agent result
  • forward model, provider, and context_length through gateway/run.py
  • add regression coverage in tests/gateway/test_session.py

Local verification

A local patch implementing this behavior now passes targeted gateway session tests.

extent analysis

TL;DR

Update the SessionEntry model to include model, model_provider, and context_tokens fields and modify the SessionStore.update_session() method to accept and store these fields.

Guidance

  • Extend the SessionEntry class to include the missing fields (model, model_provider, context_tokens) to store the required metadata.
  • Modify the to_dict() and from_dict() methods of SessionEntry to serialize and deserialize the new fields.
  • Update the SessionStore.update_session() method to accept the new fields and store them in the session record.
  • Expose the context_length in the final result of run_agent to allow the gateway to persist the full runtime envelope.

Example

class SessionEntry:
    def __init__(self, ...):
        self.model = None
        self.model_provider = None
        self.context_tokens = None

    def to_dict(self):
        return {
            ...,
            'model': self.model,
            'model_provider': self.model_provider,
            'context_tokens': self.context_tokens
        }

    def from_dict(self, data):
        ...,
        self.model = data['model']
        self.model_provider = data['model_provider']
        self.context_tokens = data['context_tokens']

Notes

The proposed fix seems to address the issue, but it's essential to ensure that the changes do not introduce any new bugs or compatibility issues. Thorough testing, including regression coverage, is necessary to verify the fix.

Recommendation

Apply the proposed workaround by extending the SessionEntry model and updating the SessionStore.update_session() method, as it directly addresses the issue and provides a clear solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Persist these lightweight runtime metadata fields in the gateway session record:

  • model
  • model_provider
  • context_tokens (from the agent's active context_compressor.context_length)

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING