Add Epiphany CRRC coordinator recommendation
This commit is contained in:
parent
289ab31e64
commit
9d18cdbe9f
16 changed files with 920 additions and 38 deletions
|
|
@ -15105,6 +15105,43 @@
|
|||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ThreadEpiphanyCrrcAction": {
|
||||
"enum": [
|
||||
"continue",
|
||||
"prepareCheckpoint",
|
||||
"launchReorientWorker",
|
||||
"waitForReorientWorker",
|
||||
"reviewReorientResult",
|
||||
"acceptReorientResult",
|
||||
"regatherManually"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ThreadEpiphanyCrrcRecommendation": {
|
||||
"properties": {
|
||||
"action": {
|
||||
"$ref": "#/definitions/v2/ThreadEpiphanyCrrcAction"
|
||||
},
|
||||
"reason": {
|
||||
"type": "string"
|
||||
},
|
||||
"recommendedSceneAction": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/v2/ThreadEpiphanySceneAction"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"reason"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ThreadEpiphanyFreshnessSource": {
|
||||
"enum": [
|
||||
"stored",
|
||||
|
|
@ -16062,6 +16099,7 @@
|
|||
"freshness",
|
||||
"pressure",
|
||||
"reorient",
|
||||
"crrc",
|
||||
"reorientLaunch",
|
||||
"reorientResult",
|
||||
"reorientAccept",
|
||||
|
|
|
|||
|
|
@ -12992,6 +12992,43 @@
|
|||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ThreadEpiphanyCrrcAction": {
|
||||
"enum": [
|
||||
"continue",
|
||||
"prepareCheckpoint",
|
||||
"launchReorientWorker",
|
||||
"waitForReorientWorker",
|
||||
"reviewReorientResult",
|
||||
"acceptReorientResult",
|
||||
"regatherManually"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ThreadEpiphanyCrrcRecommendation": {
|
||||
"properties": {
|
||||
"action": {
|
||||
"$ref": "#/definitions/ThreadEpiphanyCrrcAction"
|
||||
},
|
||||
"reason": {
|
||||
"type": "string"
|
||||
},
|
||||
"recommendedSceneAction": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ThreadEpiphanySceneAction"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"reason"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ThreadEpiphanyFreshnessSource": {
|
||||
"enum": [
|
||||
"stored",
|
||||
|
|
@ -13949,6 +13986,7 @@
|
|||
"freshness",
|
||||
"pressure",
|
||||
"reorient",
|
||||
"crrc",
|
||||
"reorientLaunch",
|
||||
"reorientResult",
|
||||
"reorientAccept",
|
||||
|
|
|
|||
5
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyCrrcAction.ts
generated
vendored
Normal file
5
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyCrrcAction.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ThreadEpiphanyCrrcAction = "continue" | "prepareCheckpoint" | "launchReorientWorker" | "waitForReorientWorker" | "reviewReorientResult" | "acceptReorientResult" | "regatherManually";
|
||||
7
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyCrrcRecommendation.ts
generated
vendored
Normal file
7
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyCrrcRecommendation.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ThreadEpiphanyCrrcAction } from "./ThreadEpiphanyCrrcAction";
|
||||
import type { ThreadEpiphanySceneAction } from "./ThreadEpiphanySceneAction";
|
||||
|
||||
export type ThreadEpiphanyCrrcRecommendation = { action: ThreadEpiphanyCrrcAction, recommendedSceneAction?: ThreadEpiphanySceneAction | null, reason: string, };
|
||||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "reorientLaunch" | "reorientResult" | "reorientAccept" | "propose" | "promote" | "update";
|
||||
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "crrc" | "reorientLaunch" | "reorientResult" | "reorientAccept" | "propose" | "promote" | "update";
|
||||
|
|
|
|||
2
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/index.ts
generated
vendored
2
vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/index.ts
generated
vendored
|
|
@ -321,6 +321,8 @@ export type { ThreadEpiphanyContext } from "./ThreadEpiphanyContext";
|
|||
export type { ThreadEpiphanyContextMissing } from "./ThreadEpiphanyContextMissing";
|
||||
export type { ThreadEpiphanyContextSource } from "./ThreadEpiphanyContextSource";
|
||||
export type { ThreadEpiphanyContextStateStatus } from "./ThreadEpiphanyContextStateStatus";
|
||||
export type { ThreadEpiphanyCrrcAction } from "./ThreadEpiphanyCrrcAction";
|
||||
export type { ThreadEpiphanyCrrcRecommendation } from "./ThreadEpiphanyCrrcRecommendation";
|
||||
export type { ThreadEpiphanyFreshnessSource } from "./ThreadEpiphanyFreshnessSource";
|
||||
export type { ThreadEpiphanyGraphContext } from "./ThreadEpiphanyGraphContext";
|
||||
export type { ThreadEpiphanyGraphFreshness } from "./ThreadEpiphanyGraphFreshness";
|
||||
|
|
|
|||
|
|
@ -366,6 +366,11 @@ client_request_definitions! {
|
|||
params: v2::ThreadEpiphanyReorientParams,
|
||||
response: v2::ThreadEpiphanyReorientResponse,
|
||||
},
|
||||
#[experimental("thread/epiphany/crrc")]
|
||||
ThreadEpiphanyCrrc => "thread/epiphany/crrc" {
|
||||
params: v2::ThreadEpiphanyCrrcParams,
|
||||
response: v2::ThreadEpiphanyCrrcResponse,
|
||||
},
|
||||
#[experimental("thread/epiphany/reorientLaunch")]
|
||||
ThreadEpiphanyReorientLaunch => "thread/epiphany/reorientLaunch" {
|
||||
params: v2::ThreadEpiphanyReorientLaunchParams,
|
||||
|
|
@ -1725,6 +1730,7 @@ mod tests {
|
|||
v2::ThreadEpiphanySceneAction::Freshness,
|
||||
v2::ThreadEpiphanySceneAction::Pressure,
|
||||
v2::ThreadEpiphanySceneAction::Reorient,
|
||||
v2::ThreadEpiphanySceneAction::Crrc,
|
||||
v2::ThreadEpiphanySceneAction::ReorientLaunch,
|
||||
v2::ThreadEpiphanySceneAction::Update,
|
||||
v2::ThreadEpiphanySceneAction::JobInterrupt,
|
||||
|
|
@ -1825,6 +1831,7 @@ mod tests {
|
|||
"freshness",
|
||||
"pressure",
|
||||
"reorient",
|
||||
"crrc",
|
||||
"reorientLaunch",
|
||||
"update",
|
||||
"jobInterrupt",
|
||||
|
|
@ -2242,6 +2249,117 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_thread_epiphany_crrc_response() -> Result<()> {
|
||||
let response = ClientResponse::ThreadEpiphanyCrrc {
|
||||
request_id: RequestId::Integer(9),
|
||||
response: v2::ThreadEpiphanyCrrcResponse {
|
||||
thread_id: "thr_123".to_string(),
|
||||
source: v2::ThreadEpiphanyReorientSource::Live,
|
||||
state_status: v2::ThreadEpiphanyReorientStateStatus::Ready,
|
||||
state_revision: Some(4),
|
||||
pressure: v2::ThreadEpiphanyPressure {
|
||||
status: v2::ThreadEpiphanyPressureStatus::Ready,
|
||||
level: v2::ThreadEpiphanyPressureLevel::High,
|
||||
basis: v2::ThreadEpiphanyPressureBasis::AutoCompactLimit,
|
||||
used_tokens: Some(92_000),
|
||||
model_context_window: Some(128_000),
|
||||
model_auto_compact_token_limit: Some(100_000),
|
||||
remaining_tokens: Some(8_000),
|
||||
ratio_per_mille: Some(920),
|
||||
should_prepare_compaction: true,
|
||||
note: "Pressure is derived from the model auto-compact token limit."
|
||||
.to_string(),
|
||||
},
|
||||
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],
|
||||
checkpoint_dirty_paths: Vec::new(),
|
||||
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(),
|
||||
},
|
||||
recommendation: v2::ThreadEpiphanyCrrcRecommendation {
|
||||
action: v2::ThreadEpiphanyCrrcAction::LaunchReorientWorker,
|
||||
recommended_scene_action: Some(v2::ThreadEpiphanySceneAction::ReorientLaunch),
|
||||
reason: "The current pressure/reorientation verdict needs a bounded worker before safe continuation."
|
||||
.to_string(),
|
||||
},
|
||||
reorient_binding_id: "reorient-worker".to_string(),
|
||||
reorient_result_status: v2::ThreadEpiphanyReorientResultStatus::MissingBinding,
|
||||
reorient_job: None,
|
||||
reorient_finding: None,
|
||||
available_actions: vec![
|
||||
v2::ThreadEpiphanySceneAction::Reorient,
|
||||
v2::ThreadEpiphanySceneAction::Crrc,
|
||||
v2::ThreadEpiphanySceneAction::ReorientLaunch,
|
||||
],
|
||||
note: "The current pressure/reorientation verdict needs a bounded worker before safe continuation. Result status: MissingBinding. No matching Epiphany reorientation worker binding exists."
|
||||
.to_string(),
|
||||
},
|
||||
};
|
||||
|
||||
assert_eq!(response.id(), &RequestId::Integer(9));
|
||||
assert_eq!(response.method(), "thread/epiphany/crrc");
|
||||
assert_eq!(
|
||||
json!({
|
||||
"method": "thread/epiphany/crrc",
|
||||
"id": 9,
|
||||
"response": {
|
||||
"threadId": "thr_123",
|
||||
"source": "live",
|
||||
"stateStatus": "ready",
|
||||
"stateRevision": 4,
|
||||
"pressure": {
|
||||
"status": "ready",
|
||||
"level": "high",
|
||||
"basis": "autoCompactLimit",
|
||||
"usedTokens": 92000,
|
||||
"modelContextWindow": 128000,
|
||||
"modelAutoCompactTokenLimit": 100000,
|
||||
"remainingTokens": 8000,
|
||||
"ratioPerMille": 920,
|
||||
"shouldPrepareCompaction": true,
|
||||
"note": "Pressure is derived from the model auto-compact token limit."
|
||||
},
|
||||
"decision": {
|
||||
"action": "regather",
|
||||
"checkpointStatus": "resumeReady",
|
||||
"checkpointId": "ix-1",
|
||||
"pressureLevel": "high",
|
||||
"retrievalStatus": "stale",
|
||||
"graphStatus": "ready",
|
||||
"watcherStatus": "changed",
|
||||
"reasons": ["checkpointPathsChanged"],
|
||||
"checkpointChangedPaths": ["src/lib.rs"],
|
||||
"activeFrontierNodeIds": ["state-spine"],
|
||||
"nextAction": "Re-gather source before editing.",
|
||||
"note": "Resume-ready checkpoint was invalidated by watcher/frontier drift."
|
||||
},
|
||||
"recommendation": {
|
||||
"action": "launchReorientWorker",
|
||||
"recommendedSceneAction": "reorientLaunch",
|
||||
"reason": "The current pressure/reorientation verdict needs a bounded worker before safe continuation."
|
||||
},
|
||||
"reorientBindingId": "reorient-worker",
|
||||
"reorientResultStatus": "missingBinding",
|
||||
"availableActions": ["reorient", "crrc", "reorientLaunch"],
|
||||
"note": "The current pressure/reorientation verdict needs a bounded worker before safe continuation. Result status: MissingBinding. No matching Epiphany reorientation worker binding exists."
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&response)?,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_thread_epiphany_reorient_launch_response() -> Result<()> {
|
||||
let response = ClientResponse::ThreadEpiphanyReorientLaunch {
|
||||
|
|
@ -3816,6 +3934,18 @@ mod tests {
|
|||
assert_eq!(reason, Some("thread/epiphany/reorient"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_epiphany_crrc_is_marked_experimental() {
|
||||
let request = ClientRequest::ThreadEpiphanyCrrc {
|
||||
request_id: RequestId::Integer(1),
|
||||
params: v2::ThreadEpiphanyCrrcParams {
|
||||
thread_id: "thr_123".to_string(),
|
||||
},
|
||||
};
|
||||
let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request);
|
||||
assert_eq!(reason, Some("thread/epiphany/crrc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_epiphany_reorient_launch_is_marked_experimental() {
|
||||
let request = ClientRequest::ThreadEpiphanyReorientLaunch {
|
||||
|
|
|
|||
|
|
@ -4002,6 +4002,7 @@ pub enum ThreadEpiphanySceneAction {
|
|||
Freshness,
|
||||
Pressure,
|
||||
Reorient,
|
||||
Crrc,
|
||||
ReorientLaunch,
|
||||
ReorientResult,
|
||||
ReorientAccept,
|
||||
|
|
@ -4654,6 +4655,63 @@ pub struct ThreadEpiphanyReorientAcceptResponse {
|
|||
pub finding: ThreadEpiphanyReorientFinding,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyCrrcParams {
|
||||
pub thread_id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyCrrcResponse {
|
||||
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 pressure: ThreadEpiphanyPressure,
|
||||
pub decision: ThreadEpiphanyReorientDecision,
|
||||
pub recommendation: ThreadEpiphanyCrrcRecommendation,
|
||||
pub reorient_binding_id: String,
|
||||
pub reorient_result_status: ThreadEpiphanyReorientResultStatus,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub reorient_job: Option<ThreadEpiphanyJob>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub reorient_finding: Option<ThreadEpiphanyReorientFinding>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub available_actions: Vec<ThreadEpiphanySceneAction>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadEpiphanyCrrcRecommendation {
|
||||
pub action: ThreadEpiphanyCrrcAction,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub recommended_scene_action: Option<ThreadEpiphanySceneAction>,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ThreadEpiphanyCrrcAction {
|
||||
Continue,
|
||||
PrepareCheckpoint,
|
||||
LaunchReorientWorker,
|
||||
WaitForReorientWorker,
|
||||
ReviewReorientResult,
|
||||
AcceptReorientResult,
|
||||
RegatherManually,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ use codex_app_server_protocol::ThreadEpiphanyContextParams;
|
|||
use codex_app_server_protocol::ThreadEpiphanyContextResponse;
|
||||
use codex_app_server_protocol::ThreadEpiphanyContextSource;
|
||||
use codex_app_server_protocol::ThreadEpiphanyContextStateStatus;
|
||||
use codex_app_server_protocol::ThreadEpiphanyCrrcAction;
|
||||
use codex_app_server_protocol::ThreadEpiphanyCrrcParams;
|
||||
use codex_app_server_protocol::ThreadEpiphanyCrrcRecommendation;
|
||||
use codex_app_server_protocol::ThreadEpiphanyCrrcResponse;
|
||||
use codex_app_server_protocol::ThreadEpiphanyDistillParams;
|
||||
use codex_app_server_protocol::ThreadEpiphanyDistillResponse;
|
||||
use codex_app_server_protocol::ThreadEpiphanyFreshnessParams;
|
||||
|
|
@ -1098,6 +1102,10 @@ impl CodexMessageProcessor {
|
|||
self.thread_epiphany_reorient(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyCrrc { request_id, params } => {
|
||||
self.thread_epiphany_crrc(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyReorientLaunch { request_id, params } => {
|
||||
self.thread_epiphany_reorient_launch(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
|
|
@ -4535,6 +4543,155 @@ impl CodexMessageProcessor {
|
|||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
async fn thread_epiphany_crrc(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyCrrcParams,
|
||||
) {
|
||||
let ThreadEpiphanyCrrcParams { thread_id } = params;
|
||||
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
|
||||
let loaded = loaded_thread.is_some();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let retrieval_override = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(loaded_thread.epiphany_retrieval_state().await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let watcher_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
self.epiphany_invalidation_manager
|
||||
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
|
||||
.await;
|
||||
Some(
|
||||
self.epiphany_invalidation_manager
|
||||
.snapshot(&thread_id)
|
||||
.await,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (source, token_usage_info) = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
(
|
||||
ThreadEpiphanyReorientSource::Live,
|
||||
loaded_thread.token_usage_info().await,
|
||||
)
|
||||
} else {
|
||||
let token_usage_info = match thread.path.as_deref() {
|
||||
Some(path) => latest_token_usage_info_from_rollout_path(path).await,
|
||||
None => None,
|
||||
};
|
||||
(ThreadEpiphanyReorientSource::Stored, token_usage_info)
|
||||
};
|
||||
|
||||
let (state_revision, retrieval, graph, watcher) = map_epiphany_freshness(
|
||||
thread.epiphany_state.as_ref(),
|
||||
retrieval_override.as_ref(),
|
||||
watcher_snapshot.as_ref(),
|
||||
);
|
||||
let pressure = map_epiphany_pressure(token_usage_info.as_ref());
|
||||
let (state_status, decision) = map_epiphany_reorient(
|
||||
thread.epiphany_state.as_ref(),
|
||||
&pressure,
|
||||
&retrieval,
|
||||
&graph,
|
||||
&watcher,
|
||||
);
|
||||
|
||||
let mut state_db_ctx = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
loaded_thread.epiphany_state_runtime().await
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if state_db_ctx.is_none() {
|
||||
state_db_ctx = open_state_db_for_direct_thread_lookup(&self.config).await;
|
||||
}
|
||||
let job_resolution = load_epiphany_job_launcher_snapshots(
|
||||
state_db_ctx.as_ref(),
|
||||
thread.epiphany_state.as_ref(),
|
||||
)
|
||||
.await;
|
||||
let jobs = map_epiphany_jobs(
|
||||
thread.epiphany_state.as_ref(),
|
||||
retrieval_override.as_ref(),
|
||||
&job_resolution,
|
||||
);
|
||||
let reorient_job = jobs
|
||||
.iter()
|
||||
.find(|job| job.id == EPIPHANY_REORIENT_LAUNCH_BINDING_ID)
|
||||
.cloned();
|
||||
let (result_status, finding, result_note) = load_epiphany_reorient_result_snapshot(
|
||||
thread.epiphany_state.as_ref(),
|
||||
state_db_ctx.as_ref(),
|
||||
EPIPHANY_REORIENT_LAUNCH_BINDING_ID,
|
||||
)
|
||||
.await;
|
||||
let available_actions = epiphany_scene_available_actions(
|
||||
loaded,
|
||||
thread.epiphany_state.is_some(),
|
||||
thread
|
||||
.epiphany_state
|
||||
.as_ref()
|
||||
.and_then(|state| state.investigation_checkpoint.as_ref())
|
||||
.is_some(),
|
||||
reorient_job.is_some(),
|
||||
);
|
||||
let recommendation = map_epiphany_crrc_recommendation(
|
||||
loaded,
|
||||
state_status,
|
||||
&pressure,
|
||||
&decision,
|
||||
result_status,
|
||||
thread
|
||||
.epiphany_state
|
||||
.as_ref()
|
||||
.and_then(|state| state.investigation_checkpoint.as_ref())
|
||||
.is_some(),
|
||||
finding.is_some(),
|
||||
);
|
||||
let note = format!(
|
||||
"{} Result status: {:?}. {}",
|
||||
recommendation.reason, result_status, result_note
|
||||
);
|
||||
|
||||
let response = ThreadEpiphanyCrrcResponse {
|
||||
thread_id,
|
||||
source,
|
||||
state_status,
|
||||
state_revision,
|
||||
pressure,
|
||||
decision,
|
||||
recommendation,
|
||||
reorient_binding_id: EPIPHANY_REORIENT_LAUNCH_BINDING_ID.to_string(),
|
||||
reorient_result_status: result_status,
|
||||
reorient_job,
|
||||
reorient_finding: finding,
|
||||
available_actions,
|
||||
note,
|
||||
};
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
async fn thread_epiphany_reorient_launch(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
|
|
@ -11909,6 +12066,7 @@ fn epiphany_scene_available_actions(
|
|||
ThreadEpiphanySceneAction::Freshness,
|
||||
ThreadEpiphanySceneAction::Pressure,
|
||||
ThreadEpiphanySceneAction::Reorient,
|
||||
ThreadEpiphanySceneAction::Crrc,
|
||||
];
|
||||
if checkpoint_present {
|
||||
actions.push(ThreadEpiphanySceneAction::ReorientLaunch);
|
||||
|
|
@ -12150,6 +12308,201 @@ fn render_epiphany_reorient_result_note(
|
|||
}
|
||||
}
|
||||
|
||||
async fn load_epiphany_reorient_result_snapshot(
|
||||
state: Option<&EpiphanyThreadState>,
|
||||
state_db_ctx: Option<&StateDbHandle>,
|
||||
binding_id: &str,
|
||||
) -> (
|
||||
ThreadEpiphanyReorientResultStatus,
|
||||
Option<ThreadEpiphanyReorientFinding>,
|
||||
String,
|
||||
) {
|
||||
let Some(state) = state else {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::MissingState,
|
||||
None,
|
||||
"No authoritative Epiphany state exists for this thread.".to_string(),
|
||||
);
|
||||
};
|
||||
let Some(binding) = state
|
||||
.job_bindings
|
||||
.iter()
|
||||
.find(|binding| binding.id == binding_id)
|
||||
else {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::MissingBinding,
|
||||
None,
|
||||
"No matching Epiphany reorientation worker binding exists.".to_string(),
|
||||
);
|
||||
};
|
||||
let Some(agent_job_id) = binding_agent_jobs_job_id(binding) else {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
|
||||
None,
|
||||
"The matching binding is not currently backed by the agent_jobs backend.".to_string(),
|
||||
);
|
||||
};
|
||||
let Some(state_db_ctx) = state_db_ctx else {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
|
||||
None,
|
||||
"State runtime is unavailable, so the bound agent_jobs result cannot be read."
|
||||
.to_string(),
|
||||
);
|
||||
};
|
||||
let agent_job = match state_db_ctx.get_agent_job(agent_job_id).await {
|
||||
Ok(Some(job)) => job,
|
||||
Ok(None) => {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendMissing,
|
||||
None,
|
||||
format!(
|
||||
"Bound agent_jobs backend job {:?} was not found.",
|
||||
agent_job_id
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
|
||||
None,
|
||||
format!("Failed to read Epiphany reorientation backend job: {err}"),
|
||||
);
|
||||
}
|
||||
};
|
||||
let item = match state_db_ctx
|
||||
.get_agent_job_item(agent_job_id, binding_id)
|
||||
.await
|
||||
{
|
||||
Ok(Some(item)) => item,
|
||||
Ok(None) => {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendMissing,
|
||||
None,
|
||||
"Bound agent_jobs backend item was not found for this reorient worker.".to_string(),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
return (
|
||||
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
|
||||
None,
|
||||
format!("Failed to read Epiphany reorientation backend item: {err}"),
|
||||
);
|
||||
}
|
||||
};
|
||||
let status = map_epiphany_reorient_result_status(agent_job.status, item.status);
|
||||
let finding = item.result_json.as_ref().map(|result| {
|
||||
map_epiphany_reorient_finding(
|
||||
result.clone(),
|
||||
agent_job.last_error.clone(),
|
||||
item.last_error.clone(),
|
||||
)
|
||||
});
|
||||
let note =
|
||||
render_epiphany_reorient_result_note(status, finding.as_ref(), item.last_error.as_deref());
|
||||
(status, finding, note)
|
||||
}
|
||||
|
||||
fn map_epiphany_crrc_recommendation(
|
||||
loaded: bool,
|
||||
state_status: ThreadEpiphanyReorientStateStatus,
|
||||
pressure: &ThreadEpiphanyPressure,
|
||||
decision: &ThreadEpiphanyReorientDecision,
|
||||
result_status: ThreadEpiphanyReorientResultStatus,
|
||||
checkpoint_present: bool,
|
||||
finding_present: bool,
|
||||
) -> ThreadEpiphanyCrrcRecommendation {
|
||||
let build = |action: ThreadEpiphanyCrrcAction,
|
||||
recommended_scene_action: Option<ThreadEpiphanySceneAction>,
|
||||
reason: &str| ThreadEpiphanyCrrcRecommendation {
|
||||
action,
|
||||
recommended_scene_action,
|
||||
reason: reason.to_string(),
|
||||
};
|
||||
|
||||
if state_status == ThreadEpiphanyReorientStateStatus::Missing {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::RegatherManually,
|
||||
None,
|
||||
"No authoritative Epiphany state exists; re-gather source context before editing.",
|
||||
);
|
||||
}
|
||||
|
||||
if !checkpoint_present {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::PrepareCheckpoint,
|
||||
Some(ThreadEpiphanySceneAction::Update),
|
||||
"Epiphany state exists, but CRRC has no durable investigation checkpoint to resume.",
|
||||
);
|
||||
}
|
||||
|
||||
match result_status {
|
||||
ThreadEpiphanyReorientResultStatus::Pending
|
||||
| ThreadEpiphanyReorientResultStatus::Running => {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::WaitForReorientWorker,
|
||||
Some(ThreadEpiphanySceneAction::ReorientResult),
|
||||
"A reorientation worker is already in flight; wait or read the bound result.",
|
||||
);
|
||||
}
|
||||
ThreadEpiphanyReorientResultStatus::Completed => {
|
||||
if finding_present {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::AcceptReorientResult,
|
||||
Some(ThreadEpiphanySceneAction::ReorientAccept),
|
||||
"A completed reorientation finding is available; review and explicitly accept it before continuing.",
|
||||
);
|
||||
}
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::ReviewReorientResult,
|
||||
Some(ThreadEpiphanySceneAction::ReorientResult),
|
||||
"The reorientation worker completed, but no structured finding was recorded.",
|
||||
);
|
||||
}
|
||||
ThreadEpiphanyReorientResultStatus::Failed
|
||||
| ThreadEpiphanyReorientResultStatus::Cancelled => {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::RegatherManually,
|
||||
Some(ThreadEpiphanySceneAction::ReorientResult),
|
||||
"The reorientation worker ended without a usable finding; inspect the failure before relaunching.",
|
||||
);
|
||||
}
|
||||
ThreadEpiphanyReorientResultStatus::MissingState => {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::RegatherManually,
|
||||
None,
|
||||
"No authoritative Epiphany state exists; re-gather source context before editing.",
|
||||
);
|
||||
}
|
||||
ThreadEpiphanyReorientResultStatus::MissingBinding
|
||||
| ThreadEpiphanyReorientResultStatus::BackendUnavailable
|
||||
| ThreadEpiphanyReorientResultStatus::BackendMissing => {}
|
||||
}
|
||||
|
||||
if pressure.should_prepare_compaction
|
||||
|| decision.action == ThreadEpiphanyReorientAction::Regather
|
||||
{
|
||||
if loaded {
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::LaunchReorientWorker,
|
||||
Some(ThreadEpiphanySceneAction::ReorientLaunch),
|
||||
"The current pressure/reorientation verdict needs a bounded worker before safe continuation.",
|
||||
);
|
||||
}
|
||||
return build(
|
||||
ThreadEpiphanyCrrcAction::RegatherManually,
|
||||
Some(ThreadEpiphanySceneAction::Reorient),
|
||||
"The thread is not loaded, so CRRC can only report the regather verdict.",
|
||||
);
|
||||
}
|
||||
|
||||
build(
|
||||
ThreadEpiphanyCrrcAction::Continue,
|
||||
Some(ThreadEpiphanySceneAction::Reorient),
|
||||
"Pressure is tolerable and the checkpoint remains resume-ready; continue the bounded task.",
|
||||
)
|
||||
}
|
||||
|
||||
async fn load_completed_epiphany_reorient_finding(
|
||||
thread: &CodexThread,
|
||||
state: &EpiphanyThreadState,
|
||||
|
|
@ -16093,6 +16446,120 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_epiphany_crrc_recommendation_continues_clean_checkpoint() {
|
||||
let pressure = map_epiphany_pressure(None);
|
||||
let decision = ThreadEpiphanyReorientDecision {
|
||||
action: ThreadEpiphanyReorientAction::Resume,
|
||||
checkpoint_status: ThreadEpiphanyReorientCheckpointStatus::ResumeReady,
|
||||
checkpoint_id: Some("ix-clean".to_string()),
|
||||
pressure_level: pressure.level,
|
||||
retrieval_status: ThreadEpiphanyRetrievalFreshnessStatus::Ready,
|
||||
graph_status: ThreadEpiphanyGraphFreshnessStatus::Ready,
|
||||
watcher_status: ThreadEpiphanyInvalidationStatus::Clean,
|
||||
reasons: vec![ThreadEpiphanyReorientReason::CheckpointReady],
|
||||
checkpoint_dirty_paths: Vec::new(),
|
||||
checkpoint_changed_paths: Vec::new(),
|
||||
active_frontier_node_ids: Vec::new(),
|
||||
next_action: "Continue the bounded task.".to_string(),
|
||||
note: "ready".to_string(),
|
||||
};
|
||||
|
||||
let recommendation = map_epiphany_crrc_recommendation(
|
||||
true,
|
||||
ThreadEpiphanyReorientStateStatus::Ready,
|
||||
&pressure,
|
||||
&decision,
|
||||
ThreadEpiphanyReorientResultStatus::MissingBinding,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
assert_eq!(recommendation.action, ThreadEpiphanyCrrcAction::Continue);
|
||||
assert_eq!(
|
||||
recommendation.recommended_scene_action,
|
||||
Some(ThreadEpiphanySceneAction::Reorient)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_epiphany_crrc_recommendation_launches_on_regather_verdict() {
|
||||
let pressure = map_epiphany_pressure(None);
|
||||
let decision = ThreadEpiphanyReorientDecision {
|
||||
action: ThreadEpiphanyReorientAction::Regather,
|
||||
checkpoint_status: ThreadEpiphanyReorientCheckpointStatus::ResumeReady,
|
||||
checkpoint_id: Some("ix-drifted".to_string()),
|
||||
pressure_level: pressure.level,
|
||||
retrieval_status: ThreadEpiphanyRetrievalFreshnessStatus::Ready,
|
||||
graph_status: ThreadEpiphanyGraphFreshnessStatus::Stale,
|
||||
watcher_status: ThreadEpiphanyInvalidationStatus::Changed,
|
||||
reasons: vec![ThreadEpiphanyReorientReason::CheckpointPathsChanged],
|
||||
checkpoint_dirty_paths: Vec::new(),
|
||||
checkpoint_changed_paths: vec![PathBuf::from("src/lib.rs")],
|
||||
active_frontier_node_ids: vec!["node-a".to_string()],
|
||||
next_action: "Regather.".to_string(),
|
||||
note: "drifted".to_string(),
|
||||
};
|
||||
|
||||
let recommendation = map_epiphany_crrc_recommendation(
|
||||
true,
|
||||
ThreadEpiphanyReorientStateStatus::Ready,
|
||||
&pressure,
|
||||
&decision,
|
||||
ThreadEpiphanyReorientResultStatus::MissingBinding,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
recommendation.action,
|
||||
ThreadEpiphanyCrrcAction::LaunchReorientWorker
|
||||
);
|
||||
assert_eq!(
|
||||
recommendation.recommended_scene_action,
|
||||
Some(ThreadEpiphanySceneAction::ReorientLaunch)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_epiphany_crrc_recommendation_accepts_completed_finding() {
|
||||
let pressure = map_epiphany_pressure(None);
|
||||
let decision = ThreadEpiphanyReorientDecision {
|
||||
action: ThreadEpiphanyReorientAction::Regather,
|
||||
checkpoint_status: ThreadEpiphanyReorientCheckpointStatus::RegatherRequired,
|
||||
checkpoint_id: Some("ix-result".to_string()),
|
||||
pressure_level: pressure.level,
|
||||
retrieval_status: ThreadEpiphanyRetrievalFreshnessStatus::Ready,
|
||||
graph_status: ThreadEpiphanyGraphFreshnessStatus::Ready,
|
||||
watcher_status: ThreadEpiphanyInvalidationStatus::Clean,
|
||||
reasons: vec![ThreadEpiphanyReorientReason::CheckpointRequestedRegather],
|
||||
checkpoint_dirty_paths: Vec::new(),
|
||||
checkpoint_changed_paths: Vec::new(),
|
||||
active_frontier_node_ids: Vec::new(),
|
||||
next_action: "Review result.".to_string(),
|
||||
note: "result".to_string(),
|
||||
};
|
||||
|
||||
let recommendation = map_epiphany_crrc_recommendation(
|
||||
true,
|
||||
ThreadEpiphanyReorientStateStatus::Ready,
|
||||
&pressure,
|
||||
&decision,
|
||||
ThreadEpiphanyReorientResultStatus::Completed,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
recommendation.action,
|
||||
ThreadEpiphanyCrrcAction::AcceptReorientResult
|
||||
);
|
||||
assert_eq!(
|
||||
recommendation.recommended_scene_action,
|
||||
Some(ThreadEpiphanySceneAction::ReorientAccept)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reorient_finding_acceptance_builds_scratch_and_checkpoint_update() {
|
||||
let finding = ThreadEpiphanyReorientFinding {
|
||||
|
|
|
|||
Reference in a new issue