Skip to content

feat: incremental wallet graph updates and shadow model deployment#360

Merged
Inkman007 merged 2 commits into
Ledger-Lenz:mainfrom
brite-side0:feature/incremental-graph-shadow-deployment-203-204
Jun 30, 2026
Merged

feat: incremental wallet graph updates and shadow model deployment#360
Inkman007 merged 2 commits into
Ledger-Lenz:mainfrom
brite-side0:feature/incremental-graph-shadow-deployment-203-204

Conversation

@brite-side0

Copy link
Copy Markdown
Contributor

Summary

  • Implement Incremental Graph Update Mechanism for Real-Time Node and Edge Additions to Wallet Graph #203 — Incremental Graph Update Mechanism: Adds IncrementalWalletGraph to detection/wallet_graph.py with add_trade_edge() (O(1) amortised), remove_stale_edges() (background staleness eviction via GRAPH_STALE_EDGE_MAX_AGE_HOURS), and get_ego_subgraph() (BFS-based 2-hop extraction, < 10 ms for 500 direct neighbours). Prometheus gauges exposed for nodes, edges, and stale edges. WalletGraphCache singleton added to detection/feature_cache.py. Docs section added to gnn_architecture.md.
  • Implement Concept Drift-Aware Model Versioning with Automatic Rollback #204 — Concept Drift-Aware Model Versioning with Automatic Rollback: Adds ShadowScorer to detection/model_inference.py routing SHADOW_TRAFFIC_PERCENT (default 20%) of requests through the candidate model and counting drift events. ModelVersionRecord ORM model added to detection/persistence.py. scripts/retrain_if_drifted.py extended with shadow deployment flow (exit 4), --check-shadow evaluation flag, auto-promotion when drift rate < 5%, auto-rollback when candidate FP rate regresses by > 10%, and signature verification before rollback. Runbook added at docs/model_rollback_runbook.md.

Test plan

  • IncrementalWalletGraph.add_trade_edge() adds edges; get_ego_subgraph() returns correct 2-hop neighbourhood
  • remove_stale_edges() removes only edges older than the configured threshold; isolated nodes pruned
  • Prometheus gauges increment/decrement correctly with graph mutations
  • WalletGraphCache.instance() is a true singleton across threads
  • ShadowScorer.score() always returns the production result; drift events counted when diff > 15 pts
  • ShadowScorer.should_promote() blocks before shadow period elapses and when drift rate ≥ 5%
  • retrain_if_drifted --check-shadow promotes when drift rate < 5%, rolls back when FP regression > 10%
  • verify_model_artifact_signature() returns False on tampered artifacts
  • ModelVersionRecord rows persist status transitions to DB

Closes #203
Closes #204

🤖 Generated with Claude Code

…edger-Lenz#203, Ledger-Lenz#204)

Issue Ledger-Lenz#203 — Incremental Graph Update Mechanism:
- Add IncrementalWalletGraph to detection/wallet_graph.py with add_trade_edge()
  (O(1) amortised), remove_stale_edges() (background staleness eviction), and
  get_ego_subgraph() (BFS-based 2-hop neighbourhood extraction < 10 ms for
  500 direct neighbours).
- Expose wallet_graph_nodes_total, wallet_graph_edges_total, and
  wallet_graph_stale_edges_total Prometheus gauges.
- Add WalletGraphCache singleton to detection/feature_cache.py wrapping the
  incremental graph for use by the streaming scorer and feature pipeline.
- Add GRAPH_STALE_EDGE_MAX_AGE_HOURS (168 h default) to config.py.
- Add FEATURE_CACHE_TTL_SECONDS and FEATURE_CACHE_MAXSIZE to config.py.
- Document incremental update strategy and staleness policy in docs/gnn_architecture.md.

Issue Ledger-Lenz#204 — Concept Drift-Aware Model Versioning with Automatic Rollback:
- Add ShadowScorer to detection/model_inference.py: routes SHADOW_TRAFFIC_PERCENT
  (default 20%) of live requests through the candidate model, counts disagreements
  > SHADOW_DRIFT_THRESHOLD_POINTS (15 pts) as drift events.
- Add verify_model_artifact_signature() helper for Ed25519 chain verification
  before rollback.
- Add ModelVersionRecord ORM model to detection/persistence.py tracking
  shadow/promoted/rolled_back status, drift rate, and training metadata.
- Extend scripts/retrain_if_drifted.py: after drift detection, register the new
  model as a shadow candidate (exit 4) instead of promoting unconditionally; add
  --check-shadow flag for evaluation after the shadow period; auto-promote when
  drift rate < SHADOW_DRIFT_MAX_RATE (5%); auto-rollback when candidate FP rate
  exceeds production by > SHADOW_FP_RATE_MAX_EXCESS (10%); --no-shadow flag
  preserves legacy immediate-promotion behaviour.
- Add docs/model_rollback_runbook.md with step-by-step manual intervention guide.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@brite-side0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Inkman007 Inkman007 merged commit 70b3cb8 into Ledger-Lenz:main Jun 30, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants