Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3f9d938
fix(settings): keep saved sources, plugin state and sign-ins a newer …
Mavrick-F Nov 13, 2026
af475cf
fix(settings): refuse before changing a plugin, keep a web plugin's u…
Mavrick-F Nov 14, 2026
5c1205a
fix(settings): say what cleaning changed in an address, keep stored s…
Mavrick-F Nov 14, 2026
7a72ab7
fix(settings): classify a source's unknown fields on the whole object…
Mavrick-F Nov 14, 2026
6525bd4
fix(settings): a source listed twice is one source, merged at load; a…
Mavrick-F Nov 14, 2026
ea1a7f2
fix(engine,assistant): count cleared login bindings, refuse odd store…
Mavrick-F Nov 14, 2026
88fccc4
Merge upstream/main into fix/settings-preserve-sources-plugins
Mavrick-F Nov 14, 2026
add3f83
fix(plugins): load no plugins while state.json can't be read
Mavrick-F Nov 14, 2026
b3f2e37
Merge upstream/main into fix/settings-preserve-sources-plugins
Mavrick-F Nov 14, 2026
d81b76d
fix(engine,ui): forgetting a source drops its kept over-limit row; co…
Mavrick-F Nov 14, 2026
54e3bc6
refactor(engine): one identity for saved sources; a repeated row is d…
Mavrick-F Nov 14, 2026
d71cb05
fix(plugins): an empty state.json is nothing disabled, as a missing one
Mavrick-F Nov 14, 2026
8bc93e0
fix(engine): forgetting a source kept only past the list's limit coun…
Mavrick-F Nov 14, 2026
eda708f
fix(engine): check kept fields again when a source's details change; …
Mavrick-F Nov 14, 2026
4adf225
fix(engine, plugins): say a secret left out when a source changes; a …
Mavrick-F Nov 14, 2026
a0a78ae
fix(engine): every way of recording a recent source says a secret it …
Mavrick-F Nov 14, 2026
073592c
fix(engine, plugins): a byte-order mark in saved sources reads as JSO…
Mavrick-F Nov 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion crates/assistant/src/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,31 @@ mod native {
}
}

/// The sign-in store at `path` (none: no account). One that isn't JSON, or that a newer
/// RustGIS saved (a `version` above [`STORE_VERSION`]), is an error: every change reads it
/// first, so it is never written over.
fn read_accounts(path: &Path) -> Result<Accounts, Error> {
let text = match std::fs::read_to_string(path) {
Ok(text) => text,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(Accounts::default()),
Err(e) => return Err(e.to_string().into()),
};
let v: Value = serde_json::from_str(text.trim_start_matches('\u{feff}')).map_err(|_| "the sign-in store isn't JSON")?;
// One a newer RustGIS wrote may hold what this version would lose by writing it again: it
// is neither used nor written over.
match v.get("version").map(|version| version.as_u64().ok_or(version)) {
Some(Ok(version)) if version > STORE_VERSION => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Never silent (low-medium confidence): a newer store reads as signed out with only a log line. This refusal reaches load_any_at, which on Err calls log::warn! and then falls back to read_accounts(path).ok()?. That fallback fails again for a newer store, so load() returns None. The account looks signed out, and the reason only appears if the user tries to sign in. log::warn! doesn't count as a notice under AGENTS.md.

Suggested fix: report the refusal to the user through Session::notify or the existing error path, once per session, from the code that calls load() for UI state. Add a test that the newer-version refusal is shown where the user sees it, not only in the log.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changed in this round: a refused or newer store reaches the user only through the log because load_any returns an Option to its callers (the assistant pane reads it on a worker). Showing it as a notice needs a new way to carry the refusal out of chatgpt, which is more than a local change here; the maintainer will decide whether it is done here or separately.

return Err(Error::new(
Recovery::Auth,
format!(
"the ChatGPT sign-ins were saved by a newer RustGIS (version {version}; this one reads {STORE_VERSION}): use that RustGIS, or update this one"
),
));
}
// A version that isn't a plain integer can't be told from a newer one's.
Some(Err(_)) => return Err("the sign-in store's version isn't a whole number".into()),
_ => {}
}
if let Some(entries) = v.get("accounts").and_then(Value::as_array) {
let entries = entries.iter().map(Credentials::from_json).collect::<Result<Vec<_>, _>>()?;
let active =
Expand All @@ -857,6 +875,11 @@ mod native {
}
}

/// The version of the sign-in store this RustGIS reads and writes.
const STORE_VERSION: u64 = 2;

/// Writes the sign-in store as version [`STORE_VERSION`], without tokens except a settings
/// file's own from before the keychain.
fn write_accounts(path: &Path, accounts: &Accounts) -> Result<(), Error> {
let active = accounts.active.as_ref().map(|(client, subject)| serde_json::json!({"client_id": client, "subject": subject}));
let entry = |c: &Credentials| {
Expand All @@ -871,7 +894,7 @@ mod native {
};
write_private(
path,
&serde_json::json!({"version": 2, "active": active, "accounts": accounts.entries.iter().map(entry).collect::<Vec<_>>()})
&serde_json::json!({"version": STORE_VERSION, "active": active, "accounts": accounts.entries.iter().map(entry).collect::<Vec<_>>()})
.to_string(),
)
}
Expand Down Expand Up @@ -2023,6 +2046,35 @@ mod native {
assert!(remove_at(&path, &v, "oaiapp_other", "user-1").unwrap().is_none());
}

/// A store a newer RustGIS saved is neither used nor written over, whatever is asked of it.
#[test]
fn a_store_from_a_newer_version_is_kept_as_it_is() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("auth.json");
let store = Arc::new(MemorySecrets::new());
let v = sharing(&store);
write_credentials(&path, &v, &synthetic(now() + 100_000)).unwrap();
let mut newer: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
newer["version"] = serde_json::json!(3);
newer["devices"] = serde_json::json!([{"id": "d1"}]);
let text = newer.to_string();
std::fs::write(&path, &text).unwrap();
let e = read_accounts(&path).err().unwrap();
assert!(e.to_string().contains("newer RustGIS (version 3; this one reads 2)"), "{e}");
assert!(read_credentials(&path, &v).is_err());
assert!(write_credentials(&path, &v, &synthetic(now() + 100_000)).is_err());
assert!(sign_out_at(&path, &v).is_err());
assert!(remove_at(&path, &v, "oaiapp_synthetic", "user-1").is_err());
assert_eq!(std::fs::read_to_string(&path).unwrap(), text);
// A version that isn't a plain integer is unreadable, not newer-or-not.
for odd in [serde_json::json!("3"), serde_json::json!(3.0), serde_json::json!(true)] {
let mut v: Value = serde_json::from_str(&text).unwrap();
v["version"] = odd;
std::fs::write(&path, v.to_string()).unwrap();
assert!(read_accounts(&path).is_err());
}
}

#[test]
fn an_unreadable_keychain_signs_out_here_and_keeps_its_item_noted() {
let dir = tempfile::tempdir().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions crates/engine/src/cmd/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ fn source(p: &Value) -> Result<Source, String> {

fn keep(s: &mut Session, p: &Value, list: &str) -> CmdResult {
let src = source(p)?;
let before = s.sources.secrets_left_out();
let kept = s.sources.keep(list, src)?;
let left_out = s.sources.secrets_left_out().saturating_sub(before);
if left_out > 0 {
s.notify(crate::sources::secrets_notice(left_out), false);
}
Ok(shown(&kept))
}

Expand Down
13 changes: 12 additions & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ impl Session {
if res.is_ok()
&& let Some(src) = sources::added_by(id, params)
{
self.sources.note(src);
self.note_source(src);
}
res
}
Expand Down Expand Up @@ -2341,6 +2341,17 @@ impl Session {
started
}

/// Records `src` in the Data Sources pane's Recent list ([`sources::Sources::note`]), and says
/// any value it left out because, beside the source as now listed, it holds a secret.
pub fn note_source(&mut self, src: sources::Source) {
let before = self.sources.secrets_left_out();
self.sources.note(src);
let left_out = self.sources.secrets_left_out().saturating_sub(before);
if left_out > 0 {
self.notify(sources::secrets_notice(left_out), false);
}
}

pub fn notify(&mut self, text: impl Into<String>, error: bool) {
use rustgis_data::diagnostics::Severity;
self.notice(text.into(), if error { Severity::Error } else { Severity::Info });
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/policy/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Session {
if result.is_ok()
&& let Some(source) = crate::sources::added_by(command, &params)
{
s.sources.note(source);
s.note_source(source);
}
result
})?
Expand Down
Loading
Loading