Add Epiphany reorientation policy

This commit is contained in:
Meta Vens 2026-04-26 11:47:34 +01:00
commit 3ac09f9d1b
22 changed files with 1438 additions and 35 deletions

View file

@ -361,6 +361,11 @@ client_request_definitions! {
params: v2::ThreadEpiphanyPressureParams,
response: v2::ThreadEpiphanyPressureResponse,
},
#[experimental("thread/epiphany/reorient")]
ThreadEpiphanyReorient => "thread/epiphany/reorient" {
params: v2::ThreadEpiphanyReorientParams,
response: v2::ThreadEpiphanyReorientResponse,
},
#[experimental("thread/epiphany/index")]
ThreadEpiphanyIndex => "thread/epiphany/index" {
params: v2::ThreadEpiphanyIndexParams,
@ -1691,6 +1696,7 @@ mod tests {
v2::ThreadEpiphanySceneAction::Jobs,
v2::ThreadEpiphanySceneAction::Freshness,
v2::ThreadEpiphanySceneAction::Pressure,
v2::ThreadEpiphanySceneAction::Reorient,
v2::ThreadEpiphanySceneAction::Update,
v2::ThreadEpiphanySceneAction::Propose,
v2::ThreadEpiphanySceneAction::Promote,
@ -1787,6 +1793,7 @@ mod tests {
"jobs",
"freshness",
"pressure",
"reorient",
"update",
"propose",
"promote"
@ -2129,6 +2136,73 @@ mod tests {
Ok(())
}
#[test]
fn serialize_thread_epiphany_reorient_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyReorient {
request_id: RequestId::Integer(8),
response: v2::ThreadEpiphanyReorientResponse {
thread_id: "thr_123".to_string(),
source: v2::ThreadEpiphanyReorientSource::Live,
state_status: v2::ThreadEpiphanyReorientStateStatus::Ready,
state_revision: Some(4),
decision: v2::ThreadEpiphanyReorientDecision {
action: v2::ThreadEpiphanyReorientAction::Regather,
checkpoint_status: v2::ThreadEpiphanyReorientCheckpointStatus::ResumeReady,
checkpoint_id: Some("ix-1".to_string()),
pressure_level: v2::ThreadEpiphanyPressureLevel::High,
retrieval_status: v2::ThreadEpiphanyRetrievalFreshnessStatus::Stale,
graph_status: v2::ThreadEpiphanyGraphFreshnessStatus::Ready,
watcher_status: v2::ThreadEpiphanyInvalidationStatus::Changed,
reasons: vec![
v2::ThreadEpiphanyReorientReason::CheckpointPathsChanged,
v2::ThreadEpiphanyReorientReason::FrontierChanged,
],
checkpoint_dirty_paths: vec![PathBuf::from("src/lib.rs")],
checkpoint_changed_paths: vec![PathBuf::from("src/lib.rs")],
active_frontier_node_ids: vec!["state-spine".to_string()],
next_action: "Re-gather source before editing.".to_string(),
note: "Resume-ready checkpoint was invalidated by watcher/frontier drift."
.to_string(),
},
},
};
assert_eq!(response.id(), &RequestId::Integer(8));
assert_eq!(response.method(), "thread/epiphany/reorient");
assert_eq!(
json!({
"method": "thread/epiphany/reorient",
"id": 8,
"response": {
"threadId": "thr_123",
"source": "live",
"stateStatus": "ready",
"stateRevision": 4,
"decision": {
"action": "regather",
"checkpointStatus": "resumeReady",
"checkpointId": "ix-1",
"pressureLevel": "high",
"retrievalStatus": "stale",
"graphStatus": "ready",
"watcherStatus": "changed",
"reasons": [
"checkpointPathsChanged",
"frontierChanged"
],
"checkpointDirtyPaths": ["src/lib.rs"],
"checkpointChangedPaths": ["src/lib.rs"],
"activeFrontierNodeIds": ["state-spine"],
"nextAction": "Re-gather source before editing.",
"note": "Resume-ready checkpoint was invalidated by watcher/frontier drift."
}
}
}),
serde_json::to_value(&response)?,
);
Ok(())
}
#[test]
fn serialize_thread_epiphany_retrieve_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyRetrieve {
@ -3053,6 +3127,18 @@ mod tests {
assert_eq!(reason, Some("thread/epiphany/pressure"));
}
#[test]
fn thread_epiphany_reorient_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyReorient {
request_id: RequestId::Integer(1),
params: v2::ThreadEpiphanyReorientParams {
thread_id: "thr_123".to_string(),
},
};
let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request);
assert_eq!(reason, Some("thread/epiphany/reorient"));
}
#[test]
fn thread_epiphany_index_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyIndex {

View file

@ -3997,6 +3997,7 @@ pub enum ThreadEpiphanySceneAction {
Jobs,
Freshness,
Pressure,
Reorient,
Propose,
Promote,
Update,
@ -4507,6 +4508,98 @@ pub enum ThreadEpiphanyPressureBasis {
ModelContextWindow,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyReorientParams {
pub thread_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyReorientResponse {
pub thread_id: String,
pub source: ThreadEpiphanyReorientSource,
pub state_status: ThreadEpiphanyReorientStateStatus,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub state_revision: Option<u64>,
pub decision: ThreadEpiphanyReorientDecision,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyReorientSource {
Stored,
Live,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyReorientStateStatus {
Missing,
Ready,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyReorientAction {
Resume,
Regather,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyReorientCheckpointStatus {
Missing,
ResumeReady,
RegatherRequired,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyReorientReason {
MissingState,
MissingCheckpoint,
CheckpointRequestedRegather,
CheckpointPathsDirty,
CheckpointPathsChanged,
FrontierChanged,
UnanchoredCheckpointWhileStateStale,
CheckpointReady,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyReorientDecision {
pub action: ThreadEpiphanyReorientAction,
pub checkpoint_status: ThreadEpiphanyReorientCheckpointStatus,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub checkpoint_id: Option<String>,
pub pressure_level: ThreadEpiphanyPressureLevel,
pub retrieval_status: ThreadEpiphanyRetrievalFreshnessStatus,
pub graph_status: ThreadEpiphanyGraphFreshnessStatus,
pub watcher_status: ThreadEpiphanyInvalidationStatus,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub reasons: Vec<ThreadEpiphanyReorientReason>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub checkpoint_dirty_paths: Vec<PathBuf>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub checkpoint_changed_paths: Vec<PathBuf>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub active_frontier_node_ids: Vec<String>,
pub next_action: String,
pub note: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]