MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / replace_codex_compaction_summary

Method replace_codex_compaction_summary

src/global_db.rs:2967–3028  ·  view source on GitHub ↗

Replaces a deterministic Codex compaction placeholder summary with an auxiliary summary while preserving the exact source lineage.

(
        &self,
        node_id: &str,
        summary_text: &str,
        route: &str,
        model: Option<&str>,
    )

Source from the content-addressed store, hash-verified

2965 /// Replaces a deterministic Codex compaction placeholder summary with an
2966 /// auxiliary summary while preserving the exact source lineage.
2967 pub async fn replace_codex_compaction_summary(
2968 &self,
2969 node_id: &str,
2970 summary_text: &str,
2971 route: &str,
2972 model: Option<&str>,
2973 ) -> Result<LcmSummaryNode, crate::sessions::lcm::LcmError> {
2974 let mut draft = self.codex_compaction_summary_draft(node_id).await?;
2975 if draft.provider != "codex" {
2976 return Err(crate::sessions::lcm::LcmError::SummaryNodeNotFound);
2977 }
2978 let mut metadata: serde_json::Map<String, JsonValue> = draft
2979 .metadata_json
2980 .as_deref()
2981 .and_then(|raw| serde_json::from_str::<JsonValue>(raw).ok())
2982 .and_then(|value| value.as_object().cloned())
2983 .unwrap_or_default();
2984 if metadata.get("source").and_then(JsonValue::as_str) != Some("codex_context_compacted") {
2985 return Err(crate::sessions::lcm::LcmError::SummaryNodeNotFound);
2986 }
2987 draft.summary_text = summary_text.trim().to_string();
2988 draft.summary_token_count = estimate_summary_tokens(&draft.summary_text);
2989 metadata.insert(
2990 "tracedecay_summary_source".to_string(),
2991 JsonValue::String(route.to_string()),
2992 );
2993 if let Some(model) = model.filter(|model| !model.trim().is_empty()) {
2994 metadata.insert(
2995 "codex_auxiliary_model".to_string(),
2996 JsonValue::String(model.trim().to_string()),
2997 );
2998 }
2999 draft.metadata_json = Some(JsonValue::Object(metadata).to_string());
3000
3001 self.conn.execute("BEGIN IMMEDIATE", ()).await?;
3002 let result = async {
3003 self.conn
3004 .execute(
3005 "DELETE FROM lcm_summary_sources WHERE node_id = ?1",
3006 params![node_id],
3007 )
3008 .await?;
3009 self.conn
3010 .execute(
3011 "DELETE FROM lcm_summary_nodes WHERE node_id = ?1",
3012 params![node_id],
3013 )
3014 .await?;
3015 crate::sessions::lcm::dag::insert_summary_node_in_transaction(&self.conn, draft).await
3016 }
3017 .await;
3018 match result {
3019 Ok(node) => {
3020 self.conn.execute("COMMIT", ()).await?;
3021 Ok(node)
3022 }
3023 Err(err) => {
3024 let _ = self.conn.execute("ROLLBACK", ()).await;

Calls 5

estimate_summary_tokensFunction · 0.85
insertMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected