Skip to main content

lean_ctx/core/config/
retired.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Retired configuration keys (2026-10-16 settings audit).
3//!
4//! Each key here was accepted by the config but never applied, or lost its
5//! effect. An older `config.toml` that still sets one keeps loading (serde
6//! ignores unknown fields). The automatic config migration removes them from a
7//! writable global config (`Config::migrate_v4_config_document`), and
8//! `lean-ctx doctor` names them instead of calling them unknown.
9
10/// One retired key: its dotted path and what replaced it, if anything.
11pub struct RetiredKey {
12    pub path: &'static str,
13    pub note: &'static str,
14}
15
16const fn retired(path: &'static str, note: &'static str) -> RetiredKey {
17    RetiredKey { path, note }
18}
19
20const LEGACY_CLOUD_NOTE: &str =
21    "the hosted account and its sync left the engine; accounts live in LeanCTX";
22
23/// Removed configuration keys. A path names a key or a whole table.
24pub const RETIRED_KEYS: &[RetiredKey] = &[
25    retired(
26        "session_token_limit",
27        "never enforced; per-turn limits are `turn_fresh_limit`",
28    ),
29    retired(
30        "allow_auto_reroot",
31        "re-rooting from an unsuitable jail root is always on",
32    ),
33    retired("shadow.auto_record", "never read"),
34    retired(
35        "shadow.baseline_model",
36        "reports compare each task with the model its host chose",
37    ),
38    retired(
39        "agents.identity_ttl_hours",
40        "the reaper uses `presence_ttl_hours` and `logical_session_ttl_seconds`",
41    ),
42    retired(
43        "agents.max_concurrent_workers",
44        "registration never applied it",
45    ),
46    retired(
47        "agents.max_concurrent_mutating_workers",
48        "registration never applied it",
49    ),
50    retired("context.diet_max_config_tokens", "never read"),
51    retired("context.diet_relevance_threshold", "never read"),
52    retired("context.diet_rebalance_on_change", "never read"),
53    retired("context.diet_staleness_enabled", "never read"),
54    // The pre-3.12 `[cloud]` table (hosted account sync). `[cloud]` now holds
55    // the LeanCTX Cloud connector (renamed from `[cloud]`), so only the old
56    // table's own keys are retired, never the table.
57    retired("cloud.contribute_enabled", LEGACY_CLOUD_NOTE),
58    retired("cloud.last_contribute", LEGACY_CLOUD_NOTE),
59    retired("cloud.sync_stats_enabled", LEGACY_CLOUD_NOTE),
60    retired("cloud.last_sync", LEGACY_CLOUD_NOTE),
61    retired("cloud.sync_gain_enabled", LEGACY_CLOUD_NOTE),
62    retired("cloud.last_gain_sync", LEGACY_CLOUD_NOTE),
63    retired("cloud.sync_models_enabled", LEGACY_CLOUD_NOTE),
64    retired("cloud.last_model_pull", LEGACY_CLOUD_NOTE),
65    retired("cloud.auto_sync", LEGACY_CLOUD_NOTE),
66    retired("cloud.last_auto_sync", LEGACY_CLOUD_NOTE),
67    retired("cloud.auto_index", LEGACY_CLOUD_NOTE),
68    retired("cloud.last_index_push", LEGACY_CLOUD_NOTE),
69    retired("cloud.metrics_project_labels", LEGACY_CLOUD_NOTE),
70    retired("cloud.auto_publish", LEGACY_CLOUD_NOTE),
71    retired("cloud.auto_publish_interval_hours", LEGACY_CLOUD_NOTE),
72    retired("cloud.last_auto_publish", LEGACY_CLOUD_NOTE),
73    retired("cloud.leaderboard", LEGACY_CLOUD_NOTE),
74    retired("cloud.display_name", LEGACY_CLOUD_NOTE),
75    retired(
76        "cognitive_mode",
77        "the science features had no measured retrieval gain at +74 % read output",
78    ),
79    retired("code_health.coupling", "coupling is always computed"),
80    retired(
81        "graph.traversal_edges",
82        "learned co-access ranking changed no retrieval result",
83    ),
84    // Read-path autonomy drivers (A/B 2026-10-17): byte-identical responses
85    // and equal retrieval quality without them, 2-14 s more at session start.
86    retired(
87        "autonomy.auto_preload",
88        "the session-start preload changed no response",
89    ),
90    retired(
91        "autonomy.silent_preload",
92        "the import preload changed no response",
93    ),
94    retired(
95        "autonomy.auto_related",
96        "the related-file hint changed no response",
97    ),
98    retired(
99        "autonomy.auto_dedup",
100        "the automatic cache dedup changed no response",
101    ),
102    retired(
103        "autonomy.dedup_threshold",
104        "the automatic cache dedup changed no response",
105    ),
106    // Profile-only `[autonomy]` keys of the same drivers.
107    retired(
108        "autonomy.auto_prefetch",
109        "the post-read prefetch changed no response",
110    ),
111    retired(
112        "autonomy.prefetch_max_files",
113        "the post-read prefetch changed no response",
114    ),
115    retired(
116        "autonomy.prefetch_budget_tokens",
117        "the post-read prefetch changed no response",
118    ),
119    retired("boundary_policy.audit_cross_access", "never read"),
120    retired(
121        "gateway_server.admin_bind_host",
122        "the admin listener left the engine",
123    ),
124    retired(
125        "gateway_server.usage_retention_days",
126        "the admin listener left the engine",
127    ),
128    retired("solution.commercial", "never read"),
129    retired("team_url", "the team savings roll-up left the engine"),
130    retired("team_token", "the team savings roll-up left the engine"),
131    retired("team_auto_push", "the team savings roll-up left the engine"),
132    retired(
133        "gain",
134        "hosted card publication and public rankings left the engine",
135    ),
136    retired("response_shaping.preamble", "`mode` selects the patterns"),
137    retired(
138        "response_shaping.code_repetition",
139        "`mode` selects the patterns",
140    ),
141    retired("response_shaping.narration", "`mode` selects the patterns"),
142    retired(
143        "response_shaping.confirmation",
144        "`mode` selects the patterns",
145    ),
146    retired(
147        "proxy.reasoning_budget",
148        "reasoning effort is the host's choice or `proxy.effort`",
149    ),
150    retired(
151        "proxy.pipeline.enable_effort",
152        "reasoning effort is the host's choice or `proxy.effort`",
153    ),
154    retired(
155        "conversation.summarize_score_range",
156        "summaries cover the scores between `drop_score_below` and `min_score_to_preserve`",
157    ),
158    retired(
159        "conversation.ccr_store_dropped",
160        "dropped messages never had a recoverable copy",
161    ),
162    retired(
163        "cache.l1_max_entries",
164        "the process tier is bounded by `l1_ttl_secs`",
165    ),
166    retired(
167        "cache.l3_gc_threshold",
168        "the disk tier is bounded by `l3_max_bytes`",
169    ),
170    retired("memory.gotcha.retrieval_budget_per_room", "never applied"),
171    retired(
172        "memory.gotcha.default_decay_rate",
173        "decay follows each gotcha's provenance",
174    ),
175    retired(
176        "memory.gotcha.category_decay_overrides",
177        "decay follows each gotcha's provenance",
178    ),
179    retired("memory.gotcha.auto_expire_days", "never applied"),
180];
181
182/// Moved table: `[ocla.delivery.cache]` settings now live in `[cache]`.
183const MOVED_CACHE_FROM: [&str; 3] = ["ocla", "delivery", "cache"];
184
185/// The retired key that `path` (dotted) is, or lies under.
186#[must_use]
187pub fn retired_key(path: &str) -> Option<&'static RetiredKey> {
188    if path.split('.').take(3).eq(MOVED_CACHE_FROM) {
189        return Some(&MOVED_CACHE);
190    }
191    RETIRED_KEYS.iter().find(|key| {
192        path == key.path
193            || path
194                .strip_prefix(key.path)
195                .is_some_and(|rest| rest.starts_with('.'))
196    })
197}
198
199static MOVED_CACHE: RetiredKey = retired("ocla.delivery.cache", "moved to `[cache]`");
200
201/// Removes retired keys from a config document (root and every
202/// `[profiles.<name>]` overlay) and moves `[ocla.delivery.cache]` into
203/// `[cache]` without overriding a value already set there. Returns `None`
204/// when nothing changed; the comments and formatting of every other key are
205/// kept (a comment directly above a removed key goes with it).
206pub(super) fn migrate_retired_document(raw: &str) -> Result<Option<String>, String> {
207    let mut document = raw
208        .parse::<toml_edit::DocumentMut>()
209        .map_err(|error| error.to_string())?;
210    let mut changed = migrate_table(document.as_table_mut());
211    if let Some(profiles) = document
212        .get_mut("profiles")
213        .and_then(toml_edit::Item::as_table_like_mut)
214    {
215        for (_, profile) in profiles.iter_mut() {
216            if let Some(table) = profile.as_table_mut() {
217                changed |= migrate_table(table);
218            }
219        }
220    }
221    Ok(changed.then(|| document.to_string()))
222}
223
224fn migrate_table(root: &mut toml_edit::Table) -> bool {
225    let mut changed = move_delivery_cache(root);
226    changed |= super::renamed::migrate_table(root);
227    for key in RETIRED_KEYS {
228        let segments: Vec<&str> = key.path.split('.').collect();
229        changed |= remove_path(root, &segments);
230    }
231    changed
232}
233
234fn move_delivery_cache(root: &mut toml_edit::Table) -> bool {
235    let [ocla, delivery, cache] = MOVED_CACHE_FROM;
236    let Some(moved) = root
237        .get_mut(ocla)
238        .and_then(toml_edit::Item::as_table_like_mut)
239        .and_then(|table| table.get_mut(delivery))
240        .and_then(toml_edit::Item::as_table_like_mut)
241        .and_then(|table| table.remove(cache))
242    else {
243        return false;
244    };
245    if let Some(values) = moved.as_table_like() {
246        let target = root
247            .entry(cache)
248            .or_insert_with(toml_edit::table)
249            .as_table_like_mut();
250        if let Some(target) = target {
251            for (name, value) in values.iter() {
252                if target.get(name).is_none() {
253                    target.insert(name, value.clone());
254                }
255            }
256        }
257    }
258    prune_empty(root, &[ocla, delivery]);
259    true
260}
261
262/// Removes `segments` under `table`; drops tables the removal left empty.
263fn remove_path(table: &mut dyn toml_edit::TableLike, segments: &[&str]) -> bool {
264    match segments {
265        [] => false,
266        [leaf] => table.remove(leaf).is_some(),
267        [head, rest @ ..] => {
268            let Some(child) = table
269                .get_mut(head)
270                .and_then(toml_edit::Item::as_table_like_mut)
271            else {
272                return false;
273            };
274            let removed = remove_path(child, rest);
275            if removed && child.is_empty() {
276                table.remove(head);
277            }
278            removed
279        }
280    }
281}
282
283fn prune_empty(table: &mut dyn toml_edit::TableLike, segments: &[&str]) {
284    let Some((head, rest)) = segments.split_first() else {
285        return;
286    };
287    let Some(child) = table
288        .get_mut(head)
289        .and_then(toml_edit::Item::as_table_like_mut)
290    else {
291        return;
292    };
293    prune_empty(child, rest);
294    if child.is_empty() {
295        table.remove(head);
296    }
297}
298
299#[cfg(test)]
300mod tests {
301    use super::*;
302
303    #[test]
304    fn retired_keys_are_removed_and_the_delivery_cache_moves_to_cache() {
305        let raw = r#"session_token_limit = 1
306# my settings
307ultra_compact_note = "kept"
308
309[shadow]
310enabled = true
311auto_record = false
312baseline_model = "gpt-4o"
313
314[cache]
315l2_ttl_secs = 60
316
317[ocla.delivery]
318max_entries = 7
319
320[ocla.delivery.cache]
321l2_ttl_secs = 900
322l2_max_entries = 50
323l1_max_entries = 3
324
325[solution.commercial]
326fingerprints_enabled = true
327
328[solution.commercial.adaptive]
329enabled = true
330
331[memory.gotcha]
332max_gotchas_per_project = 40
333default_decay_rate = 0.1
334
335[memory.gotcha.category_decay_overrides]
336security = 0.005
337
338[profiles.ci.conversation]
339ccr_store_dropped = false
340"#;
341        let migrated = migrate_retired_document(raw)
342            .expect("parses")
343            .expect("changes");
344        let config: crate::core::config::Config =
345            toml::from_str(&migrated).expect("migrated config loads");
346
347        assert!(migrated.starts_with("# my settings"), "{migrated}");
348        assert!(migrated.contains("ultra_compact_note"));
349        for gone in [
350            "session_token_limit",
351            "auto_record",
352            "baseline_model",
353            "l1_max_entries",
354            "commercial",
355            "default_decay_rate",
356            "category_decay_overrides",
357            "ccr_store_dropped",
358            "[ocla.delivery.cache]",
359        ] {
360            assert!(!migrated.contains(gone), "{gone} survived:\n{migrated}");
361        }
362        assert!(config.shadow.enabled);
363        assert_eq!(config.ocla.delivery.max_entries, 7);
364        // A value already set in `[cache]` wins over the moved copy.
365        assert_eq!(config.cache.l2_ttl_secs, 60);
366        assert_eq!(config.cache.l2_max_entries, 50);
367        assert_eq!(config.memory.gotcha.max_gotchas_per_project, 40);
368
369        assert_eq!(migrate_retired_document(&migrated).expect("parses"), None);
370    }
371
372    #[test]
373    fn lookup_names_retired_keys_and_everything_under_them() {
374        assert!(retired_key("solution.commercial.adaptive.enabled").is_some());
375        assert!(retired_key("ocla.delivery.cache.l2_ttl_secs").is_some());
376        assert!(retired_key("shadow.auto_record").is_some());
377        assert!(retired_key("gain.auto_publish").is_some());
378        assert!(retired_key("shadow.enabled").is_none());
379        assert!(retired_key("cache.l2_ttl_secs").is_none());
380        assert!(retired_key("session_token_limit_x").is_none());
381    }
382}