mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Trust the bundled Memory session hook without saved hashes (#62112)
## Why The bundled Memory hook needs to supply context at startup and after compaction without requiring saved hook trust. ## What changed Recognize the exact bundled Memory `SessionStart` declaration as a built-in hook: the `^(startup|compact)$` matcher, `codex_apps` server, `codex_dream_memory.get_mec` tool, and empty input. Carry the expected app connector identity through discovery for dispatch checks, and hide this built-in hook from hook listings while preserving other plugin hooks. ## Testing Add coverage for exact declaration matching, hook listings without an Apps connection, and a scenario snapshot verifying memory context injection at startup and after compaction without saved trust. GitOrigin-RevId: edc0e8ffa955227328345f46afecc2a868c0be49
This commit is contained in:
@@ -17,6 +17,7 @@ use codex_config::RequirementSource;
|
||||
use codex_config::TomlValue;
|
||||
use codex_config::version_for_toml;
|
||||
use codex_plugin::PluginHookSource;
|
||||
use codex_plugin::bundled_hook_app_connector_id;
|
||||
use codex_plugin::is_allowlisted_bundled_cleanup_hook;
|
||||
use codex_protocol::protocol::HookEventName;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
@@ -648,6 +649,14 @@ fn append_matcher_groups(
|
||||
}
|
||||
};
|
||||
for (handler_index, handler) in group.hooks.iter().cloned().enumerate() {
|
||||
let expected_app_connector_id = source.plugin_id.as_deref().and_then(|plugin_id| {
|
||||
bundled_hook_app_connector_id(
|
||||
plugin_id,
|
||||
event_name,
|
||||
group.matcher.as_deref(),
|
||||
&handler,
|
||||
)
|
||||
});
|
||||
let normalized = match handler {
|
||||
HookHandlerConfig::Command {
|
||||
command,
|
||||
@@ -770,7 +779,7 @@ fn append_matcher_groups(
|
||||
NormalizedHandler {
|
||||
config,
|
||||
kind: ConfiguredHandlerKind::McpTool {
|
||||
expected_app_connector_id: None,
|
||||
expected_app_connector_id,
|
||||
server,
|
||||
tool,
|
||||
input,
|
||||
@@ -820,6 +829,7 @@ fn append_matcher_groups(
|
||||
/*app_connector_id*/ None,
|
||||
)
|
||||
});
|
||||
let builtin = builtin || expected_app_connector_id.is_some();
|
||||
let plugin_content_hash = match source.plugin_content_hash {
|
||||
Some(Ok(hash)) => Some(hash.as_str()),
|
||||
Some(Err(err)) if !builtin && !source.bypass_hook_trust => {
|
||||
|
||||
@@ -1826,6 +1826,52 @@ fn bundled_cleanup_hooks_are_trusted_without_saved_hashes() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundled_app_hook_trust_requires_exact_declaration() {
|
||||
for (matcher, input, trusted) in [
|
||||
("^(startup|compact)$", serde_json::json!({}), true),
|
||||
(".*", serde_json::json!({}), false),
|
||||
(
|
||||
"^(startup|compact)$",
|
||||
serde_json::json!({"untrusted": true}),
|
||||
false,
|
||||
),
|
||||
] {
|
||||
let temp = tempdir().expect("plugin root");
|
||||
let mut source = bundled_cleanup_source(
|
||||
"codex-dream-memory@openai-bundled",
|
||||
"codex_apps",
|
||||
"SessionStart",
|
||||
);
|
||||
source.plugin_root = AbsolutePathBuf::try_from(temp.path()).unwrap();
|
||||
source.hooks = serde_json::from_value(serde_json::json!({
|
||||
"SessionStart": [{ "matcher": matcher, "hooks": [{
|
||||
"type": "mcp_tool", "server": "codex_apps", "tool": "codex_dream_memory.get_mec", "input": input,
|
||||
}] }],
|
||||
})).unwrap();
|
||||
let discovered = super::discovery::discover_handlers(
|
||||
/*config_layer_stack*/ None,
|
||||
vec![source],
|
||||
Vec::new(),
|
||||
/*bypass_hook_trust*/ false,
|
||||
DiscoveryMode::Listing,
|
||||
);
|
||||
let expected = if trusted {
|
||||
HookTrustStatus::Trusted
|
||||
} else {
|
||||
HookTrustStatus::Untrusted
|
||||
};
|
||||
assert_eq!(
|
||||
(
|
||||
discovered.handlers.len(),
|
||||
discovered.hook_entries[0].trust_status,
|
||||
discovered.hook_entries[0].builtin
|
||||
),
|
||||
(usize::from(trusted), expected, trusted)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundled_cleanup_trust_does_not_extend_to_other_handlers() {
|
||||
let temp = tempdir().expect("create plugin directory");
|
||||
|
||||
Reference in New Issue
Block a user