← Back to Pull requests

fix(agent-mesh): decay trust for agents without a positive signal #4297

Closed
unknown closed this pull request without merging on Oct 13, 2026 08:57 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 07:50 UTC
Author

Related Issue


None. This is a bug I found in agentmesh.reward.trust_decay.NetworkTrustEngine; the sections below are filled in as the template asks.

Problem & Solution


Problem. Spec §12.1 (docs/specs/AGENTMESH-IDENTITY-TRUST-1.0.md) says trust scores MUST decay over time when no positive signals are received. apply_temporal_decay() measures idle time from the later of the last positive signal and the last decay pass. For an agent that never had a positive signal it uses self._last_positive.get(agent_did, now), so the start time is always the current pass, hours_since is 0, and _last_decay is never written. On main, an agent whose score came only from set_score() or process_trust_event() never decays, however long the timer runs:

engine = NetworkTrustEngine(decay_rate=10.0)
engine.set_score("a", 800.0)
t0 = time.time()
engine.apply_temporal_decay(now=t0)
engine.apply_temporal_decay(now=t0 + 3600)
engine.apply_temporal_decay(now=t0 + 30 * 86400)
engine.get_score("a")   # 800.0 on main; expected 790.0 after the first hour

Agents with no positive signal are the ones decay is meant for, but they are exempt. An agent that has had one positive signal does decay.

Solution. When decay sees an agent with neither a positive signal nor a previous decay pass, it records that pass as _last_decay and skips it. Later passes measure from there, using the same max(last positive, last decay) logic added in #4161. So:

  • a newly seen agent still gets no decay on its first pass (test_no_decay_for_newly_registered_agent is unchanged and passes);

  • from then on it decays at decay_rate per hour, down to the existing floor of 100;

  • a later positive signal moves the clock forward as before.
  • Agents that already have a positive signal behave exactly as before.

    Impact on Your Work


    An agent that misbehaves and never earns a positive signal keeps its score indefinitely, while a well-behaved agent that earned one bonus decays. Scores of idle, unproven agents never move toward the revocation and warning thresholds the decay is supposed to push them to.

    Timeline


    None.

    Alternatives Considered


  • Start the clock in set_score() / when the score is first created. That would measure from the agent's real first appearance, but set_score() runs on every score change, and the existing tests set _last_positive after set_score() with explicit now values, which a wall-clock timestamp written in set_score() would override. Starting at the first decay pass keeps the change inside apply_temporal_decay(), the only place that reads these timestamps.

  • Default the missing positive signal to -inf only. That would charge an unbounded number of hours on the first pass and send every new agent straight to the floor.
  • Type of Change


  • Bug fix (non-breaking change that fixes an issue)
  • Package(s) Affected


  • agent-mesh
  • Testing


    Unit Testing


    tests/test_trust_decay.py::TestDecayOverTime:
  • test_agent_without_positive_signal_decays_after_first_pass: no decay on the first pass, then 790 after one hour and 780 after two.

  • test_agent_hit_by_trust_event_decays_without_positive_signal: a score created only by process_trust_event() (490) decays to 460 three hours after the first pass.

  • test_positive_signal_after_first_pass_restarts_the_clock: a positive signal after the first pass is still what decay measures from.
  • The first two fail on main and pass here. The third passes on both and guards the interaction with positive signals.

    Manual Testing


  • tests/test_trust_decay.py and tests/test_spec_identity_trust_conformance.py: 195 passed.

  • agent-mesh full suite: 4368 passed, 153 skipped, 3 failed. The 3 failures are unrelated and also fail on main on my machine (Windows): test_renewed_credential_extends_expiry, test_handshake_with_freshness_bypasses_cache, test_auto_release_after_duration.

  • ruff check reports the same 38 pre-existing findings (typing-style UP rules and an import-order finding in the test) on main and on this branch, none on the changed lines.
  • Checklist


  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest)

  • I have updated documentation as needed (CHANGELOG)

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • AI Assistance


  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • I used Claude Code (Claude Opus) to help find the bug and draft the fix and tests. I reviewed the full diff and will handle review comments myself.

    IP, Patents, and Licensing


  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MohammadHaroonAbuomar Review duration: 67m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4297"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%