lex-synapse 0.4.9 → 0.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/CLAUDE.md +54 -40
- data/README.md +18 -33
- data/lib/legion/extensions/synapse/runners/pain.rb +2 -1
- data/lib/legion/extensions/synapse/runners/propose.rb +5 -1
- data/lib/legion/extensions/synapse/runners/retrieve.rb +4 -1
- data/lib/legion/extensions/synapse/version.rb +1 -1
- data/lib/legion/extensions/synapse.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 712f9976e4ce62962405f83fd39b3bd2dfa2ea678bed7f183a246b80506f6623
|
|
4
|
+
data.tar.gz: 73c470450fd5d6800054c81441bc48bd603e12e161cc0e963a4306853de5fa5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6356f7f31a55ac536e5d7d3d2aa2923bae4e723c1f4f3be68adf83027d8916020d19a44d363e199af015c825c5ccf0eeeeee0126e33396623e95b4af5b1cf7eb
|
|
7
|
+
data.tar.gz: 0677dfdaa1c422b1db309036c2872d8b22473e376050a259ca16e8733d91cbfa720a18291b46c9119d28f6430b0d889cd5ab09ba83217fcca8dad3fcaa1f9b46
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.11] - 2026-04-22
|
|
4
|
+
### Fixed
|
|
5
|
+
- `handle_pain` now actually calls `revert` when consecutive failures reach threshold (was only setting a flag)
|
|
6
|
+
- `analyze_routing` stub now logs warning instead of silently returning nil
|
|
7
|
+
- Silent rescue blocks in `retrieve#parse_pattern` and `propose#call_llm` now log errors
|
|
8
|
+
|
|
9
|
+
## [0.4.10] - 2026-04-15
|
|
10
|
+
### Changed
|
|
11
|
+
- Set `mcp_tools?` and `mcp_tools_deferred?` to `false` — internal infrastructure extension, not an LLM-callable tool
|
|
12
|
+
|
|
3
13
|
## [0.4.9] - 2026-04-06
|
|
4
14
|
|
|
5
15
|
### Fixed
|
data/CLAUDE.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# lex-synapse: Cognitive Routing Layer for LegionIO
|
|
2
2
|
|
|
3
3
|
**Repository Level 3 Documentation**
|
|
4
|
-
- **Parent**:
|
|
5
|
-
- **Grandparent**:
|
|
4
|
+
- **Parent**: `../CLAUDE.md`
|
|
5
|
+
- **Grandparent**: `../../CLAUDE.md`
|
|
6
6
|
|
|
7
7
|
## Purpose
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ Cognitive routing layer that wraps task chain relationships with observation, le
|
|
|
10
10
|
|
|
11
11
|
**GitHub**: https://github.com/LegionIO/lex-synapse
|
|
12
12
|
**License**: MIT
|
|
13
|
-
**Version**: 0.4.
|
|
13
|
+
**Version**: 0.4.11
|
|
14
14
|
|
|
15
15
|
## Architecture
|
|
16
16
|
|
|
@@ -22,19 +22,19 @@ Legion::Extensions::Synapse
|
|
|
22
22
|
│ ├── Crystallize # Every 300s — emergent synapse detection
|
|
23
23
|
│ ├── Homeostasis # Every 30s — spike/drought monitoring
|
|
24
24
|
│ ├── Decay # Every 3600s — idle confidence decay
|
|
25
|
-
│ ├── Propose
|
|
26
|
-
│ └── Challenge
|
|
25
|
+
│ ├── Propose # Every 300s — proactive proposal analysis for AUTONOMOUS synapses
|
|
26
|
+
│ └── Challenge # Every 60s — adversarial challenge pipeline for pending proposals
|
|
27
27
|
├── Runners/
|
|
28
|
-
│ ├── Evaluate # attention -> transform -> route -> record
|
|
29
|
-
│ ├── Pain # failure recording, confidence hit, auto-revert
|
|
28
|
+
│ ├── Evaluate # attention -> transform -> route -> record -> propose (if AUTONOMOUS)
|
|
29
|
+
│ ├── Pain # failure recording, confidence hit, auto-revert (calls revert!), dampen
|
|
30
30
|
│ ├── Crystallize # unrouted traffic analysis, emergent creation
|
|
31
|
-
│ ├── Mutate # versioned self-modification with snapshots
|
|
32
|
-
│ ├── Revert # rollback to previous mutation version
|
|
31
|
+
│ ├── Mutate # versioned self-modification with before/after snapshots
|
|
32
|
+
│ ├── Revert # rollback to previous mutation version (restores before_state)
|
|
33
33
|
│ ├── Report # aggregate stats for GAIA consumption
|
|
34
|
-
│ ├── Dream # replay historical signals in simulation mode
|
|
34
|
+
│ ├── Dream # replay historical signals in simulation mode
|
|
35
35
|
│ ├── GaiaReport # GAIA tick hook: report confidence and health per synapse
|
|
36
|
-
│ ├── Promote # Apollo integration: promote high-confidence synapse patterns
|
|
37
|
-
│ ├── Retrieve # Apollo integration: retrieve relevant synapse patterns
|
|
36
|
+
│ ├── Promote # Apollo integration: promote high-confidence synapse patterns
|
|
37
|
+
│ ├── Retrieve # Apollo integration: retrieve relevant synapse patterns
|
|
38
38
|
│ ├── Propose # reactive (signal-driven) + proactive (periodic) proposal generation
|
|
39
39
|
│ └── Challenge # conflict detection, LLM challenge, weighted aggregation, outcome resolution
|
|
40
40
|
├── Helpers/
|
|
@@ -43,7 +43,7 @@ Legion::Extensions::Synapse
|
|
|
43
43
|
│ ├── RelationshipWrapper # Layer 1 -> Layer 2 wrapping
|
|
44
44
|
│ └── Challenge # settings, constants, impact threshold helpers
|
|
45
45
|
├── Data/
|
|
46
|
-
│ ├── Migrations/ # 001 synapses, 002 mutations, 003 signals, 004 proposals, 005 challenges
|
|
46
|
+
│ ├── Migrations/ # 001 synapses, 002 mutations, 003 signals, 004 proposals, 005 challenges, 006 slow_query_indexes, 007 blast_radius
|
|
47
47
|
│ └── Models/ # Synapse, SynapseMutation, SynapseSignal, SynapseProposal, SynapseChallenge
|
|
48
48
|
├── Transport/
|
|
49
49
|
│ ├── Exchanges/Synapse
|
|
@@ -52,6 +52,24 @@ Legion::Extensions::Synapse
|
|
|
52
52
|
└── Client # Standalone client including all runners
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Runner Methods (Public API)
|
|
56
|
+
|
|
57
|
+
| Runner | Method | Signature |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| Evaluate | `evaluate` | `evaluate(synapse_id:, payload: {}, conditioner_client: nil, transformer_client: nil)` |
|
|
60
|
+
| Pain | `handle_pain` | `handle_pain(synapse_id:, task_id: nil)` — records failure, adjusts confidence, calls `revert` on 3+ consecutive failures |
|
|
61
|
+
| Crystallize | `crystallize` | `crystallize(signal_pairs:, threshold: 20)` |
|
|
62
|
+
| Mutate | `mutate` | `mutate(synapse_id:, mutation_type:, changes:, trigger:)` |
|
|
63
|
+
| Revert | `revert` | `revert(synapse_id:, to_version: nil, trigger: 'pain')` — restores `before_state` from mutation record; records revert as new mutation |
|
|
64
|
+
| Report | `report` | `report(synapse_id:)` |
|
|
65
|
+
| Dream | `dream` | `dream(synapse_id:, limit:)` |
|
|
66
|
+
| GaiaReport | `gaia_report` | Called during GAIA tick cycle |
|
|
67
|
+
| Promote | `promote` | `promote(synapse_id:)` |
|
|
68
|
+
| Retrieve | `retrieve` | `retrieve(...)` |
|
|
69
|
+
| Propose | `propose`, `proposals`, `review_proposal` | `propose(synapse_id:, ...)` / `proposals(synapse_id:, status:)` / `review_proposal(proposal_id:, status:)` |
|
|
70
|
+
| Challenge | `challenge_proposal`, `challenges`, `challenger_stats` | `challenge_proposal(proposal_id:)` / `challenges(proposal_id:)` / `challenger_stats` |
|
|
71
|
+
| Blast Radius | `analyze_routing` | `analyze_routing(synapse_id:)` — logs blast radius analysis result |
|
|
72
|
+
|
|
55
73
|
## Key Thresholds
|
|
56
74
|
|
|
57
75
|
| Parameter | Value |
|
|
@@ -76,44 +94,34 @@ Legion::Extensions::Synapse
|
|
|
76
94
|
| 0.0-0.3 | OBSERVE | Log, pass through unchanged |
|
|
77
95
|
| 0.3-0.6 | FILTER | Suppress signals |
|
|
78
96
|
| 0.6-0.8 | TRANSFORM | Filter + transform within schemas |
|
|
79
|
-
| 0.8-1.0 | AUTONOMOUS | Self-modify rules, infer transforms |
|
|
97
|
+
| 0.8-1.0 | AUTONOMOUS | Self-modify rules via proposals, infer transforms |
|
|
98
|
+
|
|
99
|
+
## Pain Auto-Revert
|
|
100
|
+
|
|
101
|
+
`Runners::Pain#handle_pain` calls `revert(synapse_id:, trigger: 'pain')` directly when `consecutive_failures >= 3`. The revert finds the latest mutation record for the synapse's current version, restores `before_state` (attention, transform, routing_strategy, confidence, status), decrements version, marks the mutation outcome as `'reverted'`, and creates a new mutation record with `outcome: 'reverted'`.
|
|
80
102
|
|
|
81
103
|
## Data Model
|
|
82
104
|
|
|
83
|
-
- **synapses**: Core routing definition with confidence, status, version, baseline_throughput
|
|
84
|
-
- **synapse_mutations**: Versioned change history with before/after JSON snapshots
|
|
85
|
-
- **synapse_signals**: Per-signal outcome records (attention pass, transform success,
|
|
86
|
-
- **synapse_proposals**: Proposed changes with status lifecycle, challenge_state, challenge_score, impact_score
|
|
105
|
+
- **synapses**: Core routing definition with confidence, status, version, baseline_throughput, blast_radius
|
|
106
|
+
- **synapse_mutations**: Versioned change history with before/after JSON snapshots, trigger, outcome
|
|
107
|
+
- **synapse_signals**: Per-signal outcome records (attention pass, transform success, latency_ms, downstream outcome)
|
|
108
|
+
- **synapse_proposals**: Proposed changes with status lifecycle (pending → approved/rejected/applied/expired/auto_accepted/auto_rejected), challenge_state, challenge_score, impact_score
|
|
87
109
|
- **synapse_challenges**: Per-challenge verdicts (conflict/LLM), confidence tracking, outcome resolution
|
|
88
110
|
|
|
89
111
|
## Autonomous Observation Mode (v0.3.0)
|
|
90
112
|
|
|
91
|
-
-
|
|
92
|
-
- **Reactive proposals**: on signal evaluation — no-template inference, transform failure fix, attention pain correlation
|
|
93
|
-
- **Proactive proposals**: periodic analysis — success rate degradation, payload drift detection
|
|
94
|
-
- **LLM-backed**: proposals call lex-transformer LLM engine for real output generation
|
|
95
|
-
- **Settings**: `lex-synapse.proposals.*` — enabled, reactive, proactive, max_per_run, llm_engine_options, thresholds
|
|
96
|
-
- **Data**: `synapse_proposals` table with status lifecycle (pending -> approved/rejected/applied/expired)
|
|
97
|
-
- **Client methods**: `proposals(synapse_id:, status:)`, `review_proposal(proposal_id:, status:)`
|
|
113
|
+
AUTONOMOUS-tier synapses (confidence >= 0.8) generate proposals instead of executing autonomous actions. Proposals are reactive (triggered on signal evaluation in `Runners::Evaluate`) or proactive (generated periodically by `Actors::Propose`). Settings: `lex-synapse.proposals.*` (enabled, reactive, proactive, max_per_run, llm_engine_options, thresholds).
|
|
98
114
|
|
|
99
115
|
## Adversarial Challenge Phase (v0.4.0)
|
|
100
116
|
|
|
101
|
-
|
|
102
|
-
- **Conflict detection**: queries sibling pending proposals on same synapse; conflicting types produce 'challenge' verdict
|
|
103
|
-
- **LLM challenge**: gated by `impact_score >= 0.3`; calls lex-transformer LLM engine; parses SUPPORT/CHALLENGE/ABSTAIN
|
|
104
|
-
- **Aggregation**: `support_weight / (support_weight + challenge_weight)`, abstains excluded; >= 0.85 auto-accepts, <= 0.15 auto-rejects
|
|
105
|
-
- **Challenger confidence**: starting 0.5, correct +0.05, incorrect -0.08, decay *0.998/hr; tracks via outcome resolution after observation window (50 signals post-application)
|
|
106
|
-
- **Settings**: `lex-synapse.challenge.*` — enabled, impact_threshold, auto_accept_threshold, auto_reject_threshold, llm_engine_options, outcome_observation_window, max_per_cycle
|
|
107
|
-
- **Data**: `synapse_challenges` table; `synapse_proposals` gains challenge_state, challenge_score, impact_score columns
|
|
108
|
-
- **Statuses**: `auto_accepted`, `auto_rejected` added to proposal lifecycle
|
|
109
|
-
- **Client methods**: `challenge_proposal(proposal_id:)`, `challenges(proposal_id:)`, `challenger_stats`
|
|
117
|
+
Pending proposals pass through: conflict detection → impact scoring → LLM challenge (gated by `impact_score >= 0.3`) → weighted aggregation → auto-accept/reject. Aggregation: `support_weight / (support_weight + challenge_weight)`, >= 0.85 auto-accepts, <= 0.15 auto-rejects. Settings: `lex-synapse.challenge.*`.
|
|
110
118
|
|
|
111
119
|
## GAIA / Apollo Integration (v0.2.2)
|
|
112
120
|
|
|
113
|
-
- **GaiaReport
|
|
114
|
-
- **Dream
|
|
115
|
-
- **Promote
|
|
116
|
-
- **Retrieve
|
|
121
|
+
- **GaiaReport**: Called during GAIA tick to report per-synapse confidence and health metrics
|
|
122
|
+
- **Dream**: Replays historical signals in simulation without affecting live state
|
|
123
|
+
- **Promote**: Publishes high-confidence patterns to Apollo shared knowledge store
|
|
124
|
+
- **Retrieve**: Pulls relevant patterns from Apollo to seed new synapses or adjust confidence
|
|
117
125
|
|
|
118
126
|
## Dependencies
|
|
119
127
|
|
|
@@ -121,7 +129,13 @@ Legion::Extensions::Synapse
|
|
|
121
129
|
|-----|---------|
|
|
122
130
|
| `lex-conditioner` >= 0.3.0 | Attention evaluation (condition rules) |
|
|
123
131
|
| `lex-transformer` >= 0.3.0 | Payload transformation (template engines) |
|
|
124
|
-
| `legion-
|
|
132
|
+
| `legion-cache` >= 1.3.11 | Cache access |
|
|
133
|
+
| `legion-crypt` >= 1.4.9 | Encryption/Vault |
|
|
134
|
+
| `legion-data` >= 1.4.17 | Required — database persistence via Sequel |
|
|
135
|
+
| `legion-json` >= 1.2.1 | JSON serialization |
|
|
136
|
+
| `legion-logging` >= 1.3.2 | Logging |
|
|
137
|
+
| `legion-settings` >= 1.3.14 | Settings |
|
|
138
|
+
| `legion-transport` >= 1.3.9 | AMQP |
|
|
125
139
|
|
|
126
140
|
## Testing
|
|
127
141
|
|
|
@@ -131,7 +145,7 @@ bundle exec rspec # 412 specs, 0 failures
|
|
|
131
145
|
bundle exec rubocop # 0 offenses
|
|
132
146
|
```
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
Uses in-memory SQLite for model/runner tests.
|
|
135
149
|
|
|
136
150
|
---
|
|
137
151
|
|
data/README.md
CHANGED
|
@@ -70,7 +70,7 @@ Each synapse has a confidence score (0.0-1.0) that governs what it's allowed to
|
|
|
70
70
|
| 0.0-0.3 | OBSERVE | Log what it would do, pass through unchanged |
|
|
71
71
|
| 0.3-0.6 | FILTER | Can suppress signals, cannot modify |
|
|
72
72
|
| 0.6-0.8 | TRANSFORM | Can filter + transform within defined schemas |
|
|
73
|
-
| 0.8-1.0 | AUTONOMOUS |
|
|
73
|
+
| 0.8-1.0 | AUTONOMOUS | Generates proposals for self-modification |
|
|
74
74
|
|
|
75
75
|
**Starting scores**: explicit=0.7, emergent=0.3, seeded=0.5
|
|
76
76
|
|
|
@@ -82,7 +82,7 @@ Each synapse has a confidence score (0.0-1.0) that governs what it's allowed to
|
|
|
82
82
|
|
|
83
83
|
Downstream task failures propagate backward through the chain:
|
|
84
84
|
- Each failure reduces confidence by 0.05
|
|
85
|
-
- 3+ consecutive failures trigger auto-revert to last known-good state
|
|
85
|
+
- 3+ consecutive failures trigger auto-revert to last known-good state (calls `revert` directly)
|
|
86
86
|
- Extreme failure rates trigger dampening (homeostasis)
|
|
87
87
|
|
|
88
88
|
### Homeostasis
|
|
@@ -96,27 +96,27 @@ Downstream task failures propagate backward through the chain:
|
|
|
96
96
|
### Evaluate
|
|
97
97
|
`evaluate(synapse_id:, payload:, conditioner_client:, transformer_client:)`
|
|
98
98
|
|
|
99
|
-
Main signal flow: load synapse
|
|
99
|
+
Main signal flow: load synapse → check autonomy → run attention (conditioner) → run transform (transformer) → record signal → adjust confidence → generate proposals if AUTONOMOUS.
|
|
100
100
|
|
|
101
101
|
### Pain
|
|
102
102
|
`handle_pain(synapse_id:, task_id:)`
|
|
103
103
|
|
|
104
|
-
Downstream failure handler. Records failed signal, adjusts confidence,
|
|
104
|
+
Downstream failure handler. Records failed signal, adjusts confidence, calls `revert` on 3+ consecutive failures, may dampen synapse.
|
|
105
|
+
|
|
106
|
+
### Revert
|
|
107
|
+
`revert(synapse_id:, to_version:, trigger:)`
|
|
108
|
+
|
|
109
|
+
Rolls back to a previous mutation version, restoring `before_state`. Records the revert as a new mutation entry.
|
|
105
110
|
|
|
106
111
|
### Crystallize
|
|
107
112
|
`crystallize(signal_pairs:, threshold: 20)`
|
|
108
113
|
|
|
109
|
-
Bottom-up emergence.
|
|
114
|
+
Bottom-up emergence. Creates new synapses for source/target pairs exceeding the threshold.
|
|
110
115
|
|
|
111
116
|
### Mutate
|
|
112
117
|
`mutate(synapse_id:, mutation_type:, changes:, trigger:)`
|
|
113
118
|
|
|
114
|
-
Versioned self-modification. Records before/after state snapshots.
|
|
115
|
-
|
|
116
|
-
### Revert
|
|
117
|
-
`revert(synapse_id:, to_version:, trigger:)`
|
|
118
|
-
|
|
119
|
-
Rolls back to a previous mutation version, restoring the before_state.
|
|
119
|
+
Versioned self-modification. Records before/after state snapshots.
|
|
120
120
|
|
|
121
121
|
### Report
|
|
122
122
|
`report(synapse_id:)`
|
|
@@ -126,17 +126,10 @@ Aggregates stats: confidence, status, 24h signal count, success rate, last mutat
|
|
|
126
126
|
### Dream
|
|
127
127
|
`dream(synapse_id:, limit:)`
|
|
128
128
|
|
|
129
|
-
Replays historical signals in simulation mode without affecting live state.
|
|
130
|
-
|
|
131
|
-
### Propose
|
|
132
|
-
`propose(synapse_id:, ...)` / `proposals(synapse_id:, status:)` / `review_proposal(proposal_id:, status:)`
|
|
133
|
-
|
|
134
|
-
Generates proposed changes (reactive on signal evaluation, proactive on periodic analysis) for AUTONOMOUS-tier synapses. Proposals enter a status lifecycle: pending -> approved/rejected/applied/expired/auto_accepted/auto_rejected.
|
|
135
|
-
|
|
136
|
-
### Challenge
|
|
137
|
-
`challenge_proposal(proposal_id:)` / `challenges(proposal_id:)` / `challenger_stats`
|
|
129
|
+
Replays historical signals in simulation mode without affecting live state.
|
|
138
130
|
|
|
139
|
-
|
|
131
|
+
### Propose / Challenge
|
|
132
|
+
AUTONOMOUS-tier synapses generate proposals (reactive on evaluation, proactive periodically). Proposals are subjected to a multi-stage challenge pipeline: conflict detection → impact scoring → optional LLM challenge → weighted aggregation → auto-accept/reject.
|
|
140
133
|
|
|
141
134
|
## Relationship Wrapper
|
|
142
135
|
|
|
@@ -148,24 +141,16 @@ relationship = { id: 42, trigger_function_id: 1, function_id: 2,
|
|
|
148
141
|
synapse = Legion::Extensions::Synapse::Helpers::RelationshipWrapper.wrap(relationship)
|
|
149
142
|
```
|
|
150
143
|
|
|
144
|
+
## Data Model
|
|
145
|
+
|
|
146
|
+
Five tables: `synapses` (core routing + confidence + status + blast_radius), `synapse_mutations` (versioned history), `synapse_signals` (per-signal outcomes), `synapse_proposals` (proposal lifecycle), `synapse_challenges` (per-challenge verdicts).
|
|
147
|
+
|
|
151
148
|
## Transport
|
|
152
149
|
|
|
153
150
|
- **Exchange**: `synapse` (inherits from `Legion::Transport::Exchanges::Task`)
|
|
154
151
|
- **Queues**: `synapse.evaluate`, `synapse.pain`
|
|
155
152
|
- **Routing keys**: `synapse.evaluate`, `task.failed`
|
|
156
153
|
|
|
157
|
-
## Autonomous Observation Mode
|
|
158
|
-
|
|
159
|
-
AUTONOMOUS-tier synapses (confidence >= 0.8) generate proposals instead of directly executing changes. Proposals are reactive (triggered on signal evaluation) or proactive (generated periodically). The `lex-synapse.proposals.*` settings control enabled state, LLM engine options, and thresholds.
|
|
160
|
-
|
|
161
|
-
## Adversarial Challenge Phase
|
|
162
|
-
|
|
163
|
-
Pending proposals are subjected to a multi-stage challenge pipeline: conflict detection among sibling proposals, impact scoring, optional LLM challenge (for high-impact proposals), weighted aggregation across verdicts, and auto-accept/reject based on configurable thresholds. The `lex-synapse.challenge.*` settings control gating.
|
|
164
|
-
|
|
165
|
-
## Data Model
|
|
166
|
-
|
|
167
|
-
Five tables: `synapses` (core routing definition + confidence + status), `synapse_mutations` (versioned change history), `synapse_signals` (per-signal outcome records), `synapse_proposals` (proposal lifecycle), `synapse_challenges` (per-challenge verdicts).
|
|
168
|
-
|
|
169
154
|
## Dependencies
|
|
170
155
|
|
|
171
156
|
- `lex-conditioner` >= 0.3.0
|
|
@@ -38,7 +38,8 @@ module Legion
|
|
|
38
38
|
# Auto-revert on 3+ consecutive failures
|
|
39
39
|
if consecutive >= CONSECUTIVE_FAILURE_THRESHOLD
|
|
40
40
|
result[:action] = :auto_revert
|
|
41
|
-
|
|
41
|
+
revert_result = revert(synapse_id: synapse_id, trigger: 'pain')
|
|
42
|
+
result[:reverted] = revert_result[:success] == true
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
# Check if confidence dropped below autonomy threshold
|
|
@@ -11,6 +11,8 @@ module Legion
|
|
|
11
11
|
module Synapse
|
|
12
12
|
module Runners
|
|
13
13
|
module Propose
|
|
14
|
+
include Legion::Logging::Helper if defined?(Legion::Logging::Helper)
|
|
15
|
+
|
|
14
16
|
PAIN_CORRELATION_THRESHOLD = 3
|
|
15
17
|
|
|
16
18
|
def propose_reactive(synapse:, payload:, signal_id:, attention_result:, transform_result:,
|
|
@@ -165,6 +167,8 @@ module Legion
|
|
|
165
167
|
signals = Data::Model::SynapseSignal.where(synapse_id: synapse.id).order(Sequel.desc(:id)).limit(50).all
|
|
166
168
|
return nil if signals.size < 10
|
|
167
169
|
|
|
170
|
+
# TODO: implement routing analysis (e.g. detect latency patterns that suggest a better route)
|
|
171
|
+
log.warn("analyze_routing: no routing analysis implemented for synapse #{synapse.id}")
|
|
168
172
|
nil
|
|
169
173
|
end
|
|
170
174
|
|
|
@@ -210,7 +214,7 @@ module Legion
|
|
|
210
214
|
)
|
|
211
215
|
{ output: result[:success] ? Legion::JSON.dump(result[:result]) : nil }
|
|
212
216
|
rescue StandardError => e
|
|
213
|
-
log.
|
|
217
|
+
log.error("Proposal LLM call failed: #{e.message}")
|
|
214
218
|
{ output: nil }
|
|
215
219
|
end
|
|
216
220
|
|
|
@@ -8,6 +8,8 @@ module Legion
|
|
|
8
8
|
module Synapse
|
|
9
9
|
module Runners
|
|
10
10
|
module Retrieve
|
|
11
|
+
include Legion::Logging::Helper if defined?(Legion::Logging::Helper)
|
|
12
|
+
|
|
11
13
|
SEED_CONFIDENCE_THRESHOLD = 0.7
|
|
12
14
|
|
|
13
15
|
def retrieve_and_seed(knowledge_entries:, **)
|
|
@@ -45,7 +47,8 @@ module Legion
|
|
|
45
47
|
return nil unless content
|
|
46
48
|
|
|
47
49
|
content.is_a?(String) ? Legion::JSON.load(content) : content
|
|
48
|
-
rescue StandardError =>
|
|
50
|
+
rescue StandardError => e
|
|
51
|
+
log.error("parse_pattern failed: #{e.message}")
|
|
49
52
|
nil
|
|
50
53
|
end
|
|
51
54
|
|