← Back to Pull requests

fix(gateway): inherit the parent platform for a nested home_channel mapping #137929

Open
unknown opened this pull request with 576 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 13, 2026 17:14 UTC
Author

What does this PR do?

hermes config set platforms.<name>.home_channel.<field> <value> persists a partial mapping ({chat_id, name} with no platform key). HomeChannel.from_dict() indexed data["platform"] bare, so the KeyError escaped by_platform()'s except ValueError recovery and aborted the whole GatewayConfig.from_dict() — the write succeeded, everything kept working until the next restart, and then the gateway process died with KeyError: 'platform' (~1 s after boot; on a supervised host this burns the supervisor's restart budget).

The platform key is redundant for a home_channel nested under its own platform block — the parent key already says which platform it is. This PR passes the parent platform down and inherits it when the key is absent. A mapping that names neither source (or is missing chat_id) now raises a descriptive ValueError, which by_platform() already treats as recoverable: the malformed block is skipped instead of killing the load.

Related Issue

Fixes #137919

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • Changes Made

  • gateway/config.py — HomeChannel.from_dict(data, , default_platform=None): use an explicit platform when present, else inherit default_platform; raise a descriptive ValueError (not a bare KeyError) when neither exists or chat_id is missing.

  • gateway/config.py — PlatformConfig.from_dict(data, , platform=None): accepts the parent platform and hands it to HomeChannel.from_dict as default_platform.

  • gateway/config.py — by_platform(..., with_platform=True): resolves the Platform once and passes it to the parser; the platforms= call site opts in.

  • tests/gateway/test_config.py — new TestHomeChannelPartialMapping: inheritance from the parent block, explicit-platform precedence, ValueError on unresolvable shapes, and a boot-level check that an unresolvable home_channel skips the platform block instead of raising.
  • How to Test

    1. Repro on unpatched main (the exact YAML the two config set commands from the issue write): GatewayConfig.from_dict on platforms.telegram.home_channel = {chat_id: '123456789', name: Home}. Observed result: KeyError: 'platform' at HomeChannel.from_dict in gateway/config.py.
    2. Same input with this patch: Observed result: the config loads and platforms[TELEGRAM].home_channel is HomeChannel(platform=TELEGRAM, chat_id='123456789', name='Home') — platform inherited from the parent block.
    3. A healthy config (full home_channel with explicit platform) loads unchanged; the to_dict/from_dict round-trip is covered by the existing TestHomeChannelRoundtrip and still passes.
    4. pytest tests/gateway/test_config.py tests/gateway/test_config_env_bridge_authority.py tests/gateway/test_slash_config_writes_routed_profile.py -q → Observed result: 107 passed.

    Checklist

    Code

  • I've read the Contributing Guide

  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)

  • I searched for existing PRs to make sure this isn't a duplicate

  • My PR contains only changes related to this fix/feature (no unrelated commits)

  • I've run pytest tests/ -q and all tests pass

  • python scripts/check passes (the blocking lint and code-health checks CI runs)

  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)

  • I've tested on my platform: macOS 15 (arm64)
  • Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A

  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A

  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A

  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A

  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A
  • Screenshots / Logs

    Before (unpatched upstream/main):

    File ".../gateway/config.py", line 364, in from_dict
        return cls(platform=Platform(data["platform"]), ...)
    KeyError: 'platform'
    

    After (this patch):

    OK loaded: HomeChannel(platform=<Platform.TELEGRAM: 'telegram'>, chat_id='123456789', name='Home', thread_id=None, user_id=None, scope_id=None)
    

    Diff: 576 lines (+432 / -144) across 7 files Reviewer: PRATHAMESH75 Review duration: 73881m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.57) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 576 lines diff across 7 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #137929"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 56.8% (MEDIUM) · Higher = larger blast radius
    56.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.4% · Safe to merge
    31.4%