Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[![codecov](https://codecov.io/gh/dallay/corvus/graph/badge.svg?token=N4THEP2OF1)](https://codecov.io/gh/dallay/corvus)
[![License](https://img.shields.io/github/license/dallay/corvus?color=blue)](LICENSE)
[![Version](https://img.shields.io/badge/version-0.1.14-blue.svg)](gradle.properties)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/dallay/corvus/compare)

## 🛡️ Code Quality (SonarCloud)

Expand Down
35 changes: 28 additions & 7 deletions clients/agent-runtime/src/channels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ fn channel_delivery_instructions(channel_name: &str) -> Option<&'static str> {
}
}

fn update_visibility_enabled(config: &Config) -> bool {
config.updates.enabled && config.updates.channel_visibility_enabled
}

struct ResponseContext<'a> {
channel: Option<&'a Arc<dyn Channel>>,
reply_target: &'a str,
Expand Down Expand Up @@ -459,13 +463,15 @@ async fn process_channel_message(ctx: Arc<ChannelRuntimeContext>, msg: traits::C
format!("{memory_context}{}", msg.content)
};

let _ = crate::update::maybe_send_opportunistic_update_notice(
ctx.config.as_ref(),
&msg,
target_channel.as_ref(),
env!("CARGO_PKG_VERSION"),
)
.await;
if update_visibility_enabled(ctx.config.as_ref()) {
let _ = crate::update::maybe_send_opportunistic_update_notice(
ctx.config.as_ref(),
&msg,
target_channel.as_ref(),
env!("CARGO_PKG_VERSION"),
)
.await;
}
Comment on lines +466 to +474
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Minor: Redundant check with function's internal guard.

Per context snippet 1 (update/mod.rs:867-870), maybe_send_opportunistic_update_notice already performs the same enabled && channel_visibility_enabled check internally. The outer gate here is defense-in-depth but creates duplication.

This is acceptable as-is (avoids an async call when disabled), but document the intentional redundancy or extract the check to a shared location to avoid divergence.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@clients/agent-runtime/src/channels/mod.rs` around lines 466 - 474, The outer
visibility check using update_visibility_enabled before calling
maybe_send_opportunistic_update_notice duplicates the same guard that
maybe_send_opportunistic_update_notice performs internally; either remove the
outer if and call maybe_send_opportunistic_update_notice directly (letting its
internal guard handle it) or, if you want to keep the outer short-circuit to
avoid an async call, add a concise comment above the if that references
update_visibility_enabled and maybe_send_opportunistic_update_notice and
explains the intentional redundancy to prevent future divergence.


let session_id = channel_session_id(&msg);

Expand Down Expand Up @@ -3175,4 +3181,19 @@ mod tests {
assert_eq!(sent_messages.len(), 1);
assert!(!sent_messages[0].contains("request blocked"));
}

#[test]
fn update_visibility_gate_follows_policy_flags() {
let mut config = Config::default();
config.updates.enabled = true;
config.updates.channel_visibility_enabled = true;
assert!(update_visibility_enabled(&config));

config.updates.channel_visibility_enabled = false;
assert!(!update_visibility_enabled(&config));

config.updates.enabled = false;
config.updates.channel_visibility_enabled = true;
assert!(!update_visibility_enabled(&config));
}
}
156 changes: 156 additions & 0 deletions clients/agent-runtime/src/config/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,10 +2027,20 @@ impl Default for Config {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(clippy::struct_excessive_bools)]
pub struct UpdateConfig {
/// Enable periodic update checks + notifications in daemon mode.
#[serde(default = "default_updates_enabled")]
pub enabled: bool,
/// Auto-install policy; disabled by default for safety.
#[serde(default)]
pub auto_install_enabled: bool,
/// Channel-side update visibility.
#[serde(default = "default_true")]
pub channel_visibility_enabled: bool,
/// CLI startup notice visibility.
#[serde(default = "default_true")]
pub cli_startup_notice_enabled: bool,
/// Poll interval for update checks while daemon is running.
#[serde(
default = "default_update_check_interval_minutes",
Expand All @@ -2049,6 +2059,15 @@ pub struct UpdateConfig {
/// Value: list of destination identifiers for that channel.
#[serde(default)]
pub notify_destinations: HashMap<String, Vec<String>>,
/// Optional install method override.
#[serde(default)]
pub install_method_override: Option<String>,
/// Restart policy after successful install.
#[serde(default = "default_update_restart_policy")]
pub restart_policy: String,
/// Maximum retained history entries.
#[serde(default = "default_update_history_max_entries")]
pub history_max_entries: u32,
}

fn deserialize_nonzero_u64<'de, D>(deserializer: D) -> Result<u64, D::Error>
Expand Down Expand Up @@ -2077,13 +2096,45 @@ fn default_update_confirmation_ttl_minutes() -> u64 {
30
}

fn default_update_restart_policy() -> String {
"prompt".to_string()
}

fn default_update_history_max_entries() -> u32 {
200
}

fn normalize_install_method_override(raw: &str) -> Option<String> {
let normalized = raw.trim().to_ascii_lowercase();
match normalized.as_str() {
"npm" | "pnpm" | "yarn" | "bun" | "homebrew" | "cargo" | "script_binary" => {
Some(normalized)
}
_ => None,
}
Comment on lines +2107 to +2114
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Install-method normalization is inconsistent with update core parser.

normalize_install_method_override() rejects "unknown", but clients/agent-runtime/src/update/mod.rs accepts it in InstallMethod::from_str. This creates config/runtime contract drift for CORVUS_UPDATE_METHOD_OVERRIDE.

Proposed fix
 fn normalize_install_method_override(raw: &str) -> Option<String> {
     let normalized = raw.trim().to_ascii_lowercase();
     match normalized.as_str() {
-        "npm" | "pnpm" | "yarn" | "bun" | "homebrew" | "cargo" | "script_binary" => {
+        "npm" | "pnpm" | "yarn" | "bun" | "homebrew" | "cargo" | "script_binary" | "unknown" => {
             Some(normalized)
         }
         _ => None,
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@clients/agent-runtime/src/config/schema.rs` around lines 2107 - 2114,
normalize_install_method_override rejects "unknown" but InstallMethod::from_str
in update::mod accepts it, causing a mismatch for CORVUS_UPDATE_METHOD_OVERRIDE;
update normalize_install_method_override to accept "unknown" (i.e., include
"unknown" in the match arm) so its accepted values align with
InstallMethod::from_str and the runtime/config contract is consistent. Reference
normalize_install_method_override and InstallMethod::from_str when making the
change.

}

fn normalize_restart_policy(raw: &str) -> Option<String> {
let normalized = raw.trim().to_ascii_lowercase();
match normalized.as_str() {
"never" | "prompt" | "auto_managed_service" => Some(normalized),
_ => None,
}
}

impl Default for UpdateConfig {
fn default() -> Self {
Self {
enabled: default_updates_enabled(),
auto_install_enabled: false,
channel_visibility_enabled: true,
cli_startup_notice_enabled: true,
check_interval_minutes: default_update_check_interval_minutes(),
confirmation_ttl_minutes: default_update_confirmation_ttl_minutes(),
notify_destinations: HashMap::new(),
install_method_override: None,
restart_policy: default_update_restart_policy(),
history_max_entries: default_update_history_max_entries(),
}
}
}
Expand Down Expand Up @@ -2571,6 +2622,51 @@ impl Config {
&mut self.memory.surreal.password,
);
env_override_optional("CORVUS_SURREALDB_TOKEN", &mut self.memory.surreal.token);

env_override_bool("CORVUS_UPDATES_ENABLED", None, &mut self.updates.enabled);
env_override_bool(
"CORVUS_UPDATE_AUTO_INSTALL",
None,
&mut self.updates.auto_install_enabled,
);
env_override_bool(
"CORVUS_UPDATE_CHANNEL_VISIBILITY",
None,
&mut self.updates.channel_visibility_enabled,
);
env_override_bool(
"CORVUS_UPDATE_CLI_NOTICE",
None,
&mut self.updates.cli_startup_notice_enabled,
);

if let Ok(raw) = std::env::var("CORVUS_UPDATE_METHOD_OVERRIDE") {
let trimmed = raw.trim();
if !trimmed.is_empty() {
if let Some(method) = normalize_install_method_override(trimmed) {
self.updates.install_method_override = Some(method);
} else {
tracing::warn!(
"ignoring invalid CORVUS_UPDATE_METHOD_OVERRIDE value: {}",
trimmed
);
}
}
}

if let Ok(raw) = std::env::var("CORVUS_UPDATE_RESTART_POLICY") {
let trimmed = raw.trim();
if !trimmed.is_empty() {
if let Some(policy) = normalize_restart_policy(trimmed) {
self.updates.restart_policy = policy;
} else {
tracing::warn!(
"ignoring invalid CORVUS_UPDATE_RESTART_POLICY value: {}",
trimmed
);
}
}
}
}

pub fn validate_for_runtime(&self) -> Result<()> {
Expand Down Expand Up @@ -2947,6 +3043,12 @@ default_temperature = 0.7
fn updates_config_defaults_are_safe_and_enabled() {
let updates = UpdateConfig::default();
assert!(updates.enabled);
assert!(!updates.auto_install_enabled);
assert!(updates.channel_visibility_enabled);
assert!(updates.cli_startup_notice_enabled);
assert!(updates.install_method_override.is_none());
assert_eq!(updates.restart_policy, "prompt");
assert_eq!(updates.history_max_entries, 200);
assert_eq!(updates.check_interval_minutes, 30);
assert_eq!(updates.confirmation_ttl_minutes, 30);
assert!(updates.notify_destinations.is_empty());
Expand Down Expand Up @@ -4506,6 +4608,60 @@ default_model = "legacy-model"
std::env::remove_var("CORVUS_SURREALDB_TOKEN");
}

#[test]
fn env_override_updates_policy_fields() {
let _env_guard = env_override_test_guard();
let mut config = Config::default();

std::env::set_var("CORVUS_UPDATES_ENABLED", "false");
std::env::set_var("CORVUS_UPDATE_AUTO_INSTALL", "true");
std::env::set_var("CORVUS_UPDATE_CHANNEL_VISIBILITY", "false");
std::env::set_var("CORVUS_UPDATE_CLI_NOTICE", "false");
std::env::set_var("CORVUS_UPDATE_METHOD_OVERRIDE", "cargo");
std::env::set_var("CORVUS_UPDATE_RESTART_POLICY", "never");

config.apply_env_overrides();

assert!(!config.updates.enabled);
assert!(config.updates.auto_install_enabled);
assert!(!config.updates.channel_visibility_enabled);
assert!(!config.updates.cli_startup_notice_enabled);
assert_eq!(
config.updates.install_method_override.as_deref(),
Some("cargo")
);
assert_eq!(config.updates.restart_policy, "never");

std::env::remove_var("CORVUS_UPDATES_ENABLED");
std::env::remove_var("CORVUS_UPDATE_AUTO_INSTALL");
std::env::remove_var("CORVUS_UPDATE_CHANNEL_VISIBILITY");
std::env::remove_var("CORVUS_UPDATE_CLI_NOTICE");
std::env::remove_var("CORVUS_UPDATE_METHOD_OVERRIDE");
std::env::remove_var("CORVUS_UPDATE_RESTART_POLICY");
}

#[test]
fn env_override_updates_invalid_values_fail_safe() {
let _env_guard = env_override_test_guard();
let mut config = Config::default();
config.updates.install_method_override = Some("npm".to_string());
config.updates.restart_policy = "prompt".to_string();

std::env::set_var("CORVUS_UPDATE_METHOD_OVERRIDE", "unknown");
std::env::set_var("CORVUS_UPDATE_RESTART_POLICY", "invalid");

config.apply_env_overrides();

assert_eq!(
config.updates.install_method_override.as_deref(),
Some("npm")
);
assert_eq!(config.updates.restart_policy, "prompt");

std::env::remove_var("CORVUS_UPDATE_METHOD_OVERRIDE");
std::env::remove_var("CORVUS_UPDATE_RESTART_POLICY");
}

#[test]
fn gateway_config_default_values() {
let g = GatewayConfig::default();
Expand Down
Loading
Loading