mirror of
https://github.com/codewhale-hq/Codewhale.git
synced 2026-11-12 18:18:10 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f56b9b9cc | ||
|
|
8aa7707d04 |
No files matched your search
@@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **Non-ASCII file names:** `/diff`, the `@git` and `@diff` mentions and the Runtime API workspace diff now show paths with Chinese, emoji and other non-ASCII characters as written instead of as quoted octal escapes, and the turn context no longer lists the workspace root as an empty "Active paths" entry. Thanks [@luochen211](https://github.com/luochen211) (PR 7317).
|
||||
- **Session names after a crash, and keep-forever snapshot retention:** a session name saved right after a crash that cut off the previous session-index line is no longer lost, because the new entry now starts on its own line; and a very large `[snapshots] max_age_days` (such as `9223372036854775807` for "keep forever") no longer wraps around and deletes every undo snapshot at session start. Thanks [@luochen211](https://github.com/luochen211) (PR 7316).
|
||||
- **Blank environment variables:** exporting a variable empty (for example `CODEWHALE_MODEL=` from a compose `${VAR:-}` template) no longer hides its legacy alias. `DEEPSEEK_MODEL`, `DEEPSEEK_BASE_URL`, `KIMI_BASE_URL`, `DEEPSEEK_FORCE_HTTP1`, `DEEPSEEK_STREAM_OPEN_TIMEOUT_SECS` and the other provider alias variables now apply as they do when the primary is unset. Thanks [@luochen211](https://github.com/luochen211) (PR 7315).
|
||||
- **Qwen Code as an external agent:** Codewhale now finds an installed Qwen Code CLI (`qwen`, 0.6.1 or newer) and can run it as a session over ACP with `qwen --acp`. `GET /v1/agents/external` lists it, an older install is reported as needing `npm i -g @qwen-code/qwen-code@latest`, and sign-in stays inside Qwen Code (`/auth`). Thanks [@MannXo](https://github.com/MannXo) (PR 7293).
|
||||
- **MCP and language servers that send requests mid-call:** a tool call no longer fails with "neither a result nor an error" when an MCP server sends a `ping` or other request that reuses the call's id while the call is running, and a language server's `workspace/configuration` or similar request no longer ends a pending LSP request. Codewhale now answers `ping`, answers other server requests with "Method not found" (it never advertised them), keeps waiting for the real reply, and a refused answer over Streamable HTTP no longer drops the connection to legacy SSE. Thanks [@luochen211](https://github.com/luochen211) (PR 7319).
|
||||
- **Qwen Code as an external agent:** Codewhale now finds an installed Qwen Code CLI (`qwen`, 0.6.1 or newer) and can run it as a session over ACP with `qwen --acp`. `GET /v1/agents/external` lists it, an older install is reported as needing `npm i -g @qwen-code/qwen-code@latest`, and sign-in stays inside Qwen Code (`/auth`). Thanks [@MannXo](https://github.com/MannXo) (#7293).
|
||||
- **README and contributor credit:** the repository front page now opens the way the website does: the line "The model can be anyone's. The agent should be yours.", one sentence on what Codewhale is, the install command and one picture, with reference detail moved into the linked guides; the 18 translated READMEs follow the same structure and say they are machine-drafted. The contributor wall and the website now count the same 433 people (407 GitHub accounts and the commit authors whose email is not linked to an account), where the website had counted accounts only. `DEPENDENCY_SECURITY.md` moved into `docs/dependency-maintenance.md`, and `.github/SUPPORT.md` says where to ask for help.
|
||||
|
||||
@@ -3115,10 +3115,6 @@ fn write_exec_stdout(text: &str) -> Result<()> {
|
||||
.and_then(|()| stdout.flush())
|
||||
{
|
||||
Err(err) if err.kind() == io::ErrorKind::BrokenPipe => {
|
||||
let _ = codewhale_telemetry::report_termination(
|
||||
codewhale_telemetry::ExitClass::Signal,
|
||||
codewhale_telemetry::SIGNAL_FLUSH_TIMEOUT,
|
||||
);
|
||||
// SAFETY: restores the default disposition and re-raises the
|
||||
// signal the write would have delivered without SIG_IGN.
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -293,17 +293,11 @@ fn dispatch_and_read_telemetry_with_endpoint(
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,
|
||||
Err(error) => panic!("read telemetry dry-run sink: {error}"),
|
||||
};
|
||||
let pending = fs::read_dir(telemetry_dir.join("spool"))
|
||||
.ok()
|
||||
.and_then(|entries| {
|
||||
let bodies: Vec<String> = entries
|
||||
.filter_map(Result::ok)
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| path.extension().is_some_and(|ext| ext == "jsonl"))
|
||||
.filter_map(|path| fs::read_to_string(path).ok())
|
||||
.collect();
|
||||
(!bodies.is_empty()).then(|| bodies.join("\n"))
|
||||
});
|
||||
let pending = match fs::read_to_string(telemetry_dir.join("buffer.jsonl")) {
|
||||
Ok(contents) => Some(contents),
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,
|
||||
Err(error) => panic!("read telemetry pending buffer: {error}"),
|
||||
};
|
||||
DispatchEvidence {
|
||||
telemetry_dir_exists: telemetry_dir.exists(),
|
||||
dry_run,
|
||||
|
||||
@@ -86,6 +86,7 @@ use codewhale_skill_install::install::{
|
||||
pub mod dsh;
|
||||
mod place;
|
||||
mod stage;
|
||||
mod summary;
|
||||
mod tarball;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -93,6 +94,7 @@ mod tests;
|
||||
|
||||
use place::{ensure_target_within_plugins_dir, finalize_install, plugin_target_path};
|
||||
use stage::stage_local_copy;
|
||||
pub use summary::{PluginSummary, PreviousInstall, SummaryClause, SummaryInput, build_summary};
|
||||
use tarball::stage_tarball;
|
||||
|
||||
/// Default per-bundle size cap. Mirrors the skill installer; the runtime
|
||||
|
||||
@@ -0,0 +1,865 @@
|
||||
//! One-line install summary shared by every install surface.
|
||||
//!
|
||||
//! A pure builder: everything it needs arrives in [`SummaryInput`], nothing is
|
||||
//! read from disk, the registry or the environment. Each clause carries a
|
||||
//! stable message id so a surface can localize the clause while the English
|
||||
//! text here stays the fallback.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use super::dsh::DshConversion;
|
||||
use crate::host_services::{HostService, HostServiceReview, PluginApprover, approver_label};
|
||||
use crate::manifest::PluginInventory;
|
||||
|
||||
pub const MSG_HEAD: &str = "plugin.summary.head";
|
||||
pub const MSG_STATE_ON: &str = "plugin.summary.state_on";
|
||||
pub const MSG_STATE_OFF: &str = "plugin.summary.state_off";
|
||||
pub const MSG_APPROVER: &str = "plugin.summary.approver";
|
||||
pub const MSG_ADDS: &str = "plugin.summary.adds";
|
||||
pub const MSG_ADDS_NOTHING_NEW: &str = "plugin.summary.adds_nothing_new";
|
||||
pub const MSG_NOW_ALSO_ADDS: &str = "plugin.summary.now_also_adds";
|
||||
pub const MSG_WONT_RUN: &str = "plugin.summary.wont_run";
|
||||
pub const MSG_NEEDS_EXTENSION_HOST: &str = "plugin.summary.needs_extension_host";
|
||||
pub const MSG_NEEDS_NODE: &str = "plugin.summary.needs_node";
|
||||
pub const MSG_REPLACES: &str = "plugin.summary.replaces";
|
||||
pub const MSG_DOWNGRADED: &str = "plugin.summary.downgraded";
|
||||
pub const MSG_SERVICES: &str = "plugin.summary.services";
|
||||
pub const MSG_SERVICES_NOW_ALSO: &str = "plugin.summary.services_now_also";
|
||||
pub const MSG_SERVICES_WITHHELD: &str = "plugin.summary.services_withheld";
|
||||
pub const MSG_SERVICES_UNOFFERED: &str = "plugin.summary.services_unoffered";
|
||||
pub const MSG_SERVICES_PAUSE: &str = "plugin.summary.services_pause";
|
||||
pub const MSG_PROVIDER_NEW_SESSION: &str = "plugin.summary.provider_new_session";
|
||||
|
||||
const HOST_LIST_LIMIT: usize = 3;
|
||||
const VERSION_GATE_REASON: &str = "incompatible-version";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SummaryClause {
|
||||
pub id: &'static str,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PluginSummary {
|
||||
pub clauses: Vec<SummaryClause>,
|
||||
}
|
||||
|
||||
impl PluginSummary {
|
||||
#[must_use]
|
||||
pub fn line(&self) -> String {
|
||||
let mut clauses = self.clauses.iter();
|
||||
let Some(head) = clauses.next() else {
|
||||
return String::new();
|
||||
};
|
||||
let rest: Vec<&str> = clauses.map(|clause| clause.text.as_str()).collect();
|
||||
if rest.is_empty() {
|
||||
head.text.clone()
|
||||
} else {
|
||||
format!("{}: {}", head.text, rest.join("; "))
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn ids(&self) -> Vec<&'static str> {
|
||||
self.clauses.iter().map(|clause| clause.id).collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PreviousInstall<'a> {
|
||||
pub name: &'a str,
|
||||
pub version: &'a str,
|
||||
pub source: Option<&'a str>,
|
||||
pub inventory: &'a PluginInventory,
|
||||
pub host_services: &'a [HostService],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SummaryInput<'a> {
|
||||
pub name: &'a str,
|
||||
pub version: &'a str,
|
||||
pub source: Option<&'a str>,
|
||||
pub enabled: bool,
|
||||
pub approver: Option<&'a PluginApprover>,
|
||||
pub inventory: &'a PluginInventory,
|
||||
pub dsh: Option<&'a DshConversion>,
|
||||
pub host_services: Option<&'a HostServiceReview>,
|
||||
pub extension_host_on: bool,
|
||||
pub previous: Option<PreviousInstall<'a>>,
|
||||
pub downgrade_allowed: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
struct Capabilities {
|
||||
skills: usize,
|
||||
local_mcp: usize,
|
||||
remote_mcp: usize,
|
||||
commands: usize,
|
||||
agents: usize,
|
||||
hooks: usize,
|
||||
lsp: usize,
|
||||
native: usize,
|
||||
providers: usize,
|
||||
panels: usize,
|
||||
filesystem_roots: BTreeSet<String>,
|
||||
network_hosts: BTreeSet<String>,
|
||||
lifecycle_mutation: bool,
|
||||
}
|
||||
|
||||
impl Capabilities {
|
||||
fn from_inventory(inventory: &PluginInventory) -> Self {
|
||||
let split = inventory.stdio_mcp_servers + inventory.remote_mcp_servers;
|
||||
let (local_mcp, remote_mcp) = if split == 0 {
|
||||
(inventory.mcp_servers, 0)
|
||||
} else {
|
||||
(
|
||||
inventory.stdio_mcp_servers + inventory.mcp_servers.saturating_sub(split),
|
||||
inventory.remote_mcp_servers,
|
||||
)
|
||||
};
|
||||
Self {
|
||||
skills: inventory.skills,
|
||||
local_mcp,
|
||||
remote_mcp,
|
||||
commands: inventory.commands,
|
||||
agents: inventory.agents,
|
||||
hooks: inventory.hooks,
|
||||
lsp: inventory.lsp,
|
||||
native: inventory.native,
|
||||
providers: inventory.providers,
|
||||
panels: 0,
|
||||
filesystem_roots: inventory.filesystem_roots.iter().cloned().collect(),
|
||||
network_hosts: inventory.network_hosts.iter().cloned().collect(),
|
||||
lifecycle_mutation: inventory.lifecycle_mutation,
|
||||
}
|
||||
}
|
||||
|
||||
fn with_dsh(mut self, dsh: &DshConversion) -> Self {
|
||||
self.skills = self.skills.max(dsh.skills.len());
|
||||
self.local_mcp = self.local_mcp.max(dsh.local_servers.len());
|
||||
self.remote_mcp = self.remote_mcp.max(dsh.remote_servers.len());
|
||||
self.native = self.native.max(dsh.native_rows.len());
|
||||
if dsh.requires_native && self.native == 0 {
|
||||
self.native = 1;
|
||||
}
|
||||
self.panels = self.panels.max(dsh.client_closures.len());
|
||||
self.network_hosts.extend(dsh.network_hosts.iter().cloned());
|
||||
self
|
||||
}
|
||||
|
||||
fn since(&self, old: &Self) -> Self {
|
||||
let more = |new: usize, old: usize| new.saturating_sub(old);
|
||||
Self {
|
||||
skills: more(self.skills, old.skills),
|
||||
local_mcp: more(self.local_mcp, old.local_mcp),
|
||||
remote_mcp: more(self.remote_mcp, old.remote_mcp),
|
||||
commands: more(self.commands, old.commands),
|
||||
agents: more(self.agents, old.agents),
|
||||
hooks: more(self.hooks, old.hooks),
|
||||
lsp: more(self.lsp, old.lsp),
|
||||
native: more(self.native, old.native),
|
||||
providers: more(self.providers, old.providers),
|
||||
panels: more(self.panels, old.panels),
|
||||
filesystem_roots: self
|
||||
.filesystem_roots
|
||||
.difference(&old.filesystem_roots)
|
||||
.cloned()
|
||||
.collect(),
|
||||
network_hosts: self
|
||||
.network_hosts
|
||||
.difference(&old.network_hosts)
|
||||
.cloned()
|
||||
.collect(),
|
||||
lifecycle_mutation: self.lifecycle_mutation && !old.lifecycle_mutation,
|
||||
}
|
||||
}
|
||||
|
||||
fn phrases(&self) -> Vec<String> {
|
||||
let mut phrases = Vec::new();
|
||||
let mut count = |n: usize, one: &str, many: &str| {
|
||||
if n > 0 {
|
||||
phrases.push(format!("{n} {}", if n == 1 { one } else { many }));
|
||||
}
|
||||
};
|
||||
count(self.skills, "skill", "skills");
|
||||
count(self.local_mcp, "local MCP server", "local MCP servers");
|
||||
count(self.remote_mcp, "remote MCP server", "remote MCP servers");
|
||||
count(self.commands, "command", "commands");
|
||||
count(self.agents, "agent profile", "agent profiles");
|
||||
count(self.hooks, "hook", "hooks");
|
||||
count(self.lsp, "language server", "language servers");
|
||||
count(self.native, "native extension", "native extensions");
|
||||
count(self.providers, "provider", "providers");
|
||||
count(self.panels, "panel", "panels");
|
||||
if !self.filesystem_roots.is_empty() {
|
||||
phrases.push(format!("file access ({})", limited(&self.filesystem_roots)));
|
||||
}
|
||||
if !self.network_hosts.is_empty() {
|
||||
phrases.push(format!("network access ({})", limited(&self.network_hosts)));
|
||||
}
|
||||
if self.lifecycle_mutation {
|
||||
phrases.push("permission to change plugins".to_string());
|
||||
}
|
||||
phrases
|
||||
}
|
||||
}
|
||||
|
||||
fn limited(items: &BTreeSet<String>) -> String {
|
||||
let shown: Vec<&str> = items
|
||||
.iter()
|
||||
.take(HOST_LIST_LIMIT)
|
||||
.map(String::as_str)
|
||||
.collect();
|
||||
let mut text = shown.join(", ");
|
||||
if items.len() > HOST_LIST_LIMIT {
|
||||
text.push_str(&format!(" and {} more", items.len() - HOST_LIST_LIMIT));
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
fn and_list(items: &[String]) -> String {
|
||||
match items {
|
||||
[] => String::new(),
|
||||
[only] => only.clone(),
|
||||
[init @ .., last] => format!("{} and {last}", init.join(", ")),
|
||||
}
|
||||
}
|
||||
|
||||
fn rows(n: usize) -> String {
|
||||
format!("{n} {}", if n == 1 { "row" } else { "rows" })
|
||||
}
|
||||
|
||||
fn quoted(peers: &[crate::host_services::ReviewPeer]) -> String {
|
||||
peers
|
||||
.iter()
|
||||
.map(|peer| format!("`{}`", peer.name))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
fn push(clauses: &mut Vec<SummaryClause>, id: &'static str, text: String) {
|
||||
clauses.push(SummaryClause { id, text });
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn build_summary(input: &SummaryInput<'_>) -> PluginSummary {
|
||||
let mut clauses = Vec::new();
|
||||
|
||||
let mut head = input.name.to_string();
|
||||
if !input.version.is_empty() {
|
||||
head.push(' ');
|
||||
head.push_str(input.version);
|
||||
}
|
||||
if let Some(source) = input.source.filter(|source| !source.is_empty()) {
|
||||
head.push_str(&format!(" from {source}"));
|
||||
}
|
||||
push(&mut clauses, MSG_HEAD, head);
|
||||
|
||||
if input.enabled {
|
||||
push(&mut clauses, MSG_STATE_ON, "on".to_string());
|
||||
} else {
|
||||
push(&mut clauses, MSG_STATE_OFF, "off".to_string());
|
||||
}
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_APPROVER,
|
||||
approver_label(input.approver).to_string(),
|
||||
);
|
||||
|
||||
if let Some(previous) = &input.previous {
|
||||
if input.downgrade_allowed && previous.version != input.version {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_DOWNGRADED,
|
||||
format!("downgraded from {}", previous.version),
|
||||
);
|
||||
}
|
||||
if previous.source != input.source {
|
||||
let from = previous
|
||||
.source
|
||||
.filter(|source| !source.is_empty())
|
||||
.map_or_else(|| "an unrecorded source".to_string(), str::to_string);
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_REPLACES,
|
||||
format!("replaces {} from {from}", previous.name),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let mut now = Capabilities::from_inventory(input.inventory);
|
||||
if let Some(dsh) = input.dsh {
|
||||
now = now.with_dsh(dsh);
|
||||
}
|
||||
match &input.previous {
|
||||
None => {
|
||||
let phrases = now.phrases();
|
||||
if !phrases.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_ADDS,
|
||||
format!("adds {}", and_list(&phrases)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Some(previous) => {
|
||||
let added = now
|
||||
.since(&Capabilities::from_inventory(previous.inventory))
|
||||
.phrases();
|
||||
if added.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_ADDS_NOTHING_NEW,
|
||||
"adds nothing new".to_string(),
|
||||
);
|
||||
} else {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_NOW_ALSO_ADDS,
|
||||
format!("now also adds {}", and_list(&added)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(dsh) = input.dsh {
|
||||
let skipped: Vec<_> = dsh
|
||||
.outcomes
|
||||
.iter()
|
||||
.filter(|outcome| outcome.needs_manual_port())
|
||||
.collect();
|
||||
if !skipped.is_empty() {
|
||||
let gated = skipped
|
||||
.iter()
|
||||
.filter(|outcome| outcome.reason.starts_with(VERSION_GATE_REASON))
|
||||
.count();
|
||||
let manual = skipped.len() - gated;
|
||||
let reason = match (gated, manual) {
|
||||
(0, _) => "each needs a manual port".to_string(),
|
||||
(_, 0) => "refused by the host version gate".to_string(),
|
||||
_ => format!(
|
||||
"{gated} refused by the host version gate, {manual} with no portable form"
|
||||
),
|
||||
};
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_WONT_RUN,
|
||||
format!("won't run: {} ({reason})", rows(skipped.len())),
|
||||
);
|
||||
}
|
||||
if dsh.requires_node {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_NEEDS_NODE,
|
||||
"needs Node.js for its local servers".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if now.native > 0 && !input.extension_host_on {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_NEEDS_EXTENSION_HOST,
|
||||
"needs the extension host (off)".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(review) = input.host_services {
|
||||
let granted = review.grants();
|
||||
let previously: &[HostService] = input
|
||||
.previous
|
||||
.as_ref()
|
||||
.map_or(&[], |previous| previous.host_services);
|
||||
let names = |services: Vec<HostService>| -> Vec<String> {
|
||||
services
|
||||
.into_iter()
|
||||
.map(|service| service.name().to_string())
|
||||
.collect()
|
||||
};
|
||||
match &input.previous {
|
||||
None => {
|
||||
if !granted.is_empty() {
|
||||
let mut text =
|
||||
format!("uses host services {}", and_list(&names(granted.clone())));
|
||||
let mut peers: Vec<_> = review
|
||||
.lines
|
||||
.iter()
|
||||
.filter(|line| line.offered)
|
||||
.flat_map(|line| line.shared_with.iter())
|
||||
.collect();
|
||||
peers.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
peers.dedup_by(|a, b| a.id == b.id);
|
||||
if !peers.is_empty() {
|
||||
let peers: Vec<_> = peers.into_iter().cloned().collect();
|
||||
text.push_str(&format!(" (shared with {})", quoted(&peers)));
|
||||
}
|
||||
push(&mut clauses, MSG_SERVICES, text);
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
let fresh: Vec<_> = granted
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|service| !previously.contains(service))
|
||||
.collect();
|
||||
if !fresh.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_SERVICES_NOW_ALSO,
|
||||
format!("now also uses host services {}", and_list(&names(fresh))),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let withheld: Vec<String> = review
|
||||
.lines
|
||||
.iter()
|
||||
.filter(|line| line.offered && !line.withheld_by.is_empty())
|
||||
.map(|line| {
|
||||
format!(
|
||||
"{} ({} is turned on without it)",
|
||||
line.service.name(),
|
||||
quoted(&line.withheld_by)
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if !withheld.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_SERVICES_WITHHELD,
|
||||
format!("off for now: {}", withheld.join(", ")),
|
||||
);
|
||||
}
|
||||
let unoffered: Vec<String> = review
|
||||
.lines
|
||||
.iter()
|
||||
.filter(|line| !line.offered)
|
||||
.map(|line| line.service.name().to_string())
|
||||
.collect();
|
||||
if !unoffered.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_SERVICES_UNOFFERED,
|
||||
format!(
|
||||
"this Codewhale does not offer {} to plugins",
|
||||
and_list(&unoffered)
|
||||
),
|
||||
);
|
||||
}
|
||||
if !granted.is_empty() {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_SERVICES_PAUSE,
|
||||
"services pause for every plugin in its host until the host is idle".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if now.providers > 0 {
|
||||
push(
|
||||
&mut clauses,
|
||||
MSG_PROVIDER_NEW_SESSION,
|
||||
"provider changes apply in a new session".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
PluginSummary { clauses }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::host_services::{
|
||||
AgentApproval, AgentPosture, HostServiceLine, PersonVia, PluginCohort, ReviewPeer,
|
||||
};
|
||||
use crate::install::dsh::DshOutcome;
|
||||
|
||||
fn inventory() -> PluginInventory {
|
||||
PluginInventory::default()
|
||||
}
|
||||
|
||||
fn input<'a>(inventory: &'a PluginInventory, approver: &'a PluginApprover) -> SummaryInput<'a> {
|
||||
SummaryInput {
|
||||
name: "notes",
|
||||
version: "1.2.0",
|
||||
source: Some("github:acme/notes"),
|
||||
enabled: true,
|
||||
approver: Some(approver),
|
||||
inventory,
|
||||
dsh: None,
|
||||
host_services: None,
|
||||
extension_host_on: true,
|
||||
previous: None,
|
||||
downgrade_allowed: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn person() -> PluginApprover {
|
||||
PluginApprover::person(PersonVia::Terminal)
|
||||
}
|
||||
|
||||
fn conversion() -> DshConversion {
|
||||
DshConversion {
|
||||
plugin_name: "dsh-whale-widget".into(),
|
||||
source_package: Some("dsh-whale-widget".into()),
|
||||
source_version: Some("0.4.2".into()),
|
||||
manifest_sha256: "0".repeat(64),
|
||||
layers: Vec::new(),
|
||||
outcomes: Vec::new(),
|
||||
diagnostics: Vec::new(),
|
||||
skills: vec!["balance".into()],
|
||||
remote_servers: vec!["account".into()],
|
||||
local_servers: vec!["bridge".into(), "helper".into()],
|
||||
network_hosts: vec!["api.example.com".into()],
|
||||
requires_node: false,
|
||||
requires_native: false,
|
||||
native_rows: Vec::new(),
|
||||
client_closures: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn skipped(kind: &str, reason: &str) -> DshOutcome {
|
||||
DshOutcome {
|
||||
row: Some("row".into()),
|
||||
package: Some("pkg".into()),
|
||||
kind: kind.into(),
|
||||
outcome: "skipped".into(),
|
||||
reason: reason.into(),
|
||||
layer: None,
|
||||
patch: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn text_of(summary: &PluginSummary, id: &str) -> Option<String> {
|
||||
summary
|
||||
.clauses
|
||||
.iter()
|
||||
.find(|clause| clause.id == id)
|
||||
.map(|clause| clause.text.clone())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_plain_plugin_names_source_state_approver_and_adds() {
|
||||
let inventory = PluginInventory {
|
||||
skills: 2,
|
||||
mcp_servers: 1,
|
||||
stdio_mcp_servers: 1,
|
||||
hooks: 1,
|
||||
network_hosts: vec!["api.example.com".into()],
|
||||
..inventory()
|
||||
};
|
||||
let approver = person();
|
||||
let summary = build_summary(&input(&inventory, &approver));
|
||||
assert_eq!(
|
||||
summary.line(),
|
||||
"notes 1.2.0 from github:acme/notes: on; approved by you; adds 2 skills, 1 local MCP server, 1 hook and network access (api.example.com)"
|
||||
);
|
||||
assert_eq!(
|
||||
summary.ids(),
|
||||
vec![MSG_HEAD, MSG_STATE_ON, MSG_APPROVER, MSG_ADDS]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_off_plugin_and_each_approver_kind_read_distinctly() {
|
||||
let inventory = inventory();
|
||||
let agent = PluginApprover::Agent(AgentApproval {
|
||||
posture: AgentPosture::AutoReview,
|
||||
workspace: "/work".into(),
|
||||
thread_id: None,
|
||||
turn_id: None,
|
||||
tool_call_id: None,
|
||||
});
|
||||
let mut request = input(&inventory, &agent);
|
||||
request.enabled = false;
|
||||
request.source = None;
|
||||
let summary = build_summary(&request);
|
||||
assert_eq!(
|
||||
summary.line(),
|
||||
"notes 1.2.0: off; approved by the agent in Auto-Review"
|
||||
);
|
||||
let mut request = input(&inventory, &agent);
|
||||
request.approver = None;
|
||||
assert!(
|
||||
build_summary(&request)
|
||||
.line()
|
||||
.contains("approver not recorded")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_dsh_package_counts_conversion_fields_and_panels() {
|
||||
let mut dsh = conversion();
|
||||
dsh.requires_node = true;
|
||||
dsh.client_closures = vec![crate::install::dsh::DshClientClosure {
|
||||
package: "dsh-whale-widget".into(),
|
||||
root: String::new(),
|
||||
entry: "source/client.js".into(),
|
||||
platform: None,
|
||||
inject: Vec::new(),
|
||||
host_provided: Vec::new(),
|
||||
files: Default::default(),
|
||||
bytes: 10,
|
||||
}];
|
||||
let inventory = inventory();
|
||||
let approver = person();
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.dsh = Some(&dsh);
|
||||
let summary = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_ADDS).unwrap(),
|
||||
"adds 1 skill, 2 local MCP servers, 1 remote MCP server, 1 panel and network access (api.example.com)"
|
||||
);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_NEEDS_NODE).unwrap(),
|
||||
"needs Node.js for its local servers"
|
||||
);
|
||||
assert!(text_of(&summary, MSG_WONT_RUN).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_refused_and_version_refused_rows_are_counted_with_reasons() {
|
||||
let mut dsh = conversion();
|
||||
dsh.outcomes = vec![
|
||||
skipped("foreign", "no portable representation"),
|
||||
skipped("mcp", "needs a manual port"),
|
||||
DshOutcome {
|
||||
outcome: "converted".into(),
|
||||
..skipped("mcp", "")
|
||||
},
|
||||
];
|
||||
let inventory = inventory();
|
||||
let approver = person();
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.dsh = Some(&dsh);
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&request), MSG_WONT_RUN).unwrap(),
|
||||
"won't run: 2 rows (each needs a manual port)"
|
||||
);
|
||||
|
||||
dsh.outcomes = vec![skipped(
|
||||
"patch",
|
||||
"incompatible-version: this bundle requires DSH `^0.1.0-rc.6`",
|
||||
)];
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.dsh = Some(&dsh);
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&request), MSG_WONT_RUN).unwrap(),
|
||||
"won't run: 1 row (refused by the host version gate)"
|
||||
);
|
||||
|
||||
dsh.outcomes
|
||||
.push(skipped("foreign", "no portable representation"));
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.dsh = Some(&dsh);
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&request), MSG_WONT_RUN).unwrap(),
|
||||
"won't run: 2 rows (1 refused by the host version gate, 1 with no portable form)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_native_rows_need_the_extension_host_only_while_it_is_off() {
|
||||
let mut dsh = conversion();
|
||||
dsh.requires_native = true;
|
||||
dsh.native_rows = vec!["worker".into()];
|
||||
let inventory = inventory();
|
||||
let approver = person();
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.dsh = Some(&dsh);
|
||||
request.extension_host_on = false;
|
||||
let off = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&off, MSG_NEEDS_EXTENSION_HOST).unwrap(),
|
||||
"needs the extension host (off)"
|
||||
);
|
||||
assert!(
|
||||
text_of(&off, MSG_ADDS)
|
||||
.unwrap()
|
||||
.contains("1 native extension")
|
||||
);
|
||||
request.extension_host_on = true;
|
||||
assert!(text_of(&build_summary(&request), MSG_NEEDS_EXTENSION_HOST).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_update_names_only_what_changed() {
|
||||
let before = PluginInventory {
|
||||
skills: 2,
|
||||
..inventory()
|
||||
};
|
||||
let after = PluginInventory {
|
||||
skills: 2,
|
||||
hooks: 1,
|
||||
network_hosts: vec!["api.example.com".into()],
|
||||
..inventory()
|
||||
};
|
||||
let approver = person();
|
||||
let mut request = input(&after, &approver);
|
||||
request.previous = Some(PreviousInstall {
|
||||
name: "notes",
|
||||
version: "1.1.0",
|
||||
source: Some("github:acme/notes"),
|
||||
inventory: &before,
|
||||
host_services: &[],
|
||||
});
|
||||
let summary = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_NOW_ALSO_ADDS).unwrap(),
|
||||
"now also adds 1 hook and network access (api.example.com)"
|
||||
);
|
||||
assert!(text_of(&summary, MSG_ADDS).is_none());
|
||||
assert!(text_of(&summary, MSG_REPLACES).is_none());
|
||||
assert!(text_of(&summary, MSG_DOWNGRADED).is_none());
|
||||
|
||||
request.previous = Some(PreviousInstall {
|
||||
name: "notes",
|
||||
version: "1.1.0",
|
||||
source: Some("github:acme/notes"),
|
||||
inventory: &after,
|
||||
host_services: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&request), MSG_ADDS_NOTHING_NEW).unwrap(),
|
||||
"adds nothing new"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_source_change_and_downgrade_are_stated() {
|
||||
let inventory = inventory();
|
||||
let approver = person();
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.previous = Some(PreviousInstall {
|
||||
name: "notes",
|
||||
version: "1.4.0",
|
||||
source: Some("github:old/notes"),
|
||||
inventory: &inventory,
|
||||
host_services: &[],
|
||||
});
|
||||
request.downgrade_allowed = true;
|
||||
let summary = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_REPLACES).unwrap(),
|
||||
"replaces notes from github:old/notes"
|
||||
);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_DOWNGRADED).unwrap(),
|
||||
"downgraded from 1.4.0"
|
||||
);
|
||||
request.downgrade_allowed = false;
|
||||
assert!(text_of(&build_summary(&request), MSG_DOWNGRADED).is_none());
|
||||
request.previous.as_mut().unwrap().source = None;
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&request), MSG_REPLACES).unwrap(),
|
||||
"replaces notes from an unrecorded source"
|
||||
);
|
||||
}
|
||||
|
||||
fn review(lines: Vec<HostServiceLine>) -> HostServiceReview {
|
||||
HostServiceReview::new("user/0/notes", "c", "k", &PluginCohort::Reviewed, lines)
|
||||
}
|
||||
|
||||
fn peer(name: &str) -> ReviewPeer {
|
||||
ReviewPeer {
|
||||
id: format!("user/0/{name}"),
|
||||
name: name.into(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_host_services_state_sharing_withheld_and_the_pause() {
|
||||
let inventory = inventory();
|
||||
let approver = person();
|
||||
let review = review(vec![
|
||||
HostServiceLine {
|
||||
service: HostService::Workspace,
|
||||
offered: true,
|
||||
shared_with: vec![peer("other")],
|
||||
withheld_by: Vec::new(),
|
||||
},
|
||||
HostServiceLine {
|
||||
service: HostService::Network,
|
||||
offered: true,
|
||||
shared_with: Vec::new(),
|
||||
withheld_by: vec![peer("legacy")],
|
||||
},
|
||||
HostServiceLine {
|
||||
service: HostService::Remote,
|
||||
offered: false,
|
||||
shared_with: Vec::new(),
|
||||
withheld_by: Vec::new(),
|
||||
},
|
||||
]);
|
||||
let mut request = input(&inventory, &approver);
|
||||
request.host_services = Some(&review);
|
||||
let summary = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_SERVICES).unwrap(),
|
||||
"uses host services workspace and network (shared with `other`)"
|
||||
);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_SERVICES_WITHHELD).unwrap(),
|
||||
"off for now: network (`legacy` is turned on without it)"
|
||||
);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_SERVICES_UNOFFERED).unwrap(),
|
||||
"this Codewhale does not offer remote to plugins"
|
||||
);
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_SERVICES_PAUSE).unwrap(),
|
||||
"services pause for every plugin in its host until the host is idle"
|
||||
);
|
||||
|
||||
let before = [HostService::Workspace];
|
||||
let prior = PluginInventory::default();
|
||||
request.previous = Some(PreviousInstall {
|
||||
name: "notes",
|
||||
version: "1.1.0",
|
||||
source: Some("github:acme/notes"),
|
||||
inventory: &prior,
|
||||
host_services: &before,
|
||||
});
|
||||
let update = build_summary(&request);
|
||||
assert_eq!(
|
||||
text_of(&update, MSG_SERVICES_NOW_ALSO).unwrap(),
|
||||
"now also uses host services network"
|
||||
);
|
||||
assert!(text_of(&update, MSG_SERVICES).is_none());
|
||||
|
||||
let empty = self::review(Vec::new());
|
||||
request.previous = None;
|
||||
request.host_services = Some(&empty);
|
||||
assert!(text_of(&build_summary(&request), MSG_SERVICES_PAUSE).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_provider_declarations_say_they_apply_in_a_new_session() {
|
||||
let inventory = PluginInventory {
|
||||
providers: 1,
|
||||
..inventory()
|
||||
};
|
||||
let approver = person();
|
||||
let summary = build_summary(&input(&inventory, &approver));
|
||||
assert_eq!(
|
||||
text_of(&summary, MSG_PROVIDER_NEW_SESSION).unwrap(),
|
||||
"provider changes apply in a new session"
|
||||
);
|
||||
assert!(text_of(&summary, MSG_ADDS).unwrap().contains("1 provider"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_long_host_lists_are_shortened() {
|
||||
let inventory = PluginInventory {
|
||||
network_hosts: ["a.io", "b.io", "c.io", "d.io", "e.io"]
|
||||
.map(String::from)
|
||||
.to_vec(),
|
||||
..inventory()
|
||||
};
|
||||
let approver = person();
|
||||
assert_eq!(
|
||||
text_of(&build_summary(&input(&inventory, &approver)), MSG_ADDS).unwrap(),
|
||||
"adds network access (a.io, b.io, c.io and 2 more)"
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
-131
@@ -23,7 +23,6 @@ use crate::client::{self, SendOutcome};
|
||||
use crate::decision::{self, TelemetryDecision};
|
||||
use crate::envelope;
|
||||
use crate::event::{Batch, Event, SCHEMA_VERSION, Surface};
|
||||
use crate::spool::{self, SpoolContext};
|
||||
|
||||
/// Events per batch.
|
||||
pub const BATCH_MAX_EVENTS: usize = 200;
|
||||
@@ -65,19 +64,6 @@ pub(crate) struct Context {
|
||||
pub app_version: String,
|
||||
pub git_sha: Option<String>,
|
||||
pub tty: bool,
|
||||
pub spool: PathBuf,
|
||||
pub nonce: String,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
fn header(&self) -> SpoolContext {
|
||||
SpoolContext::new(
|
||||
self.surface,
|
||||
self.app_version.clone(),
|
||||
self.git_sha.clone(),
|
||||
self.tty,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// A handle to the writer thread.
|
||||
@@ -223,7 +209,8 @@ fn append(context: &Context, event: &Event) {
|
||||
let Ok(line) = serde_json::to_string(event) else {
|
||||
return;
|
||||
};
|
||||
let _ = buffer::append(&context.root, &context.spool, &line);
|
||||
let path = buffer::buffer_path(&context.root);
|
||||
let _ = buffer::append(&context.root, &path, &line);
|
||||
}
|
||||
|
||||
/// Seal every event queued before this message without reaching the network.
|
||||
@@ -232,7 +219,7 @@ fn append(context: &Context, event: &Event) {
|
||||
/// runs. Re-deciding here preserves the same mid-session opt-out boundary as a
|
||||
/// full flush. An explicitly empty endpoint is the local dry-run sink and can
|
||||
/// therefore be finalized immediately; a configured endpoint leaves the
|
||||
/// events in this process's spool for a later start to send.
|
||||
/// events in `buffer.jsonl` for the next interactive flush.
|
||||
fn persist_local(context: &Context) -> FlushOutcome {
|
||||
match decision::re_decide(context.config_path.as_deref(), context.surface) {
|
||||
TelemetryDecision::Enabled(_) => {}
|
||||
@@ -246,10 +233,7 @@ fn persist_local(context: &Context) -> FlushOutcome {
|
||||
if context.endpoint.is_none() {
|
||||
return flush(context);
|
||||
}
|
||||
if buffer::read_lines(&context.spool)
|
||||
.iter()
|
||||
.all(|line| spool::is_header_line(line))
|
||||
{
|
||||
if buffer::read_lines(&buffer::buffer_path(&context.root)).is_empty() {
|
||||
FlushOutcome::Empty
|
||||
} else {
|
||||
FlushOutcome::Buffered
|
||||
@@ -273,7 +257,7 @@ fn flush(context: &Context) -> FlushOutcome {
|
||||
return FlushOutcome::Suppressed;
|
||||
}
|
||||
|
||||
let lines = spool::take_own(&context.root, &context.spool);
|
||||
let lines = buffer::drain(&context.root);
|
||||
if lines.is_empty() {
|
||||
return FlushOutcome::Empty;
|
||||
}
|
||||
@@ -293,94 +277,28 @@ fn flush(context: &Context) -> FlushOutcome {
|
||||
// attempts at most once per interval rather than on every launch.
|
||||
let _ = envelope::write_state(&context.root, &state);
|
||||
|
||||
deliver(
|
||||
&context.root,
|
||||
context.endpoint.as_deref(),
|
||||
&context.header(),
|
||||
install.install_id,
|
||||
events,
|
||||
)
|
||||
}
|
||||
|
||||
fn deliver(
|
||||
root: &std::path::Path,
|
||||
endpoint: Option<&str>,
|
||||
header: &SpoolContext,
|
||||
install_id: String,
|
||||
events: Vec<Event>,
|
||||
) -> FlushOutcome {
|
||||
let batch = Batch {
|
||||
schema_version: header.schema_version,
|
||||
notice_version: header.notice_version,
|
||||
schema_version: SCHEMA_VERSION,
|
||||
notice_version: crate::event::NOTICE_VERSION,
|
||||
sent_at: envelope::now_rfc3339(),
|
||||
install_id,
|
||||
app_version: header.app_version.clone(),
|
||||
git_sha: header.git_sha.clone(),
|
||||
surface: header.surface,
|
||||
install_id: install.install_id,
|
||||
app_version: context.app_version.clone(),
|
||||
git_sha: context.git_sha.clone(),
|
||||
surface: context.surface,
|
||||
os: envelope::current_os(),
|
||||
arch: envelope::current_arch(),
|
||||
libc: envelope::current_libc(),
|
||||
tty: header.tty,
|
||||
tty: context.tty,
|
||||
events,
|
||||
};
|
||||
match client::send(root, endpoint, &batch) {
|
||||
|
||||
match client::send(&context.root, context.endpoint.as_deref(), &batch) {
|
||||
SendOutcome::DryRun => FlushOutcome::DryRun,
|
||||
SendOutcome::Accepted => FlushOutcome::Sent,
|
||||
SendOutcome::Dropped => FlushOutcome::Dropped,
|
||||
}
|
||||
}
|
||||
|
||||
/// Send what dead processes left behind, once each, on their own thread so a
|
||||
/// slow request never holds up this session's writer.
|
||||
///
|
||||
/// Consent and the tombstone are decided before anything is read, and again by
|
||||
/// the sender for every batch. Each spool is deleted before its request.
|
||||
pub(crate) fn spawn_recovery(context: Context) {
|
||||
if !matches!(
|
||||
context.surface,
|
||||
Surface::Tui | Surface::Exec | Surface::Serve
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let _ = std::thread::Builder::new()
|
||||
.name("codewhale-telemetry-recover".to_string())
|
||||
.spawn(move || {
|
||||
let _ = catch_unwind(AssertUnwindSafe(|| recover(&context)));
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn recover(context: &Context) -> Vec<FlushOutcome> {
|
||||
match decision::re_decide(context.config_path.as_deref(), context.surface) {
|
||||
TelemetryDecision::Enabled(_) => {}
|
||||
TelemetryDecision::OptedOut | TelemetryDecision::ForcedOff => return Vec::new(),
|
||||
}
|
||||
send_dead(context)
|
||||
}
|
||||
|
||||
pub(crate) fn send_dead(context: &Context) -> Vec<FlushOutcome> {
|
||||
if buffer::tombstone_present(&context.root) {
|
||||
return Vec::new();
|
||||
}
|
||||
let Ok(install) = envelope::read_or_create_install_id(&context.root) else {
|
||||
return Vec::new();
|
||||
};
|
||||
spool::take_dead(&context.root, &context.nonce, std::time::SystemTime::now())
|
||||
.into_iter()
|
||||
.filter_map(|recovered| {
|
||||
let events = parse_events(&recovered.lines);
|
||||
(!events.is_empty()).then(|| {
|
||||
deliver(
|
||||
&context.root,
|
||||
context.endpoint.as_deref(),
|
||||
&recovered.context,
|
||||
install.install_id.clone(),
|
||||
events,
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Parse drained lines into events, capped at [`BATCH_MAX_EVENTS`] and
|
||||
/// [`BATCH_MAX_BYTES`], skipping anything that does not parse **or does not
|
||||
/// satisfy its declared string bounds**.
|
||||
@@ -455,39 +373,4 @@ mod tests {
|
||||
};
|
||||
assert_eq!(handle.persist_local(), FlushOutcome::TimedOut);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hung_writer_cannot_hold_a_termination_send_past_its_deadline() {
|
||||
let (tx, rx) = sync_channel::<Message>(buffer::MAX_EVENTS + 1);
|
||||
let handle = Handle {
|
||||
tx,
|
||||
pending: Arc::new(AtomicUsize::new(0)),
|
||||
closing: AtomicBool::new(false),
|
||||
};
|
||||
let started = Instant::now();
|
||||
let outcome = handle.shutdown(Duration::from_millis(50));
|
||||
assert_eq!(outcome, FlushOutcome::TimedOut);
|
||||
assert!(started.elapsed() < Duration::from_secs(5));
|
||||
assert!(matches!(rx.try_recv(), Ok(Message::Shutdown(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_termination_send_does_not_wait() {
|
||||
let (tx, _rx) = sync_channel::<Message>(buffer::MAX_EVENTS + 1);
|
||||
let handle = Handle {
|
||||
tx,
|
||||
pending: Arc::new(AtomicUsize::new(0)),
|
||||
closing: AtomicBool::new(false),
|
||||
};
|
||||
assert_eq!(
|
||||
handle.shutdown(Duration::from_millis(20)),
|
||||
FlushOutcome::TimedOut
|
||||
);
|
||||
let started = Instant::now();
|
||||
assert_eq!(
|
||||
handle.shutdown(Duration::from_secs(30)),
|
||||
FlushOutcome::TimedOut
|
||||
);
|
||||
assert!(started.elapsed() < Duration::from_secs(5));
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,8 @@
|
||||
//!
|
||||
//! | file | role |
|
||||
//! |---|---|
|
||||
//! | `spool/<nonce>.jsonl` | one process's header line, then one JSON event per line, awaiting its flush |
|
||||
//! | `spool/<nonce>.lock` | held exclusively by that process while it lives |
|
||||
//! | `buffer.jsonl` | the pre-spool sink, only ever truncated now |
|
||||
//! | `buffer.jsonl.lock` | the **privacy** lock, a sibling file; never a data file |
|
||||
//! | `buffer.jsonl` | one JSON event per line, awaiting a flush |
|
||||
//! | `buffer.jsonl.lock` | a **sibling** lock file; never the data file |
|
||||
//! | `dryrun.jsonl` | the sink when the endpoint resolves empty, same ring policy |
|
||||
//! | `state.json` | last version seen and last flush attempt |
|
||||
//! | `install_id.json` | the random install id |
|
||||
@@ -220,39 +218,6 @@ fn append_under_lock(root: &Path, path: &Path, buf: &[u8]) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Write a spool header line, while the caller holds the blocking privacy lock.
|
||||
pub(crate) fn append_header(root: &Path, path: &Path, line: &str) -> Result<bool> {
|
||||
let mut buf = Vec::with_capacity(line.len() + 1);
|
||||
buf.extend_from_slice(line.as_bytes());
|
||||
buf.push(b'\n');
|
||||
append_under_lock(root, path, &buf)
|
||||
}
|
||||
|
||||
/// Re-attach the spool header that a ring cut dropped, keeping the newest events.
|
||||
fn keep_spool_header(path: &Path, mut lines: Vec<String>) -> Vec<String> {
|
||||
use std::io::BufRead as _;
|
||||
let Ok(file) = File::open(path) else {
|
||||
return lines;
|
||||
};
|
||||
let mut first = String::new();
|
||||
if std::io::BufReader::new(file.take(MAX_LINE_BYTES as u64 + 2))
|
||||
.read_line(&mut first)
|
||||
.is_err()
|
||||
{
|
||||
return lines;
|
||||
}
|
||||
let first = first.trim_end().to_string();
|
||||
if first.is_empty() || !crate::spool::is_header_line(&first) || lines.first() == Some(&first) {
|
||||
return lines;
|
||||
}
|
||||
lines.insert(0, first);
|
||||
let size = |lines: &[String]| lines.iter().map(|l| l.len() as u64 + 1).sum::<u64>();
|
||||
while lines.len() > 1 && (lines.len() > MAX_EVENTS || size(&lines) > MAX_BYTES) {
|
||||
lines.remove(1);
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
/// Keep the newest [`MAX_EVENTS`] lines and at most [`MAX_BYTES`], under the
|
||||
/// compaction lock. On lock contention this cycle is skipped: the next append
|
||||
/// tries again, and the cap is a ceiling on disk footprint, not an invariant
|
||||
@@ -278,7 +243,7 @@ fn enforce_ring(root: &Path, path: &Path) {
|
||||
if len < PROBE_BYTES {
|
||||
return Ok(());
|
||||
}
|
||||
let lines = keep_spool_header(path, read_ring_tail(path)?);
|
||||
let lines = read_ring_tail(path)?;
|
||||
let mut body = lines.join("\n");
|
||||
if !body.is_empty() {
|
||||
body.push('\n');
|
||||
@@ -406,6 +371,33 @@ pub fn read_lines(path: &Path) -> Vec<String> {
|
||||
read_ring_tail(path).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Take every buffered line and truncate the buffer, under the compaction lock.
|
||||
///
|
||||
/// Returns an empty vector when the tombstone is present or the lock is held
|
||||
/// elsewhere. Truncates rather than unlinks — `crates/engine/src/fleet/ledger.rs`
|
||||
/// documents the rule: replacing the file leaves appenders holding the old
|
||||
/// inode.
|
||||
#[must_use]
|
||||
pub fn drain(root: &Path) -> Vec<String> {
|
||||
if tombstone_present(root) {
|
||||
return Vec::new();
|
||||
}
|
||||
let path = buffer_path(root);
|
||||
let drained = try_with_lock(root, || {
|
||||
// Re-check under the lock: a wipe may have landed between the check
|
||||
// above and the acquisition.
|
||||
if tombstone_present(root) {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let lines = read_lines(&path);
|
||||
if !lines.is_empty() {
|
||||
truncate(&path)?;
|
||||
}
|
||||
Ok(lines)
|
||||
});
|
||||
drained.ok().flatten().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Truncate a file to zero length, leaving the inode in place. A missing file
|
||||
/// is not an error.
|
||||
pub fn truncate(path: &Path) -> Result<()> {
|
||||
@@ -428,7 +420,7 @@ pub fn truncate(path: &Path) -> Result<()> {
|
||||
/// 1. take the blocking lock — this is not an exit path;
|
||||
/// 2. write the tombstone **first**, and never remove it here;
|
||||
/// 3. truncate `buffer.jsonl` and `dryrun.jsonl` — do **not** unlink them, and
|
||||
/// never unlink the privacy lock file — and delete every spool;
|
||||
/// never unlink the lock file;
|
||||
/// 4. remove `install_id.json` and `state.json`.
|
||||
///
|
||||
/// If any step after the tombstone fails, the error is returned and the caller
|
||||
@@ -474,11 +466,6 @@ pub fn wipe(root: &Path) -> Result<()> {
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Err(error) = fs::remove_dir_all(crate::spool::dir(root))
|
||||
&& error.kind() != std::io::ErrorKind::NotFound
|
||||
{
|
||||
failure.get_or_insert(anyhow::Error::new(error).context("failed to remove the spools"));
|
||||
}
|
||||
match failure {
|
||||
Some(error) => Err(error),
|
||||
None => Ok(()),
|
||||
@@ -486,8 +473,8 @@ pub fn wipe(root: &Path) -> Result<()> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Clear the tombstone, deleting every spool when there was one, and truncate
|
||||
/// the pre-spool buffer.
|
||||
/// Clear the tombstone and drop anything buffered before this process was
|
||||
/// permitted.
|
||||
///
|
||||
/// Called by `init` on every arming. Both the exact tombstone generation and a
|
||||
/// fresh durable permission check must still match while the wipe lock is held.
|
||||
@@ -509,7 +496,6 @@ pub(crate) fn arm(
|
||||
}
|
||||
let tombstone = tombstone_path(root);
|
||||
if tombstone.exists() {
|
||||
let _ = fs::remove_dir_all(crate::spool::dir(root));
|
||||
fs::remove_file(&tombstone)
|
||||
.with_context(|| format!("failed to remove {}", tombstone.display()))?;
|
||||
}
|
||||
|
||||
+6
-136
@@ -21,8 +21,8 @@
|
||||
//! construction empty until resolution completes. A disabled user's panic
|
||||
//! therefore writes nothing and creates no directory.
|
||||
//!
|
||||
//! Arming also gives the process its own spool file and, when the machine was
|
||||
//! opted out until now, deletes every spool left from before.
|
||||
//! Arming also **truncates** any stale buffer before a newly permitted process
|
||||
//! begins recording.
|
||||
//!
|
||||
//! # Failure posture
|
||||
//!
|
||||
@@ -41,14 +41,13 @@ pub mod decision;
|
||||
pub mod envelope;
|
||||
pub mod event;
|
||||
pub mod notice;
|
||||
pub mod spool;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
pub use actor::{BATCH_MAX_BYTES, BATCH_MAX_EVENTS, FlushOutcome};
|
||||
pub use counters::{Counter, ErrorCounter, SessionCounters, TurnOutcome, TurnTokens};
|
||||
@@ -70,27 +69,11 @@ pub use event::{
|
||||
/// handshake would hold a user's terminal past exit.
|
||||
pub const SHUTDOWN_FLUSH_TIMEOUT: Duration = Duration::from_secs(3);
|
||||
|
||||
/// How long the send attempt on a terminating signal or a broken pipe may hold
|
||||
/// the process.
|
||||
///
|
||||
/// Shorter than [`SHUTDOWN_FLUSH_TIMEOUT`] so that, run alongside the runtime's
|
||||
/// two second signal drain, it fits inside the two second grace a supervisor
|
||||
/// gives SIGTERM before it escalates.
|
||||
pub const SIGNAL_FLUSH_TIMEOUT: Duration = Duration::from_millis(1500);
|
||||
|
||||
const COLD_START_UNSET: u64 = u64::MAX;
|
||||
|
||||
static COLD_START_MS: AtomicU64 = AtomicU64::new(COLD_START_UNSET);
|
||||
|
||||
/// Everything a write path needs once the process is armed.
|
||||
struct Armed {
|
||||
handle: actor::Handle,
|
||||
root: std::path::PathBuf,
|
||||
spool: std::path::PathBuf,
|
||||
surface: Surface,
|
||||
started: Instant,
|
||||
exit_class: AtomicU8,
|
||||
session_end_recorded: AtomicBool,
|
||||
}
|
||||
|
||||
/// The one gate. Unset means every write path is a hard no-op.
|
||||
@@ -124,14 +107,6 @@ pub fn init(consent: TelemetryConsent) {
|
||||
|
||||
notice::show_startup_disclosure(consent.surface());
|
||||
|
||||
let header = spool::SpoolContext::new(
|
||||
consent.surface(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
envelope::release_build_sha(),
|
||||
envelope::current_tty(),
|
||||
);
|
||||
let (spool_path, nonce) = spool::open(&root, &header);
|
||||
|
||||
let context = actor::Context {
|
||||
root: root.clone(),
|
||||
endpoint: consent.endpoint().map(str::to_string),
|
||||
@@ -140,19 +115,12 @@ pub fn init(consent: TelemetryConsent) {
|
||||
app_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
git_sha: envelope::release_build_sha(),
|
||||
tty: envelope::current_tty(),
|
||||
spool: spool_path.clone(),
|
||||
nonce,
|
||||
};
|
||||
actor::spawn_recovery(context.clone());
|
||||
|
||||
let _ = ARMED.set(Armed {
|
||||
handle: actor::Handle::spawn(context),
|
||||
root: root.clone(),
|
||||
spool: spool_path,
|
||||
surface: consent.surface(),
|
||||
started: Instant::now(),
|
||||
exit_class: AtomicU8::new(ExitClass::Clean.as_u8()),
|
||||
session_end_recorded: AtomicBool::new(false),
|
||||
});
|
||||
|
||||
record_install_or_upgrade(&root);
|
||||
@@ -273,7 +241,8 @@ pub fn record_blocking(event: Event) {
|
||||
let Ok(line) = serde_json::to_string(&event) else {
|
||||
return;
|
||||
};
|
||||
let _ = buffer::append(&armed.root, &armed.spool, &line);
|
||||
let path = buffer::buffer_path(&armed.root);
|
||||
let _ = buffer::append(&armed.root, &path, &line);
|
||||
}
|
||||
|
||||
/// Record how this process is ending.
|
||||
@@ -297,105 +266,6 @@ pub fn exit_class() -> ExitClass {
|
||||
})
|
||||
}
|
||||
|
||||
/// Report how long the interactive event loop took to start. The terminal UI is
|
||||
/// the only caller; every other surface leaves the cold-start bucket absent.
|
||||
pub fn set_cold_start_ms(millis: u64) {
|
||||
let _ = COLD_START_MS.compare_exchange(
|
||||
COLD_START_UNSET,
|
||||
millis,
|
||||
Ordering::Relaxed,
|
||||
Ordering::Relaxed,
|
||||
);
|
||||
}
|
||||
|
||||
/// Build `session_end` from what this process actually accumulated.
|
||||
///
|
||||
/// The exit class is read from the process-wide atomic and never derived from
|
||||
/// an exit code. Building the event writes nothing; an unarmed process reports a
|
||||
/// zero duration and nothing reaches a sink.
|
||||
#[must_use]
|
||||
pub fn session_end_event() -> Event {
|
||||
let counters = session_counters();
|
||||
let cold_start = COLD_START_MS.load(Ordering::Relaxed);
|
||||
Event::SessionEnd {
|
||||
duration_bucket: DurationBucket::from_secs(
|
||||
ARMED
|
||||
.get()
|
||||
.map_or(0, |armed| armed.started.elapsed().as_secs()),
|
||||
),
|
||||
exit_class: exit_class(),
|
||||
cold_start_bucket: (cold_start != COLD_START_UNSET)
|
||||
.then(|| ColdStartBucket::from_millis(cold_start)),
|
||||
providers: counters.providers(),
|
||||
counters: counters.counters(),
|
||||
errors: counters.errors(),
|
||||
turn_wall: counters.turn_wall(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Queue this session's usage rows and `session_end` once.
|
||||
///
|
||||
/// Whichever of the clean path, the signal path or a broken pipe gets here
|
||||
/// first reports; later callers do nothing, so one session never ends twice.
|
||||
/// A no-op when unarmed.
|
||||
pub fn record_session_end() {
|
||||
let Some(armed) = ARMED.get() else {
|
||||
return;
|
||||
};
|
||||
if armed.session_end_recorded.swap(true, Ordering::AcqRel) {
|
||||
return;
|
||||
}
|
||||
for event in session_counters().usage_events() {
|
||||
record(event);
|
||||
}
|
||||
record(session_end_event());
|
||||
}
|
||||
|
||||
/// Close the session synchronously, for a path that cannot wait for the writer.
|
||||
///
|
||||
/// States `class`, then appends the usage rows and `session_end` to the local
|
||||
/// buffer with the same lock-free-for-the-caller write as [`record_blocking`].
|
||||
/// A no-op when unarmed, and a no-op for the events when the session already
|
||||
/// ended.
|
||||
pub fn record_session_end_blocking(class: ExitClass) {
|
||||
let Some(armed) = ARMED.get() else {
|
||||
return;
|
||||
};
|
||||
set_exit_class(class);
|
||||
if armed.session_end_recorded.swap(true, Ordering::AcqRel) {
|
||||
return;
|
||||
}
|
||||
for event in session_counters().usage_events() {
|
||||
record_blocking(event);
|
||||
}
|
||||
record_blocking(session_end_event());
|
||||
}
|
||||
|
||||
/// One bounded network attempt for a process that is being terminated.
|
||||
///
|
||||
/// Runs the ordinary flush, so consent, the opt-out tombstone and the run kill
|
||||
/// switch are re-checked immediately beforehand and a person who has opted out
|
||||
/// sends nothing. Short CLI commands stay disk-only. Never retried, and the
|
||||
/// caller is released after `deadline` whether or not the request finished.
|
||||
#[must_use]
|
||||
pub fn flush_for_termination(deadline: Duration) -> FlushOutcome {
|
||||
let Some(armed) = ARMED.get() else {
|
||||
return FlushOutcome::Empty;
|
||||
};
|
||||
if armed.surface == Surface::Cli {
|
||||
return FlushOutcome::Buffered;
|
||||
}
|
||||
armed.handle.shutdown(deadline)
|
||||
}
|
||||
|
||||
/// Record the session end and make the one bounded send attempt, for a process
|
||||
/// that is about to be ended by a signal. Returns [`FlushOutcome::Empty`] when
|
||||
/// unarmed.
|
||||
pub fn report_termination(class: ExitClass, deadline: Duration) -> FlushOutcome {
|
||||
record_session_end_blocking(class);
|
||||
flush_for_termination(deadline)
|
||||
}
|
||||
|
||||
/// Final flush, then stop the writer thread.
|
||||
///
|
||||
/// Returns [`FlushOutcome::Empty`] when unarmed.
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
//! Per-process spools and the recovery of the ones a dead process left behind.
|
||||
//!
|
||||
//! Each armed process owns `telemetry/spool/<nonce>.jsonl`, whose first line is
|
||||
//! a context header (the envelope facts that belong to that process), and holds
|
||||
//! an exclusive lock on `<nonce>.lock` for as long as it lives. Recording and
|
||||
//! the clean flush touch only the process's own spool, so one process can
|
||||
//! neither truncate nor send another's events under the wrong surface or
|
||||
//! version.
|
||||
//!
|
||||
//! A spool whose lock can be taken belongs to a process that is gone. A later
|
||||
//! TUI, exec or serve start sends at most [`MAX_RECOVERED`] of them, each once:
|
||||
//! the file is deleted **before** the request, so a crash or a failed send never
|
||||
//! causes a second attempt.
|
||||
//!
|
||||
//! The nonce is local only. It names a file and is never sent.
|
||||
//!
|
||||
//! Known limitation: a spool is only as trustworthy as the user account, like
|
||||
//! every other file here. Recovery therefore re-validates the header and every
|
||||
//! event as untrusted input instead of inheriting any bound.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::buffer;
|
||||
use crate::event::{NOTICE_VERSION, SCHEMA_VERSION, Surface, is_release_version_string};
|
||||
|
||||
/// Dead spools sent at one start. Older or surplus ones are deleted unsent.
|
||||
pub const MAX_RECOVERED: usize = 4;
|
||||
/// A dead spool older than this is deleted unsent.
|
||||
pub const MAX_AGE: Duration = Duration::from_secs(7 * 24 * 60 * 60);
|
||||
|
||||
const HEADER_VERSION: u32 = 1;
|
||||
const MAX_VERSION_BYTES: usize = 64;
|
||||
|
||||
/// The envelope facts one process stamps on everything it spools.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct SpoolContext {
|
||||
spool: u32,
|
||||
pub schema_version: u32,
|
||||
pub notice_version: u32,
|
||||
pub app_version: String,
|
||||
pub git_sha: Option<String>,
|
||||
pub surface: Surface,
|
||||
pub tty: bool,
|
||||
}
|
||||
|
||||
impl SpoolContext {
|
||||
pub(crate) fn new(
|
||||
surface: Surface,
|
||||
app_version: String,
|
||||
git_sha: Option<String>,
|
||||
tty: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
spool: HEADER_VERSION,
|
||||
schema_version: SCHEMA_VERSION,
|
||||
notice_version: NOTICE_VERSION,
|
||||
app_version,
|
||||
git_sha,
|
||||
surface,
|
||||
tty,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a header read from disk may be sent as an envelope.
|
||||
pub(crate) fn is_sendable(&self) -> bool {
|
||||
self.spool == HEADER_VERSION
|
||||
&& self.schema_version == SCHEMA_VERSION
|
||||
&& self.notice_version == NOTICE_VERSION
|
||||
&& self.app_version.len() <= MAX_VERSION_BYTES
|
||||
&& is_release_version_string(&self.app_version)
|
||||
&& self.git_sha.as_deref().is_none_or(|sha| {
|
||||
sha.len() == 12 && sha.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `line` is a spool header rather than an event.
|
||||
pub(crate) fn is_header_line(line: &str) -> bool {
|
||||
serde_json::from_str::<SpoolContext>(line).is_ok()
|
||||
}
|
||||
|
||||
/// `$CODEWHALE_HOME/telemetry/spool`.
|
||||
#[must_use]
|
||||
pub fn dir(root: &Path) -> PathBuf {
|
||||
root.join("spool")
|
||||
}
|
||||
|
||||
/// Every spool data file under `root`, for tests and diagnostics.
|
||||
#[must_use]
|
||||
pub fn data_files(root: &Path) -> Vec<PathBuf> {
|
||||
let Ok(entries) = fs::read_dir(dir(root)) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut files: Vec<PathBuf> = entries
|
||||
.filter_map(Result::ok)
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| path.extension().is_some_and(|ext| ext == "jsonl"))
|
||||
.collect();
|
||||
files.sort();
|
||||
files
|
||||
}
|
||||
|
||||
fn data_path(root: &Path, nonce: &str) -> PathBuf {
|
||||
dir(root).join(format!("{nonce}.jsonl"))
|
||||
}
|
||||
|
||||
fn lock_file_path(root: &Path, nonce: &str) -> PathBuf {
|
||||
dir(root).join(format!("{nonce}.lock"))
|
||||
}
|
||||
|
||||
fn is_nonce(value: &str) -> bool {
|
||||
value.len() == 32
|
||||
&& value
|
||||
.bytes()
|
||||
.all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'))
|
||||
}
|
||||
|
||||
fn open_lock_file(path: &Path) -> Option<File> {
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.truncate(false)
|
||||
.open(path)
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Create this process's spool and hold its lock until the process ends.
|
||||
///
|
||||
/// Runs at arming, where blocking on the privacy lock is allowed, so the header
|
||||
/// is on disk before any other writer, including the signal path, can append.
|
||||
/// Returns the data path and the nonce.
|
||||
pub(crate) fn open(root: &Path, context: &SpoolContext) -> (PathBuf, String) {
|
||||
let nonce = uuid::Uuid::new_v4().simple().to_string();
|
||||
let path = data_path(root, &nonce);
|
||||
if buffer::ensure_dir(&dir(root)).is_ok() {
|
||||
if let Some(file) = open_lock_file(&lock_file_path(root, &nonce)) {
|
||||
let lock = Box::leak(Box::new(fd_lock::RwLock::new(file)));
|
||||
if let Ok(guard) = lock.try_write() {
|
||||
std::mem::forget(guard);
|
||||
}
|
||||
}
|
||||
if let Ok(header) = serde_json::to_string(context) {
|
||||
let _ = buffer::with_lock(root, || buffer::append_header(root, &path, &header));
|
||||
}
|
||||
}
|
||||
(path, nonce)
|
||||
}
|
||||
|
||||
/// Take this process's own spool for delivery: read it and delete it, under the
|
||||
/// privacy lock.
|
||||
///
|
||||
/// Empty when the tombstone is present, the lock is held elsewhere, or the file
|
||||
/// could not be removed. A spool that cannot be removed is never sent, because
|
||||
/// a later start would send it again.
|
||||
#[must_use]
|
||||
pub(crate) fn take_own(root: &Path, path: &Path) -> Vec<String> {
|
||||
if buffer::tombstone_present(root) {
|
||||
return Vec::new();
|
||||
}
|
||||
buffer::try_with_lock(root, || {
|
||||
if buffer::tombstone_present(root) {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let lines = buffer::read_lines(path);
|
||||
if lines.is_empty() {
|
||||
return Ok(lines);
|
||||
}
|
||||
if remove_or_truncate(path) {
|
||||
Ok(lines)
|
||||
} else {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn remove_or_truncate(path: &Path) -> bool {
|
||||
fs::remove_file(path).is_ok() || buffer::truncate(path).is_ok_and(|()| !path.exists())
|
||||
}
|
||||
|
||||
/// A dead process's spool, already deleted from disk.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Recovered {
|
||||
pub context: SpoolContext,
|
||||
pub lines: Vec<String>,
|
||||
}
|
||||
|
||||
/// Claim the dead spools that may be sent, newest first, deleting every dead
|
||||
/// spool it looks at.
|
||||
///
|
||||
/// Live spools are skipped by their lock, and `own_nonce` is never touched.
|
||||
/// Unknown file names, symbolic links and anything without a valid header are
|
||||
/// deleted or ignored, never read as events.
|
||||
pub(crate) fn take_dead(root: &Path, own_nonce: &str, now: SystemTime) -> Vec<Recovered> {
|
||||
let Ok(entries) = fs::read_dir(dir(root)) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut stems = BTreeSet::new();
|
||||
for entry in entries.filter_map(Result::ok) {
|
||||
let name = entry.file_name();
|
||||
let Some(name) = name.to_str() else { continue };
|
||||
if let Some((stem, ext)) = name.rsplit_once('.')
|
||||
&& matches!(ext, "jsonl" | "lock")
|
||||
&& is_nonce(stem)
|
||||
&& stem != own_nonce
|
||||
{
|
||||
stems.insert(stem.to_string());
|
||||
}
|
||||
}
|
||||
let mut ranked: Vec<(SystemTime, String)> = stems
|
||||
.into_iter()
|
||||
.map(|stem| {
|
||||
let modified = [data_path(root, &stem), lock_file_path(root, &stem)]
|
||||
.iter()
|
||||
.find_map(|path| fs::symlink_metadata(path).and_then(|m| m.modified()).ok())
|
||||
.unwrap_or(SystemTime::UNIX_EPOCH);
|
||||
(modified, stem)
|
||||
})
|
||||
.collect();
|
||||
ranked.sort_by(|a, b| b.cmp(a));
|
||||
|
||||
let mut recovered = Vec::new();
|
||||
for (modified, stem) in ranked {
|
||||
if buffer::tombstone_present(root) {
|
||||
break;
|
||||
}
|
||||
let data = data_path(root, &stem);
|
||||
let lock_path = lock_file_path(root, &stem);
|
||||
let eligible = recovered.len() < MAX_RECOVERED
|
||||
&& now.duration_since(modified).is_ok_and(|age| age <= MAX_AGE);
|
||||
let claimed = with_dead_lock(&lock_path, || {
|
||||
let claimed = if eligible { claim(&data) } else { None };
|
||||
if claimed.is_none() {
|
||||
let _ = fs::remove_file(&data);
|
||||
}
|
||||
let _ = fs::remove_file(&lock_path);
|
||||
claimed
|
||||
});
|
||||
if let Some(Some(claimed)) = claimed {
|
||||
recovered.push(claimed);
|
||||
}
|
||||
}
|
||||
recovered
|
||||
}
|
||||
|
||||
fn with_dead_lock<T>(lock_path: &Path, operation: impl FnOnce() -> T) -> Option<T> {
|
||||
let file = open_lock_file(lock_path)?;
|
||||
let mut lock = fd_lock::RwLock::new(file);
|
||||
let _guard = lock.try_write().ok()?;
|
||||
Some(operation())
|
||||
}
|
||||
|
||||
fn claim(data: &Path) -> Option<Recovered> {
|
||||
let meta = fs::symlink_metadata(data).ok()?;
|
||||
if !meta.is_file() {
|
||||
return None;
|
||||
}
|
||||
let lines = buffer::read_lines(data);
|
||||
let (header, events) = lines.split_first()?;
|
||||
let context = serde_json::from_str::<SpoolContext>(header).ok()?;
|
||||
if !context.is_sendable() || events.is_empty() || !remove_or_truncate(data) {
|
||||
return None;
|
||||
}
|
||||
Some(Recovered {
|
||||
context,
|
||||
lines: events.to_vec(),
|
||||
})
|
||||
}
|
||||
@@ -1074,7 +1074,7 @@ fn failed_wipe_fails_closed() {
|
||||
assert!(result.is_err(), "a failed truncate must be reported");
|
||||
}
|
||||
assert!(
|
||||
crate::spool::take_own(&root, &buffer_path).is_empty(),
|
||||
buffer::drain(&root).is_empty(),
|
||||
"a tombstoned buffer must never drain, wipe failure or not"
|
||||
);
|
||||
assert!(
|
||||
@@ -1262,14 +1262,14 @@ fn drain_skips_a_torn_trailing_line() {
|
||||
.expect("open");
|
||||
file.write_all(b"{\"event\":\"pan").expect("tear");
|
||||
}
|
||||
let drained = crate::spool::take_own(&root, &path);
|
||||
let drained = buffer::drain(&root);
|
||||
assert_eq!(drained.len(), 3, "the drain returns raw lines");
|
||||
let parsed: Vec<Event> = drained
|
||||
.iter()
|
||||
.filter_map(|l| serde_json::from_str(l).ok())
|
||||
.collect();
|
||||
assert_eq!(parsed.len(), 2, "the torn line must not reach a batch");
|
||||
assert!(!path.exists(), "taking a spool deletes it");
|
||||
assert!(buffer::read_lines(&path).is_empty(), "drain truncates");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1320,25 +1320,21 @@ fn a_tombstoned_buffer_never_appends_or_drains() {
|
||||
|
||||
assert!(buffer::append(&root, &buffer::buffer_path(&root), &line(2)).is_none());
|
||||
assert!(buffer::append_locked(&root, &buffer::dryrun_path(&root), "{}").is_none());
|
||||
assert!(crate::spool::take_own(&root, &buffer::buffer_path(&root)).is_empty());
|
||||
assert!(buffer::drain(&root).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arming_after_a_tombstone_deletes_spools_and_truncates_the_legacy_buffer() {
|
||||
fn arming_truncates_a_pre_consent_buffer() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
buffer::ensure_dir(&root).expect("create root");
|
||||
buffer::append(&root, &buffer::buffer_path(&root), &line(1)).expect("append");
|
||||
buffer::wipe(&root).expect("wipe");
|
||||
std::fs::create_dir_all(crate::spool::dir(&root)).expect("spool dir");
|
||||
let planted = crate::spool::dir(&root).join(format!("{}.jsonl", "a".repeat(32)));
|
||||
std::fs::write(&planted, "{}\n").expect("plant");
|
||||
|
||||
let generation = buffer::tombstone_generation(&root).expect("read wipe generation");
|
||||
buffer::arm(&root, generation.as_ref(), || true).expect("arm");
|
||||
assert!(!buffer::tombstone_present(&root));
|
||||
assert!(buffer::read_lines(&buffer::buffer_path(&root)).is_empty());
|
||||
assert!(!planted.exists(), "re-enabling must not inherit old spools");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1438,21 +1434,6 @@ fn completed_wipe_blocks_identity_and_state_recreation() {
|
||||
|
||||
// ------------------------------------------------------------ unarmed gate --
|
||||
|
||||
#[test]
|
||||
fn termination_reporting_is_a_noop_when_unarmed() {
|
||||
assert!(!crate::is_armed());
|
||||
crate::record_session_end();
|
||||
crate::record_session_end_blocking(ExitClass::Signal);
|
||||
assert_eq!(
|
||||
crate::report_termination(ExitClass::Signal, Duration::from_millis(10)),
|
||||
crate::FlushOutcome::Empty
|
||||
);
|
||||
assert_eq!(
|
||||
crate::flush_for_termination(Duration::from_millis(10)),
|
||||
crate::FlushOutcome::Empty
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_blocking_is_a_noop_when_unarmed() {
|
||||
// The process panic hook is installed before the command line is parsed, so
|
||||
@@ -2013,309 +1994,3 @@ fn the_notice_summarizes_what_the_schema_collects_and_states_every_red_line() {
|
||||
assert!(!body.contains("CODEWHALE_TELEMETRY=0"));
|
||||
assert!(body.contains("docs/TELEMETRY.md"));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- the spools --
|
||||
|
||||
mod spools {
|
||||
use super::*;
|
||||
use crate::actor::{Context, send_dead};
|
||||
use crate::spool::{self, SpoolContext};
|
||||
|
||||
fn header(surface: Surface, version: &str) -> SpoolContext {
|
||||
SpoolContext::new(
|
||||
surface,
|
||||
version.to_string(),
|
||||
Some("abcdef123456".to_string()),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn event_line(source: SessionSource) -> String {
|
||||
serde_json::to_string(&Event::SessionStart { source }).expect("serialize")
|
||||
}
|
||||
|
||||
fn plant(root: &Path, nonce: char, header_line: &str, events: &[String]) -> PathBuf {
|
||||
std::fs::create_dir_all(spool::dir(root)).expect("spool dir");
|
||||
let path = spool::dir(root).join(format!("{}.jsonl", nonce.to_string().repeat(32)));
|
||||
let mut body = format!("{header_line}\n");
|
||||
for event in events {
|
||||
body.push_str(event);
|
||||
body.push('\n');
|
||||
}
|
||||
std::fs::write(&path, body).expect("plant spool");
|
||||
path
|
||||
}
|
||||
|
||||
fn header_line(surface: Surface, version: &str) -> String {
|
||||
serde_json::to_string(&header(surface, version)).expect("serialize header")
|
||||
}
|
||||
|
||||
fn current(root: &Path) -> Context {
|
||||
let header = header(Surface::Tui, "0.10.3");
|
||||
let (spool, nonce) = spool::open(root, &header);
|
||||
Context {
|
||||
root: root.to_path_buf(),
|
||||
endpoint: None,
|
||||
surface: Surface::Tui,
|
||||
config_path: None,
|
||||
app_version: "0.10.3".to_string(),
|
||||
git_sha: None,
|
||||
tty: false,
|
||||
spool,
|
||||
nonce,
|
||||
}
|
||||
}
|
||||
|
||||
fn dryrun_batches(root: &Path) -> Vec<Batch> {
|
||||
buffer::read_lines(&buffer::dryrun_path(root))
|
||||
.iter()
|
||||
.map(|line| serde_json::from_str(line).expect("a dry-run batch"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dead_spool_is_recovered_with_its_own_surface_and_version() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
let path = plant(
|
||||
&root,
|
||||
'b',
|
||||
&header_line(Surface::Serve, "0.9.9"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
|
||||
let outcomes = send_dead(&context);
|
||||
|
||||
assert_eq!(outcomes, vec![crate::FlushOutcome::DryRun]);
|
||||
let batches = dryrun_batches(&root);
|
||||
assert_eq!(batches.len(), 1);
|
||||
assert_eq!(batches[0].surface, Surface::Serve);
|
||||
assert_eq!(batches[0].app_version, "0.9.9");
|
||||
assert_eq!(batches[0].git_sha.as_deref(), Some("abcdef123456"));
|
||||
assert_eq!(batches[0].events.len(), 1);
|
||||
assert!(!path.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dead_spool_is_never_sent_twice() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
plant(
|
||||
&root,
|
||||
'b',
|
||||
&header_line(Surface::Exec, "0.10.3"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
assert_eq!(send_dead(&context).len(), 1);
|
||||
assert!(send_dead(&context).is_empty());
|
||||
assert_eq!(dryrun_batches(&root).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_live_locked_spool_is_untouched() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let live = header(Surface::Serve, "0.10.3");
|
||||
let (live_path, live_nonce) = spool::open(&root, &live);
|
||||
buffer::append(&root, &live_path, &event_line(SessionSource::Interactive)).expect("append");
|
||||
|
||||
let taken = spool::take_dead(&root, &"c".repeat(32), std::time::SystemTime::now());
|
||||
|
||||
assert!(taken.is_empty());
|
||||
assert_eq!(buffer::read_lines(&live_path).len(), 2);
|
||||
assert!(
|
||||
spool::dir(&root)
|
||||
.join(format!("{live_nonce}.lock"))
|
||||
.exists()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_running_process_never_recovers_its_own_spool() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
buffer::append(
|
||||
&root,
|
||||
&context.spool,
|
||||
&event_line(SessionSource::Interactive),
|
||||
)
|
||||
.expect("append");
|
||||
assert!(send_dead(&context).is_empty());
|
||||
assert_eq!(buffer::read_lines(&context.spool).len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tombstone_blocks_recovery_and_append() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
buffer::wipe(&root).expect("wipe");
|
||||
let planted = plant(
|
||||
&root,
|
||||
'b',
|
||||
&header_line(Surface::Serve, "0.10.3"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
|
||||
assert!(send_dead(&context).is_empty());
|
||||
assert!(dryrun_batches(&root).is_empty());
|
||||
assert!(
|
||||
planted.exists(),
|
||||
"nothing is read or sent under a tombstone"
|
||||
);
|
||||
assert!(buffer::append(&root, &context.spool, "{}").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wipe_removes_every_spool() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
plant(
|
||||
&root,
|
||||
'b',
|
||||
&header_line(Surface::Serve, "0.10.3"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
buffer::wipe(&root).expect("wipe");
|
||||
assert!(!spool::dir(&root).exists());
|
||||
assert!(!context.spool.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hostile_context_drops_the_whole_spool_unsent() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
let good = event_line(SessionSource::Interactive);
|
||||
let hostile_headers = [
|
||||
header_line(Surface::Serve, "/Users/victim/secret"),
|
||||
header_line(Surface::Serve, "0.10.3").replace("abcdef123456", "ZZZZZZZZZZZZ"),
|
||||
header_line(Surface::Serve, "0.10.3").replace("\"spool\":1", "\"spool\":2"),
|
||||
header_line(Surface::Serve, "0.10.3")
|
||||
.replace("\"schema_version\":", "\"x\":9,\"schema_version\":"),
|
||||
header_line(Surface::Serve, "0.10.3").replace("\"serve\"", "\"not-a-surface\""),
|
||||
format!(
|
||||
"{{\"schema_version\":{},\"notice_version\":{},\"app_version\":\"0.10.3\"}}",
|
||||
SCHEMA_VERSION + 1,
|
||||
NOTICE_VERSION
|
||||
),
|
||||
good.clone(),
|
||||
];
|
||||
for (index, hostile) in hostile_headers.iter().enumerate() {
|
||||
let nonce = char::from(b'1' + index as u8);
|
||||
let path = plant(&root, nonce, hostile, std::slice::from_ref(&good));
|
||||
assert!(send_dead(&context).is_empty(), "{hostile}");
|
||||
assert!(!path.exists(), "{hostile}");
|
||||
}
|
||||
let mut stale = header(Surface::Serve, "0.10.3");
|
||||
stale.schema_version = SCHEMA_VERSION + 1;
|
||||
plant(
|
||||
&root,
|
||||
'f',
|
||||
&serde_json::to_string(&stale).expect("serialize"),
|
||||
std::slice::from_ref(&good),
|
||||
);
|
||||
assert!(send_dead(&context).is_empty());
|
||||
assert!(dryrun_batches(&root).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hostile_event_in_a_dead_spool_is_dropped_and_the_rest_sent() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
plant(
|
||||
&root,
|
||||
'b',
|
||||
&header_line(Surface::Serve, "0.10.3"),
|
||||
&[
|
||||
r#"{"event":"panic","site":"/Users/victim/src/secret-repo/main.rs"}"#.to_string(),
|
||||
event_line(SessionSource::Interactive),
|
||||
],
|
||||
);
|
||||
assert_eq!(send_dead(&context).len(), 1);
|
||||
let batches = dryrun_batches(&root);
|
||||
assert_eq!(batches[0].events.len(), 1);
|
||||
assert!(!serde_json::to_string(&batches).unwrap().contains("victim"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_count_and_age_caps_hold() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let context = current(&root);
|
||||
let now = std::time::SystemTime::now();
|
||||
let mut paths = Vec::new();
|
||||
for (index, nonce) in ['1', '2', '3', '4', '5', '6'].into_iter().enumerate() {
|
||||
let path = plant(
|
||||
&root,
|
||||
nonce,
|
||||
&header_line(Surface::Serve, "0.10.3"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
let age = Duration::from_secs(60 * (index as u64 + 1));
|
||||
std::fs::File::options()
|
||||
.write(true)
|
||||
.open(&path)
|
||||
.expect("open")
|
||||
.set_modified(now - age)
|
||||
.expect("set mtime");
|
||||
paths.push(path);
|
||||
}
|
||||
let stale = plant(
|
||||
&root,
|
||||
'7',
|
||||
&header_line(Surface::Serve, "0.10.3"),
|
||||
&[event_line(SessionSource::Interactive)],
|
||||
);
|
||||
std::fs::File::options()
|
||||
.write(true)
|
||||
.open(&stale)
|
||||
.expect("open")
|
||||
.set_modified(now - Duration::from_secs(8 * 24 * 60 * 60))
|
||||
.expect("set mtime");
|
||||
|
||||
assert_eq!(send_dead(&context).len(), spool::MAX_RECOVERED);
|
||||
assert_eq!(dryrun_batches(&root).len(), spool::MAX_RECOVERED);
|
||||
for path in paths.iter().chain([&stale]) {
|
||||
assert!(!path.exists(), "{} must be gone", path.display());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_processes_never_mix_lines() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let (tui_path, _) = spool::open(&root, &header(Surface::Tui, "0.10.3"));
|
||||
let (exec_path, _) = spool::open(&root, &header(Surface::Exec, "0.10.3"));
|
||||
assert_ne!(tui_path, exec_path);
|
||||
buffer::append(&root, &tui_path, &event_line(SessionSource::Interactive)).expect("append");
|
||||
buffer::append(&root, &exec_path, &event_line(SessionSource::Ci)).expect("append");
|
||||
|
||||
let tui = spool::take_own(&root, &tui_path);
|
||||
assert!(tui.iter().any(|l| l.contains("interactive")));
|
||||
assert!(
|
||||
tui.iter()
|
||||
.all(|l| !l.contains("\"ci\"") && !l.contains("exec"))
|
||||
);
|
||||
assert!(exec_path.exists(), "taking one spool leaves the other");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_ring_keeps_the_header() {
|
||||
let home = temp_home();
|
||||
let root = root_of(&home);
|
||||
let (path, _) = spool::open(&root, &header(Surface::Serve, "0.10.3"));
|
||||
for n in 0..700 {
|
||||
buffer::append(&root, &path, &line(n)).expect("append");
|
||||
}
|
||||
let lines = buffer::read_lines(&path);
|
||||
assert!(lines.len() <= buffer::MAX_EVENTS);
|
||||
assert!(spool::is_header_line(&lines[0]));
|
||||
assert!(lines.last().unwrap().contains(&line(699)));
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **Non-ASCII file names:** `/diff`, the `@git` and `@diff` mentions and the Runtime API workspace diff now show paths with Chinese, emoji and other non-ASCII characters as written instead of as quoted octal escapes, and the turn context no longer lists the workspace root as an empty "Active paths" entry. Thanks [@luochen211](https://github.com/luochen211) (PR 7317).
|
||||
- **Session names after a crash, and keep-forever snapshot retention:** a session name saved right after a crash that cut off the previous session-index line is no longer lost, because the new entry now starts on its own line; and a very large `[snapshots] max_age_days` (such as `9223372036854775807` for "keep forever") no longer wraps around and deletes every undo snapshot at session start. Thanks [@luochen211](https://github.com/luochen211) (PR 7316).
|
||||
- **Blank environment variables:** exporting a variable empty (for example `CODEWHALE_MODEL=` from a compose `${VAR:-}` template) no longer hides its legacy alias. `DEEPSEEK_MODEL`, `DEEPSEEK_BASE_URL`, `KIMI_BASE_URL`, `DEEPSEEK_FORCE_HTTP1`, `DEEPSEEK_STREAM_OPEN_TIMEOUT_SECS` and the other provider alias variables now apply as they do when the primary is unset. Thanks [@luochen211](https://github.com/luochen211) (PR 7315).
|
||||
- **Qwen Code as an external agent:** Codewhale now finds an installed Qwen Code CLI (`qwen`, 0.6.1 or newer) and can run it as a session over ACP with `qwen --acp`. `GET /v1/agents/external` lists it, an older install is reported as needing `npm i -g @qwen-code/qwen-code@latest`, and sign-in stays inside Qwen Code (`/auth`). Thanks [@MannXo](https://github.com/MannXo) (PR 7293).
|
||||
- **MCP and language servers that send requests mid-call:** a tool call no longer fails with "neither a result nor an error" when an MCP server sends a `ping` or other request that reuses the call's id while the call is running, and a language server's `workspace/configuration` or similar request no longer ends a pending LSP request. Codewhale now answers `ping`, answers other server requests with "Method not found" (it never advertised them), keeps waiting for the real reply, and a refused answer over Streamable HTTP no longer drops the connection to legacy SSE. Thanks [@luochen211](https://github.com/luochen211) (PR 7319).
|
||||
- **Qwen Code as an external agent:** Codewhale now finds an installed Qwen Code CLI (`qwen`, 0.6.1 or newer) and can run it as a session over ACP with `qwen --acp`. `GET /v1/agents/external` lists it, an older install is reported as needing `npm i -g @qwen-code/qwen-code@latest`, and sign-in stays inside Qwen Code (`/auth`). Thanks [@MannXo](https://github.com/MannXo) (#7293).
|
||||
- **README and contributor credit:** the repository front page now opens the way the website does: the line "The model can be anyone's. The agent should be yours.", one sentence on what Codewhale is, the install command and one picture, with reference detail moved into the linked guides; the 18 translated READMEs follow the same structure and say they are machine-drafted. The contributor wall and the website now count the same 433 people (407 GitHub accounts and the commit authors whose email is not linked to an account), where the website had counted accounts only. `DEPENDENCY_SECURITY.md` moved into `docs/dependency-maintenance.md`, and `.github/SUPPORT.md` says where to ask for help.
|
||||
|
||||
+60
-8
@@ -862,10 +862,6 @@ fn spawn_signal_cleanup_task() {
|
||||
let mut signals = TerminatingSignals::register();
|
||||
tokio::spawn(async move {
|
||||
let exit_code = signals.wait().await;
|
||||
codewhale_telemetry::record_session_end_blocking(codewhale_telemetry::ExitClass::Signal);
|
||||
let telemetry_send = tokio::task::spawn_blocking(|| {
|
||||
codewhale_telemetry::flush_for_termination(codewhale_telemetry::SIGNAL_FLUSH_TIMEOUT)
|
||||
});
|
||||
// Persistence and a serving Runtime API share a bounded window to
|
||||
// flush queued saves and end open streams with a typed `stream.end`.
|
||||
// A second signal skips both waits.
|
||||
@@ -874,9 +870,6 @@ fn spawn_signal_cleanup_task() {
|
||||
tokio::join!(
|
||||
codewhale_app_server::runtime_api::drain_for_signal_exit(),
|
||||
crate::tui::persistence_actor::flush_for_signal_exit(),
|
||||
async {
|
||||
let _ = telemetry_send.await;
|
||||
},
|
||||
)
|
||||
} => {}
|
||||
_ = signals.wait() => {}
|
||||
@@ -892,11 +885,66 @@ fn spawn_signal_cleanup_task() {
|
||||
#[cfg(unix)]
|
||||
codewhale_runtime::process_tree::kill_contained_trees_for_exit();
|
||||
crate::tui::ui::emergency_restore_terminal();
|
||||
// Nothing async survives the `exit` below, so this is the last
|
||||
// chance to say how the session ended. `record_blocking` is one
|
||||
// `O_APPEND` write with no lock: taking the compaction lock here
|
||||
// would let a second Codewhale process sharing CODEWHALE_HOME hang
|
||||
// Ctrl-C, and the second-signal short-circuit below has to stay
|
||||
// reachable. A no-op unless this process was armed.
|
||||
//
|
||||
// The class is stated, not derived: `RunTerminationReason::Canceled`
|
||||
// also exits 130, so `exit_code` cannot tell a signal from an
|
||||
// Esc-cancelled turn.
|
||||
record_signal_session_end();
|
||||
}
|
||||
std::process::exit(exit_code);
|
||||
});
|
||||
}
|
||||
|
||||
/// When this process's armed telemetry session began. Set once, at arming, and
|
||||
/// read from both the ordinary teardown and the signal path.
|
||||
static TELEMETRY_SESSION_START: std::sync::OnceLock<std::time::Instant> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
/// Build `session_end` from what this process actually accumulated.
|
||||
///
|
||||
/// The exit class is read from the process-wide atomic and never derived from
|
||||
/// an exit code: `RunTerminationReason::Canceled` maps to 130, the same value
|
||||
/// the SIGINT path uses, so a code-based derivation would report every
|
||||
/// Esc-cancelled turn as a signal.
|
||||
///
|
||||
/// The cold-start bucket is `None` unless the interactive event loop actually
|
||||
/// began, which is what keeps it absent rather than invented on the surfaces
|
||||
/// that have no event loop.
|
||||
fn telemetry_session_end() -> codewhale_telemetry::Event {
|
||||
let counters = codewhale_telemetry::session_counters();
|
||||
codewhale_telemetry::Event::SessionEnd {
|
||||
duration_bucket: codewhale_telemetry::DurationBucket::from_secs(
|
||||
TELEMETRY_SESSION_START
|
||||
.get()
|
||||
.map_or(0, |start| start.elapsed().as_secs()),
|
||||
),
|
||||
exit_class: codewhale_telemetry::exit_class(),
|
||||
cold_start_bucket: codewhale_runtime::startup_trace::cold_start_ms()
|
||||
.map(codewhale_telemetry::ColdStartBucket::from_millis),
|
||||
providers: counters.providers(),
|
||||
counters: counters.counters(),
|
||||
errors: counters.errors(),
|
||||
turn_wall: counters.turn_wall(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the session synchronously, from the signal handler.
|
||||
///
|
||||
/// A no-op unless this process was armed.
|
||||
fn record_signal_session_end() {
|
||||
codewhale_telemetry::set_exit_class(codewhale_telemetry::ExitClass::Signal);
|
||||
for event in codewhale_telemetry::session_counters().usage_events() {
|
||||
codewhale_telemetry::record_blocking(event);
|
||||
}
|
||||
codewhale_telemetry::record_blocking(telemetry_session_end());
|
||||
}
|
||||
|
||||
/// Terminating-signal streams, registered up front and awaited later.
|
||||
///
|
||||
/// Splitting registration from the await is the point: the OS disposition
|
||||
@@ -2466,6 +2514,7 @@ fn arm_telemetry_with_setup(
|
||||
return;
|
||||
};
|
||||
codewhale_telemetry::init(consent.with_config_path(Some(store.path().to_path_buf())));
|
||||
let _ = TELEMETRY_SESSION_START.set(std::time::Instant::now());
|
||||
codewhale_telemetry::record(codewhale_telemetry::Event::SessionStart { source });
|
||||
}
|
||||
|
||||
@@ -2531,7 +2580,10 @@ async fn finish_telemetry(outcome: &Result<()>, surface: codewhale_telemetry::Su
|
||||
{
|
||||
codewhale_telemetry::set_exit_class(codewhale_telemetry::ExitClass::Error);
|
||||
}
|
||||
codewhale_telemetry::record_session_end();
|
||||
for event in codewhale_telemetry::session_counters().usage_events() {
|
||||
codewhale_telemetry::record(event);
|
||||
}
|
||||
codewhale_telemetry::record(telemetry_session_end());
|
||||
if surface == codewhale_telemetry::Surface::Cli {
|
||||
let persistence = codewhale_telemetry::persist_local_blocking();
|
||||
logging::info(format!(
|
||||
|
||||
@@ -227,7 +227,7 @@ fn the_session_source_distinguishes_resume_and_fork_from_a_fresh_launch() {
|
||||
|
||||
#[test]
|
||||
fn a_session_end_built_without_arming_writes_nothing() {
|
||||
let event = codewhale_telemetry::session_end_event();
|
||||
let event = telemetry_session_end();
|
||||
assert!(matches!(
|
||||
event,
|
||||
codewhale_telemetry::Event::SessionEnd { .. }
|
||||
|
||||
@@ -1418,9 +1418,6 @@ pub async fn run_tui(
|
||||
// than through it. Only this path calls it, which is what keeps the
|
||||
// cold-start bucket absent on surfaces with no event loop.
|
||||
codewhale_runtime::startup_trace::mark_cold_start();
|
||||
if let Some(millis) = codewhale_runtime::startup_trace::cold_start_ms() {
|
||||
codewhale_telemetry::set_cold_start_ms(millis);
|
||||
}
|
||||
let result = run_event_loop(
|
||||
&mut terminal,
|
||||
&mut app,
|
||||
|
||||
@@ -51,7 +51,7 @@ const SENTINEL_FILENAME: &str = "tc-workspace-sentinel-file.txt";
|
||||
const SENTINEL_PROVIDER_TABLE: &str = "tc_custom_provider_sentinel";
|
||||
const SENTINEL_MCP_SERVER: &str = "tc-mcp-server-sentinel";
|
||||
const SENTINEL_API_KEY: &str = "tc-api-key-sentinel-not-a-real-key";
|
||||
/// Planted by writing to a spool file directly, which is what any other
|
||||
/// Planted by writing to `buffer.jsonl` directly, which is what any other
|
||||
/// process running as this user can do.
|
||||
const SENTINEL_INJECTED: &str = "tc-injected-sentinel-/Users/victim/secret-repo";
|
||||
/// The key lives only in the child's environment, never in a file, so the
|
||||
@@ -279,43 +279,22 @@ async fn assert_no_batches(server: &MockServer, why: &str) {
|
||||
);
|
||||
}
|
||||
|
||||
fn spool_files(fixture: &Fixture) -> Vec<PathBuf> {
|
||||
let Ok(entries) = std::fs::read_dir(fixture.telemetry_root().join("spool")) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut files: Vec<PathBuf> = entries
|
||||
.filter_map(Result::ok)
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| path.extension().is_some_and(|ext| ext == "jsonl"))
|
||||
.collect();
|
||||
files.sort();
|
||||
files
|
||||
}
|
||||
|
||||
fn only_spool_file(fixture: &Fixture) -> Option<PathBuf> {
|
||||
let mut files = spool_files(fixture);
|
||||
(files.len() == 1).then(|| files.remove(0))
|
||||
}
|
||||
|
||||
fn buffered_events(fixture: &Fixture) -> Vec<Value> {
|
||||
let mut events = Vec::new();
|
||||
for path in spool_files(fixture) {
|
||||
let body = std::fs::read_to_string(&path).unwrap_or_else(|error| {
|
||||
panic!(
|
||||
"read locally buffered telemetry at {}: {error}",
|
||||
path.display()
|
||||
)
|
||||
});
|
||||
for line in body.lines().filter(|line| !line.trim().is_empty()) {
|
||||
let value = serde_json::from_str::<Value>(line).unwrap_or_else(|error| {
|
||||
let path = fixture.telemetry_root().join("buffer.jsonl");
|
||||
let body = std::fs::read_to_string(&path).unwrap_or_else(|error| {
|
||||
panic!(
|
||||
"read locally buffered telemetry at {}: {error}",
|
||||
path.display()
|
||||
)
|
||||
});
|
||||
body.lines()
|
||||
.filter(|line| !line.trim().is_empty())
|
||||
.map(|line| {
|
||||
serde_json::from_str::<Value>(line).unwrap_or_else(|error| {
|
||||
panic!("buffered telemetry must be JSON: {error}\nline: {line}")
|
||||
});
|
||||
if value.get("event").is_some() {
|
||||
events.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
events
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn assert_short_cli_persistence_without_network(
|
||||
@@ -401,12 +380,8 @@ async fn incomplete_short_cli_sessions_require_an_explicit_timeout() {
|
||||
let server = start_recorder().await;
|
||||
let fixture = Fixture::new().with_endpoint(&server.uri());
|
||||
std::fs::create_dir_all(fixture.telemetry_root()).expect("create local buffer root");
|
||||
std::fs::create_dir_all(fixture.telemetry_root().join("spool")).expect("create spool dir");
|
||||
std::fs::write(
|
||||
fixture
|
||||
.telemetry_root()
|
||||
.join("spool")
|
||||
.join(format!("{}.jsonl", "a".repeat(32))),
|
||||
fixture.telemetry_root().join("buffer.jsonl"),
|
||||
"{\"event\":\"session_start\",\"source\":\"unknown\"}\n",
|
||||
)
|
||||
.expect("write incomplete session");
|
||||
@@ -870,10 +845,8 @@ async fn a_hostile_buffer_line_never_reaches_a_batch() {
|
||||
let stdout = read_in_background(child.stdout.take().expect("stdout pipe"));
|
||||
let stderr = read_in_background(child.stderr.take().expect("stderr pipe"));
|
||||
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
only_spool_file(&fixture).is_some()
|
||||
});
|
||||
let buffer = only_spool_file(&fixture).expect("this session's spool");
|
||||
let buffer = fixture.telemetry_root().join("buffer.jsonl");
|
||||
wait_until(Duration::from_secs(30), || buffer.exists());
|
||||
append_lines(
|
||||
&buffer,
|
||||
&[
|
||||
@@ -956,10 +929,11 @@ async fn mid_session_opt_out_stops_the_shutdown_flush() {
|
||||
// Wait until this session's event is actually buffered, then leave enough
|
||||
// time for any accidental background flush to reach the recorder. Nothing
|
||||
// may be sent before shutdown.
|
||||
let buffer = fixture.telemetry_root().join("buffer.jsonl");
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
only_spool_file(&fixture)
|
||||
.and_then(|buffer| std::fs::read_to_string(buffer).ok())
|
||||
.is_some_and(|body| body.contains("\"event\":\"session_start\""))
|
||||
std::fs::read_to_string(&buffer)
|
||||
.map(|body| body.contains("\"event\":\"session_start\""))
|
||||
.unwrap_or(false)
|
||||
});
|
||||
tokio::time::sleep(Duration::from_millis(250)).await;
|
||||
assert_no_batches(&server, "before the shutdown flush").await;
|
||||
@@ -1007,7 +981,7 @@ async fn ctrl_c_exits_while_a_second_process_holds_the_lock() {
|
||||
// Arming itself takes the lock, so the holder below must wait until the
|
||||
// session is armed — otherwise this test would pin a deadlock it created.
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
only_spool_file(&fixture).is_some()
|
||||
root.join("buffer.jsonl").exists()
|
||||
});
|
||||
let _holder = LockHolder::take(&lock_path);
|
||||
|
||||
|
||||
+20
-49
@@ -65,11 +65,11 @@ codewhale --telemetry false # the same kill switch, for one command
|
||||
**`telemetry = false` in the config file is the opt-out.** It is a floor:
|
||||
`--telemetry true` and `CODEWHALE_TELEMETRY=1` both lose to it, because a
|
||||
setting you can undo by accident from a wrapper script is not a setting. It
|
||||
deletes the random install id, deletes every spool, truncates every dry-run
|
||||
deletes the random install id, truncates every buffered event and every dry-run
|
||||
record, and writes a tombstone. Appends, identity/state writes, and delivery all
|
||||
share the wipe's ordering lock, so once opt-out returns no pre-opt-out write or
|
||||
POST remains in flight. If any part of that wipe fails, the tombstone is still
|
||||
there and no spool can be sent — a failed wipe fails closed. Every later
|
||||
there and the buffer is undrainable — a failed wipe fails closed. Every later
|
||||
run re-asserts the same tombstone for as long as the setting stands, so it
|
||||
survives. Turning telemetry back on in `/settings` records that explicit preference
|
||||
in both existing privacy registers; a fresh launch can then clear the tombstone. Nothing buffered before that point is
|
||||
@@ -101,21 +101,17 @@ Everything is under `$CODEWHALE_HOME/telemetry/` (`0700`), every file `0600`:
|
||||
|
||||
| file | role |
|
||||
|---|---|
|
||||
| `spool/<nonce>.jsonl` | one running process's pending events: a header line (schema, notice and app version, release sha, surface, whether a terminal), then one JSON object per line |
|
||||
| `spool/<nonce>.lock` | held by that process while it runs; a spool whose lock is free belongs to a process that has ended |
|
||||
| `buffer.jsonl` | pending events, one JSON object per line |
|
||||
| `buffer.jsonl.lock` | the sibling ordering lock shared by writes, delivery, arming, and wipe |
|
||||
| `buffer.jsonl` | left over from older versions; only ever emptied, never written or sent |
|
||||
| `dryrun.jsonl` | where batches go when the endpoint is configured empty |
|
||||
| `state.json` | the last app version seen and the last flush attempt |
|
||||
| `install_id.json` | the random install id and when it was minted |
|
||||
| `disabled` | the tombstone; present means nothing is appended or sent |
|
||||
|
||||
The nonce is random, names a file on your disk and is never sent. Each spool and
|
||||
`dryrun.jsonl` is a ring capped at 512 records (the header counts as one) or
|
||||
256 KiB, whichever comes first, with the oldest events dropped. The documented
|
||||
footprint ceiling is therefore **256 KiB for each running process, 256 KiB for
|
||||
`dryrun.jsonl`, and at most four leftover spools of ended processes kept after
|
||||
each TUI, `exec` or `serve` start**, plus a few hundred bytes of metadata.
|
||||
Both `buffer.jsonl` and `dryrun.jsonl` are rings capped at 512 records or
|
||||
256 KiB, whichever comes first, with the oldest dropped. The documented
|
||||
footprint ceiling for the whole directory is therefore **512 KiB plus a few
|
||||
hundred bytes of metadata**.
|
||||
|
||||
The install id is a random v4 UUID. It is never derived from your hostname,
|
||||
MAC address, `machine-id`, home directory, username, or executable path — a
|
||||
@@ -130,43 +126,18 @@ claim one.
|
||||
## When anything is sent, and where
|
||||
|
||||
Nothing is collected or sent when a persistent opt-out or run-scoped kill
|
||||
switch is in force, or when privacy state is unreadable. TUI and `exec` sessions have one network flush point at a normal end: an attempt
|
||||
during shutdown, bounded at three seconds. That flush sends only the process's
|
||||
own spool, under that process's own surface and version, and deletes it before
|
||||
the request is made. Short CLI commands such as `config`, `doctor`, and `auth`
|
||||
do not wait for that network request. They record `session_end`, seal the event
|
||||
to their own spool with a much shorter bound, and return; the next TUI, `exec`
|
||||
or `serve` start sends what they left (below). An explicitly empty endpoint
|
||||
finalizes its local dry-run batch immediately.
|
||||
switch is in force, or when privacy state is unreadable. TUI and `exec` sessions have exactly one network flush point: an attempt
|
||||
during shutdown, bounded at three seconds. Short CLI commands such as `config`,
|
||||
`doctor`, and `auth` do not wait for that network request. They record
|
||||
`session_end`, seal the event to the local buffer with a much shorter bound, and
|
||||
return; a configured endpoint sends those buffered events with the next
|
||||
interactive shutdown flush. An explicitly empty endpoint finalizes its local
|
||||
dry-run batch immediately.
|
||||
|
||||
A session that is ended early makes one more bounded attempt, so its usage is
|
||||
not lost with it. When a terminating signal (interrupt, terminate, hang-up, or
|
||||
console close) reaches a TUI, `exec` or `serve` session, and when `exec` ends
|
||||
because the program reading its output has closed the pipe, the session records
|
||||
`session_end` with exit class `signal`, then makes one send attempt bounded at
|
||||
one and a half seconds, alongside the process's own shutdown work. A second
|
||||
signal ends the process at once without waiting. This is the same single `POST`
|
||||
of the same fields, never retried. Short CLI commands stay local-only on this
|
||||
path too.
|
||||
|
||||
A session that ends without any report (killed outright, a power loss, a crash
|
||||
before the handler runs) leaves its spool behind. When a later TUI, `exec` or
|
||||
`serve` session starts, it sends the leftovers once: at most four, newest first,
|
||||
one `POST` per leftover session, each carrying that session's own surface and
|
||||
app version and this installation's current install id and send time. Each
|
||||
leftover is deleted before its request is made and is never retried. A leftover
|
||||
older than seven days, one beyond the newest four, one written by a build with a
|
||||
different schema or notice version, and any line that fails the schema bounds is
|
||||
deleted without being sent. Consent and the opt-out tombstone are checked
|
||||
before anything is read and again before each request, and the request runs on
|
||||
its own thread so it never delays your session. Opting out deletes every spool.
|
||||
Opting back in starts without any spool from before.
|
||||
|
||||
There is no mid-session flush, per-turn flush, or per-tool-call
|
||||
flush. Every network flush re-resolves your setting from disk
|
||||
There is no startup flush, mid-session flush, per-turn flush, or per-tool-call
|
||||
flush. Every network shutdown flush re-resolves your setting from disk
|
||||
immediately beforehand, so `codewhale config set telemetry false` written from
|
||||
another terminal stops the flush of a session that is already running, including
|
||||
one that is being terminated.
|
||||
another terminal stops the flush of a session that is already running.
|
||||
|
||||
A flush is **one `POST`** to the resolved endpoint — by default
|
||||
`https://telemetry.codewhale.net/v1/telemetry`. The request carries a
|
||||
@@ -235,7 +206,7 @@ new fields, surfaces, and `product_usage` events.
|
||||
| `arch` | enum | `std::env::consts::ARCH` | `x86_64 \| aarch64 \| other`. |
|
||||
| `libc` | enum | `cfg!(target_env)` — **compile time** | `gnu \| musl \| none`. Runtime detection reads distro vendor strings; compile-time is free and leaks nothing. |
|
||||
| `tty` | bool | `std::io::IsTerminal`, as at `crates/telemetry/src/envelope.rs:196` | `stdin().is_terminal() && stdout().is_terminal()`. |
|
||||
| `events` | array | the process's spool | Every element is one of the six events below and nothing else. Capped at 200 events or 64 KiB per batch; events beyond either cap are dropped with the spool, never carried to a later flush. |
|
||||
| `events` | array | the drained buffer | Every element is one of the six events below and nothing else. Capped at 200 events or 64 KiB per batch; a batch that would exceed either cap leaves the remainder buffered for the next flush. |
|
||||
|
||||
**`os_major` is not collected.** Reading it costs unsafe FFI on two platforms plus a file parser on a third, in the one crate whose entire value is being small enough to audit — and `os`, `arch`, and `libc` are free and answer the platform question. It may be reconsidered if the stored data ever shows that the OS-version cut is what triage is missing; a hunch is not that evidence.
|
||||
|
||||
@@ -346,7 +317,7 @@ The workhorse. Everything a session accumulated ships here, once.
|
||||
|
||||
**`duration_bucket`** — `chrono` delta from `app.session_started_at` (`crates/tui/src/tui/app.rs:1889`). Half-open, seconds: `lt_1m` (`d < 60`), `1m_10m` (`60 ≤ d < 600`), `10m_60m` (`600 ≤ d < 3600`), `gt_60m` (`d ≥ 3600`).
|
||||
|
||||
**`exit_class`** — `clean | signal | panic | error`. **Derived from an explicit `AtomicU8`, never from an exit code.** `RunTerminationReason::Canceled` maps to exit 130 (`crates/engine/src/core/runtime_contract/termination.rs:53`), the same value the signal task uses (`crates/tui/src/lib.rs:682`, 128+SIGINT), so a code-based derivation would report every Esc-cancelled turn as a signal. The atomic is set by the panic hook (`crates/tui/src/lib.rs:1582`), by the signal task when the first signal arrives, by `exec` when its output pipe closes, and on the clean path from `RunTerminationReason::is_success()` (`crates/engine/src/core/runtime_contract/termination.rs:44-46`) — `error` otherwise. Exit codes remain insufficient: an approval-required exit (3) and a terminal exec failure (1) need their actual termination classification.
|
||||
**`exit_class`** — `clean | signal | panic | error`. **Derived from an explicit `AtomicU8`, never from an exit code.** `RunTerminationReason::Canceled` maps to exit 130 (`crates/engine/src/core/runtime_contract/termination.rs:53`), the same value the signal task uses (`crates/tui/src/lib.rs:682`, 128+SIGINT), so a code-based derivation would report every Esc-cancelled turn as a signal. The atomic is set by the panic hook (`crates/tui/src/lib.rs:1582`), by the signal task (`:678-696`) before `std::process::exit`, and on the clean path from `RunTerminationReason::is_success()` (`crates/engine/src/core/runtime_contract/termination.rs:44-46`) — `error` otherwise. Exit codes remain insufficient: an approval-required exit (3) and a terminal exec failure (1) need their actual termination classification.
|
||||
|
||||
**`cold_start_bucket`** — from `startup_trace::elapsed_ms()`, which reads `PROCESS_START` directly and is independent of the startup summary's buffer clear (`crates/runtime/src/startup_trace.rs:39-45`). Boundaries: `lt_250`, `250_1000`, `1000_3000`, `gte_3000`. Absent on non-TUI surfaces.
|
||||
|
||||
@@ -570,7 +541,7 @@ is established by this source change.
|
||||
|
||||
`install_id` rotates client-side every 90 days (`rotated_at` in `install_id.json`), so no single identifier spans a long history. This costs longitudinal accuracy and the docs say so: **no count derived from `install_id` is a user count.** It is a lower bound on distinct machine-installs in a window, and it undercounts a returning user across a rotation.
|
||||
|
||||
**Turning it off deletes what was kept locally, not what was already sent.** `codewhale config set telemetry false` erases the install id, every spool, and the dry-run records on your machine, and stops anything further. Rows already accepted by the endpoint are keyed only by a rotating random id that is now gone; first-party rows age out with the three-month window. If PostHog processing is activated, already-delivered processor records follow that project’s configured retention. The client has no remote deletion API and does not claim that local opt-out erases delivered records.
|
||||
**Turning it off deletes what was kept locally, not what was already sent.** `codewhale config set telemetry false` erases the install id, the buffer, and the dry-run records on your machine, and stops anything further. Rows already accepted by the endpoint are keyed only by a rotating random id that is now gone; first-party rows age out with the three-month window. If PostHog processing is activated, already-delivered processor records follow that project’s configured retention. The client has no remote deletion API and does not claim that local opt-out erases delivered records.
|
||||
|
||||
### What the owner reads back — observed active installs
|
||||
|
||||
|
||||
@@ -259,8 +259,8 @@
|
||||
},
|
||||
{
|
||||
"path": "docs/TELEMETRY.md",
|
||||
"sha256": "6ecccb66215a6aae5076cd00735028c10a50ce6e5902ce4151a9606ee86696a9",
|
||||
"content": "# Codewhale product telemetry\n\n> 阅读简体中文版:[zh_hans/TELEMETRY.md](zh_hans/TELEMETRY.md)\n\n**Usage analytics are on by default in the current source.** The first\ninteractive launch gives a localized, nonblocking disclosure naming **Codewhale\nand PostHog**, with a direct route to turn counting off. Notice version `6`\ndescribes this policy; displaying it is not recorded as human acceptance.\nMissing an older acceptance record does not turn a fresh installation off.\nExisting explicit opt-outs remain off across upgrades, and unreadable privacy\nstate fails closed. Environment and CLI kill switches still take precedence.\n\nRead the disclosure with `codewhale config telemetry`. Turn usage off in\n`/settings` or run `codewhale config set telemetry false`. Turning it back on\nin Settings or with `codewhale config set telemetry true` updates the existing\ndurable preference and privacy records for new sessions. The compatibility\ncommand `codewhale config telemetry --accept-notice 5` remains available, but\nis not required for a fresh installation. Collection never includes work content or credentials.\n\nThe PostHog sink is optional and inert until the ingest operator explicitly\nconfigures a project token and approved regional host, and records staging\nproof that the actual egress path does not forward the original client IP.\nSource readiness does not establish a deployment, an activated processor,\nan egress receipt, or a retention setting.\n\nCodewhale does not collect conversations, code, prompts, files, file/repo/branch\nnames, model content, or credentials. It sends no per-turn or per-tool timeline.\nIt does send the closed, aggregate schema below: version and platform classes,\nsession duration/outcome, feature/error counters, and a random install id that\nrotates every 90 days.\n\n**There is now a real endpoint.** An enabled session sends its batches to the\nfirst-party ingest service at `https://telemetry.codewhale.net/v1/telemetry`,\nwhich is the shipped default for `telemetry_endpoint`. What that service is,\nwhat it stores, and what it structurally cannot store is spelled out in \"What\nthe endpoint does\" below.\n\n**To send nothing anywhere, turn telemetry off** (see \"Turning it off\"). To stay\nenabled but contact nobody, set `telemetry_endpoint = \"\"`: batches are then\nappended to `$CODEWHALE_HOME/telemetry/dryrun.jsonl` on your own machine, byte\nfor byte what the server would have received, and no HTTP client is ever\nconstructed. That file is how you audit this document against reality.\n\nThis document is the schema. It is not a summary of the schema: a test in\n`crates/telemetry` parses the field names out of this file and asserts set\nequality against the structs the serializer actually uses, so a field that is\nhere and not in the code — or in the code and not here — fails the build.\n\nLocal saved sessions and `codewhale metrics` remain available with telemetry\ndisabled and require no account or hosted reporting service. Disabling telemetry\ndoes not disable local usage receipts.\n\n## Turning it off\n\nThere are two off switches and they do different things. Both stop collection\ncompletely; only one of them erases anything.\n\n```sh\ncodewhale config set telemetry false # opt out: stops collection and erases state\nCODEWHALE_TELEMETRY=0 codewhale # kill switch: stops collection, erases nothing\nDO_NOT_TRACK=1 codewhale # the same kill switch, by the common convention\ncodewhale --telemetry false # the same kill switch, for one command\n```\n\n**`telemetry = false` in the config file is the opt-out.** It is a floor:\n`--telemetry true` and `CODEWHALE_TELEMETRY=1` both lose to it, because a\nsetting you can undo by accident from a wrapper script is not a setting. It\ndeletes the random install id, deletes every spool, truncates every dry-run\nrecord, and writes a tombstone. Appends, identity/state writes, and delivery all\nshare the wipe's ordering lock, so once opt-out returns no pre-opt-out write or\nPOST remains in flight. If any part of that wipe fails, the tombstone is still\nthere and no spool can be sent — a failed wipe fails closed. Every later\nrun re-asserts the same tombstone for as long as the setting stands, so it\nsurvives. Turning telemetry back on in `/settings` records that explicit preference\nin both existing privacy registers; a fresh launch can then clear the tombstone. Nothing buffered before that point is\never sent.\n\n**The environment variable and the flag are kill switches, not opt-outs.**\nTelemetry is off for the run, nothing is written, nothing is sent — and\nnothing on disk is touched or deleted. That is deliberate: a harness or agent\nthat sets `CODEWHALE_TELEMETRY=0` for one command must not silently discard the\ninstall id and the dry-run records of the person who owns the machine. If you\nwant the erasing kind, use the config file.\n\n`CODEWHALE_TELEMETRY` (andLine truncated
|
||||
"sha256": "0ac65dbd0e1d9d196d1c4421116852c3ab6a855062c375c25b09db993084c563",
|
||||
"content": "# Codewhale product telemetry\n\n> 阅读简体中文版:[zh_hans/TELEMETRY.md](zh_hans/TELEMETRY.md)\n\n**Usage analytics are on by default in the current source.** The first\ninteractive launch gives a localized, nonblocking disclosure naming **Codewhale\nand PostHog**, with a direct route to turn counting off. Notice version `6`\ndescribes this policy; displaying it is not recorded as human acceptance.\nMissing an older acceptance record does not turn a fresh installation off.\nExisting explicit opt-outs remain off across upgrades, and unreadable privacy\nstate fails closed. Environment and CLI kill switches still take precedence.\n\nRead the disclosure with `codewhale config telemetry`. Turn usage off in\n`/settings` or run `codewhale config set telemetry false`. Turning it back on\nin Settings or with `codewhale config set telemetry true` updates the existing\ndurable preference and privacy records for new sessions. The compatibility\ncommand `codewhale config telemetry --accept-notice 5` remains available, but\nis not required for a fresh installation. Collection never includes work content or credentials.\n\nThe PostHog sink is optional and inert until the ingest operator explicitly\nconfigures a project token and approved regional host, and records staging\nproof that the actual egress path does not forward the original client IP.\nSource readiness does not establish a deployment, an activated processor,\nan egress receipt, or a retention setting.\n\nCodewhale does not collect conversations, code, prompts, files, file/repo/branch\nnames, model content, or credentials. It sends no per-turn or per-tool timeline.\nIt does send the closed, aggregate schema below: version and platform classes,\nsession duration/outcome, feature/error counters, and a random install id that\nrotates every 90 days.\n\n**There is now a real endpoint.** An enabled session sends its batches to the\nfirst-party ingest service at `https://telemetry.codewhale.net/v1/telemetry`,\nwhich is the shipped default for `telemetry_endpoint`. What that service is,\nwhat it stores, and what it structurally cannot store is spelled out in \"What\nthe endpoint does\" below.\n\n**To send nothing anywhere, turn telemetry off** (see \"Turning it off\"). To stay\nenabled but contact nobody, set `telemetry_endpoint = \"\"`: batches are then\nappended to `$CODEWHALE_HOME/telemetry/dryrun.jsonl` on your own machine, byte\nfor byte what the server would have received, and no HTTP client is ever\nconstructed. That file is how you audit this document against reality.\n\nThis document is the schema. It is not a summary of the schema: a test in\n`crates/telemetry` parses the field names out of this file and asserts set\nequality against the structs the serializer actually uses, so a field that is\nhere and not in the code — or in the code and not here — fails the build.\n\nLocal saved sessions and `codewhale metrics` remain available with telemetry\ndisabled and require no account or hosted reporting service. Disabling telemetry\ndoes not disable local usage receipts.\n\n## Turning it off\n\nThere are two off switches and they do different things. Both stop collection\ncompletely; only one of them erases anything.\n\n```sh\ncodewhale config set telemetry false # opt out: stops collection and erases state\nCODEWHALE_TELEMETRY=0 codewhale # kill switch: stops collection, erases nothing\nDO_NOT_TRACK=1 codewhale # the same kill switch, by the common convention\ncodewhale --telemetry false # the same kill switch, for one command\n```\n\n**`telemetry = false` in the config file is the opt-out.** It is a floor:\n`--telemetry true` and `CODEWHALE_TELEMETRY=1` both lose to it, because a\nsetting you can undo by accident from a wrapper script is not a setting. It\ndeletes the random install id, truncates every buffered event and every dry-run\nrecord, and writes a tombstone. Appends, identity/state writes, and delivery all\nshare the wipe's ordering lock, so once opt-out returns no pre-opt-out write or\nPOST remains in flight. If any part of that wipe fails, the tombstone is still\nthere and the buffer is undrainable — a failed wipe fails closed. Every later\nrun re-asserts the same tombstone for as long as the setting stands, so it\nsurvives. Turning telemetry back on in `/settings` records that explicit preference\nin both existing privacy registers; a fresh launch can then clear the tombstone. Nothing buffered before that point is\never sent.\n\n**The environment variable and the flag are kill switches, not opt-outs.**\nTelemetry is off for the run, nothing is written, nothing is sent — and\nnothing on disk is touched or deleted. That is deliberate: a harness or agent\nthat sets `CODEWHALE_TELEMETRY=0` for one command must not silently discard the\ninstall id and the dry-run records of the person who owns the machine. If you\nwant the erasing kind, use the config file.\n\n`CODEWHALE_TELEMELine truncated
|
||||
},
|
||||
{
|
||||
"path": "docs/public-surface-facts.json",
|
||||
|
||||
@@ -35,7 +35,6 @@ export const RELEASE_CONTRIBUTORS: string[] = [
|
||||
"@luochen211",
|
||||
"@gannp",
|
||||
"@Felixkw12",
|
||||
"@MannXo",
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -43,7 +42,7 @@ export const RELEASE_CONTRIBUTORS: string[] = [
|
||||
* one. scripts/check-contributor-credit.py requires them here now; the release
|
||||
* cut moves them into RELEASE_CONTRIBUTORS with that release's changelog block.
|
||||
*/
|
||||
export const UNRELEASED_CONTRIBUTORS: string[] = ["@luochen211", "@Lstarsky0", "@SamhandsomeLee", "@gaord"];
|
||||
export const UNRELEASED_CONTRIBUTORS: string[] = ["@luochen211", "@Lstarsky0", "@SamhandsomeLee", "@gaord", "@MannXo"];
|
||||
|
||||
/**
|
||||
* Contributors who helped with reports, reproductions, and verification.
|
||||
|
||||
Reference in new issue
Block a user