Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
44486eb
refactor(store): read the command-pack activation slot in the native …
internet-dot Nov 22, 2026
eecc8f9
fix(store): refuse a non-text activation slot state
internet-dot Nov 22, 2026
4655765
fix(store): share the schema marker check between the authority write…
internet-dot Nov 22, 2026
e46f559
refactor(store): check the extension control schema marker in the nat…
internet-dot Nov 22, 2026
da4f585
refactor(store): name a refused activation slot's error code in the n…
internet-dot Nov 22, 2026
f21bbdd
Merge remote-tracking branch 'origin/feat/native-runtime-slice42' int…
internet-dot Nov 22, 2026
641ef32
chore(contracts): map the extension control schema reader in the owne…
internet-dot Nov 22, 2026
75d0b3c
refactor(store): read the committed extension control snapshot in the…
internet-dot Nov 22, 2026
a458375
refactor(store): resume transitions and read the upgrade's activation…
internet-dot Nov 22, 2026
da84eed
refactor(store): read the cache cleanup's activation records in the n…
internet-dot Nov 22, 2026
5b33acb
refactor(store): read the pack migration's legacy evidence in the nat…
internet-dot Nov 22, 2026
5fd5359
refactor(store): read the extension control head for recovery in the …
internet-dot Nov 22, 2026
e918ad2
test(store): expect the snapshot layers read on the snapshot route
internet-dot Nov 22, 2026
ec4ca4f
Merge branch 'feat/native-runtime-slice46' into feat/native-runtime-s…
internet-dot Nov 22, 2026
7591d83
Merge branch 'feat/native-runtime-slice47' into feat/native-runtime-s…
internet-dot Nov 22, 2026
7331033
test(store): expect the new native reads on the snapshot route
internet-dot Nov 22, 2026
534b718
Merge branch 'feat/native-runtime-slice48' into feat/native-runtime-s…
internet-dot Nov 22, 2026
b51fd89
test(store): expect the new native reads on the snapshot route
internet-dot Nov 22, 2026
612e982
test(store): expect the new native reads on the snapshot route
internet-dot Nov 22, 2026
65af8ba
refactor(store): read catalog migration events and the pack baseline …
internet-dot Nov 22, 2026
ca4fdab
Merge remote-tracking branch 'origin/main' into feat/native-runtime-s…
internet-dot Nov 22, 2026
5a772eb
fix(store): read the snapshot on the shared connection inside an MCP …
internet-dot Nov 22, 2026
95b5127
fix(store): read the extension control head on the shared connection …
internet-dot Nov 22, 2026
3205f81
Merge branch 'feat/native-runtime-slice46' into feat/native-runtime-s…
internet-dot Nov 22, 2026
91cd8c8
Merge branch 'feat/native-runtime-slice47' into feat/native-runtime-s…
internet-dot Nov 22, 2026
b21a067
Merge branch 'feat/native-runtime-slice48' into feat/native-runtime-s…
internet-dot Nov 22, 2026
a891ce5
Merge branch 'feat/native-runtime-slice49' into feat/native-runtime-s…
internet-dot Nov 22, 2026
651c53c
fix(store): budget legacy history pages on the encoded reply and stop…
internet-dot Nov 22, 2026
20295bf
fix(store): answer the scoped extension control head read as the nati…
internet-dot Nov 22, 2026
3e0f05e
Merge remote-tracking branch 'origin/feat/native-runtime-slice48' int…
internet-dot Nov 22, 2026
73bb6a0
Merge remote-tracking branch 'origin/feat/native-runtime-slice49' int…
internet-dot Nov 22, 2026
2864e9c
docs(guard): record the scoped extension control reads as a temporary…
internet-dot Nov 22, 2026
e3f414f
Merge remote-tracking branch 'origin/feat/native-runtime-slice49' int…
internet-dot Nov 22, 2026
6b624ed
fix(store): let an unusable anchor revision select no legacy pending row
internet-dot Nov 22, 2026
0297abf
Merge remote-tracking branch 'origin/feat/native-runtime-slice48' int…
internet-dot Nov 22, 2026
8ffd933
Merge remote-tracking branch 'origin/feat/native-runtime-slice49' int…
internet-dot Nov 22, 2026
667a34a
test(store): answer the pending-record list in the activation fixture…
internet-dot Nov 22, 2026
3ae77a5
Merge remote-tracking branch 'origin/feat/native-runtime-slice47' int…
internet-dot Nov 22, 2026
d199c1a
Merge remote-tracking branch 'origin/feat/native-runtime-slice48' int…
internet-dot Nov 22, 2026
b216d67
Merge remote-tracking branch 'origin/feat/native-runtime-slice49' int…
internet-dot Nov 22, 2026
1ec6934
Merge remote-tracking branch 'origin/main' into feat/native-runtime-s…
internet-dot Nov 22, 2026
6e1db5c
Merge remote-tracking branch 'origin/main' into feat/native-runtime-s…
internet-dot Nov 22, 2026
d673b1d
fix(store): page the pending command-pack records so cleanup reads ev…
internet-dot Nov 22, 2026
c6d2630
Merge remote-tracking branch 'origin/main' into feat/native-runtime-s…
internet-dot Nov 22, 2026
2a7b288
Merge branch 'feat/native-runtime-slice49' of https://github.com/hash…
internet-dot Nov 22, 2026
160c681
merge(main): resolve command pack slot conflicts
internet-dot Nov 22, 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
Prev Previous commit
Next Next commit
refactor(store): read the extension control head for recovery in the …
…native store
  • Loading branch information
internet-dot committed Nov 22, 2026
commit 5fd53591d70d27f89e9497f95d9ccafd69edafbd
1 change: 1 addition & 0 deletions docs/guard/contracts/hook-data-plane-ownership.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
"src/codex_plugin_scanner/guard/native_policy_integrity_rows.py",
"src/codex_plugin_scanner/guard/native_extension_control_schema.py",
"src/codex_plugin_scanner/guard/native_extension_control_snapshot.py",
"src/codex_plugin_scanner/guard/native_extension_control_head.py",
Comment thread
internet-dot marked this conversation as resolved.
Resolved
"src/codex_plugin_scanner/guard/native_approval_resolution.py",
"src/codex_plugin_scanner/guard/native_approval_queue_identity.py",
"src/codex_plugin_scanner/guard/native_tool_action_identity.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ const SLOT_FIELDS: [&str; 5] = [
mod command_pack_legacy_evidence;
#[path = "guard_store_command_pack_pending.rs"]
mod command_pack_pending;
#[path = "guard_store_extension_control_head.rs"]
mod extension_control_head;
#[path = "guard_store_extension_control_snapshot.rs"]
mod extension_control_snapshot;

pub(crate) fn handles(method: &str) -> bool {
extension_control_snapshot::handles(method)
|| command_pack_pending::handles(method)
|| command_pack_legacy_evidence::handles(method)
|| extension_control_head::handles(method)
|| matches!(
method,
"read_command_pack_activation" | "extension_control_schema_state"
Expand All @@ -56,6 +59,9 @@ pub(crate) fn dispatch(
args: &Args<'_>,
) -> StoreResult<Value> {
match method {
_ if extension_control_head::handles(method) => {
extension_control_head::dispatch(connection, method, args)
}
_ if command_pack_legacy_evidence::handles(method) => {
command_pack_legacy_evidence::dispatch(connection, method, args)
}
Expand Down
115 changes: 115 additions & 0 deletions rust/crates/guard-runtime/src/guard_store_extension_control_head.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//! The committed extension-control head and its transitions, read for recovery.
//!
//! Port of the SQL reads the authority recovery, the persisted-authority
//! reader and the legacy secret migration check ran on their own SQLite
//! connection after the schema check:
//!
//! - `extension_control_snapshot_head` answers the snapshot row's revision,
//! snapshot digest and catalog digest, or `{"snapshot": null}` when there
//! is no row (or no snapshot table yet). A cell of the wrong type answers
//! `null` in its place so the caller refuses the row.
//! - `extension_control_recovery_transition` answers the revision of the
//! transition recovery must resume: one at the head revision that never
//! committed, or the one after it.
//! - `extension_control_transition_committed` answers whether the head
//! revision's transition committed.
//!
//! A store without the transition table has no transitions.

use rusqlite::Connection;
use serde_json::{json, Value};

use crate::guard_store_args::Args;
use crate::guard_store_db::{query_one, StoreResult};
use crate::guard_store_local_cli_inventory::table_exists;

const HEAD: &str = "extension_control_snapshot_head";
const RECOVERY: &str = "extension_control_recovery_transition";
const COMMITTED: &str = "extension_control_transition_committed";
const SNAPSHOT_TABLE: &str = "extension_control_authority_snapshot";
const TRANSITION_TABLE: &str = "extension_control_authority_transition";
const COMMITTED_PHASE: &str = "committed";

pub(crate) fn handles(method: &str) -> bool {
matches!(method, HEAD | RECOVERY | COMMITTED)
}

pub(crate) fn dispatch(
connection: &Connection,
method: &str,
args: &Args<'_>,
) -> StoreResult<Value> {
match method {
RECOVERY => recovery_transition(connection, args.int("revision")?),
COMMITTED => committed(connection, args.int("revision")?),
_ => head(connection),
}
}

fn head(connection: &Connection) -> StoreResult<Value> {
if !table_exists(connection, SNAPSHOT_TABLE)? {
return Ok(json!({"snapshot": null}));
}
let row = query_one(
connection,
&format!(
"select case when typeof(revision) = 'integer' then revision end as revision, \
case when typeof(snapshot_digest) = 'text' then snapshot_digest end \
as snapshot_digest, \
case when typeof(catalog_digest) = 'text' then catalog_digest end \
as catalog_digest \
from {SNAPSHOT_TABLE} where singleton = 1"
),
&[],
)?;
Ok(match row {
None => json!({"snapshot": null}),
Some(row) => {
let cell = |name: &str| row.get(name).cloned().unwrap_or(Value::Null);
json!({"snapshot": {
"revision": cell("revision"),
"snapshot_digest": cell("snapshot_digest"),
"catalog_digest": cell("catalog_digest"),
}})
}
})
}

fn recovery_transition(connection: &Connection, revision: i64) -> StoreResult<Value> {
if !table_exists(connection, TRANSITION_TABLE)? {
return Ok(json!({"revision": null}));
}
let row = query_one(
connection,
&format!(
"select revision from {TRANSITION_TABLE} \
where (revision = ?1 and phase != ?2) or revision = ?3 \
order by revision limit 1"
),
&[
Value::from(revision),
Value::from(COMMITTED_PHASE),
Value::from(revision.saturating_add(1)),
],
)?;
let found = row
.and_then(|row| row.get("revision").filter(|value| value.is_i64()).cloned())
.unwrap_or(Value::Null);
Ok(json!({"revision": found}))
}

fn committed(connection: &Connection, revision: i64) -> StoreResult<Value> {
if !table_exists(connection, TRANSITION_TABLE)? {
return Ok(json!({"committed": false}));
}
let row = query_one(
connection,
&format!("select 1 as found from {TRANSITION_TABLE} where revision = ?1 and phase = ?2"),
&[Value::from(revision), Value::from(COMMITTED_PHASE)],
)?;
Ok(json!({"committed": row.is_some()}))
}

#[cfg(test)]
#[path = "guard_store_extension_control_head_tests.rs"]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
use rusqlite::{params, Connection};
use serde_json::{json, Map, Value};

use super::{dispatch, handles};
use crate::guard_store_args::Args;
use crate::guard_store_op_kind::{method_kind, Kind};

const METHODS: [&str; 3] = [
"extension_control_snapshot_head",
"extension_control_recovery_transition",
"extension_control_transition_committed",
];

fn store() -> Connection {
Connection::open_in_memory().expect("memory store")
}

fn schema(connection: &Connection) {
connection
.execute_batch(
"create table extension_control_authority_snapshot ( \
singleton integer primary key, revision, catalog_digest, snapshot_digest); \
create table extension_control_authority_transition ( \
revision integer primary key, phase text not null);",
)
.expect("schema");
}

fn transition(connection: &Connection, revision: i64, phase: &str) {
connection
.execute(
"insert into extension_control_authority_transition values (?1, ?2)",
params![revision, phase],
)
.expect("transition");
}

fn call(connection: &Connection, method: &str, args: Value) -> Value {
let Value::Object(map) = args else {
panic!("object args");
};
dispatch(connection, method, &Args(&map)).expect("read")
}

fn head(connection: &Connection) -> Value {
call(connection, "extension_control_snapshot_head", json!({}))
}

fn recovery(connection: &Connection, revision: i64) -> Value {
call(
connection,
"extension_control_recovery_transition",
json!({"revision": revision}),
)
}

fn committed(connection: &Connection, revision: i64) -> Value {
call(
connection,
"extension_control_transition_committed",
json!({"revision": revision}),
)
}

#[test]
fn every_read_is_routed_as_a_read() {
for method in METHODS {
assert!(handles(method));
assert!(matches!(method_kind(method), Some(Kind::Read)));
}
assert!(!handles("extension_control_snapshot_layers"));
}

#[test]
fn a_store_without_tables_has_no_head_and_no_transitions() {
let connection = store();
assert_eq!(head(&connection), json!({"snapshot": null}));
assert_eq!(recovery(&connection, 3), json!({"revision": null}));
assert_eq!(committed(&connection, 3), json!({"committed": false}));
}

#[test]
fn an_empty_snapshot_table_has_no_head() {
let connection = store();
schema(&connection);
assert_eq!(head(&connection), json!({"snapshot": null}));
}

#[test]
fn the_head_comes_back_as_stored() {
let connection = store();
schema(&connection);
connection
.execute(
"insert into extension_control_authority_snapshot values (1, 4, 'cat', 'snap')",
[],
)
.expect("snapshot");
assert_eq!(
head(&connection),
json!({"snapshot": {"revision": 4, "snapshot_digest": "snap", "catalog_digest": "cat"}})
);
}

#[test]
fn cells_of_the_wrong_type_read_as_null() {
let connection = store();
schema(&connection);
connection
.execute(
"insert into extension_control_authority_snapshot values (1, '4', ?1, 7)",
params![b"cat".to_vec()],
)
.expect("snapshot");
assert_eq!(
head(&connection),
json!({"snapshot": {"revision": null, "snapshot_digest": null, "catalog_digest": null}})
);
}

#[test]
fn an_uncommitted_head_transition_is_resumed_first() {
let connection = store();
schema(&connection);
transition(&connection, 4, "anchored");
transition(&connection, 5, "prepared");
assert_eq!(recovery(&connection, 4), json!({"revision": 4}));
}

#[test]
fn a_committed_head_resumes_the_next_transition() {
let connection = store();
schema(&connection);
transition(&connection, 4, "committed");
transition(&connection, 5, "prepared");
assert_eq!(recovery(&connection, 4), json!({"revision": 5}));
}

#[test]
fn nothing_to_resume_past_a_committed_head() {
let connection = store();
schema(&connection);
transition(&connection, 3, "prepared");
transition(&connection, 4, "committed");
transition(&connection, 6, "prepared");
assert_eq!(recovery(&connection, 4), json!({"revision": null}));
}

#[test]
fn the_committed_check_reads_the_phase() {
let connection = store();
schema(&connection);
transition(&connection, 4, "committed");
transition(&connection, 5, "anchored");
assert_eq!(committed(&connection, 4), json!({"committed": true}));
assert_eq!(committed(&connection, 5), json!({"committed": false}));
assert_eq!(committed(&connection, 6), json!({"committed": false}));
}

#[test]
fn a_revision_argument_is_required() {
for method in &METHODS[1..] {
assert!(dispatch(&store(), method, &Args(&Map::new())).is_err());
}
}
3 changes: 3 additions & 0 deletions rust/crates/guard-runtime/src/guard_store_op_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ pub(crate) fn method_kind(method: &str) -> Option<Kind> {
| "list_command_pack_pending_records"
| "command_pack_legacy_evidence_rows"
| "command_pack_legacy_history_page"
| "extension_control_snapshot_head"
| "extension_control_recovery_transition"
| "extension_control_transition_committed"
| "connector_setup_advice"
| "approval_desktop_notified_at"
| "oldest_approval_request_created_at"
Expand Down
Loading