mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
bee78806a9
## Summary
- Add `request_kind` values for foreground turn, startup prewarm,
compaction, and detached memory model requests.
- Attach compaction dispatch metadata to local Responses, legacy
`/v1/responses/compact`, and remote v2 compact requests.
- Add the existing logical context-window identifier as `window_id` on
turn-owned model request metadata.
- Keep identity fields optional for detached memory requests, while
still emitting `request_kind="memory"` in non-git/no-sandbox workspaces.
## Root Cause
`x-codex-turn-metadata` has more than one producer. Foreground turns and
compaction requests own a real turn and should carry that turn identity.
Detached memory stage-one requests do not own a foreground turn, so
absent identity fields are valid rather than missing data. Startup
websocket prewarm is also a model request, but it has `generate=false`
and must not be counted as a foreground turn.
`thread_source` or session source identifies where a thread came from
(for example review, guardian, or another subagent). `request_kind`
identifies what the current outbound model request is doing (`turn`,
`prewarm`, `compaction`, or `memory`). A review or guardian thread can
issue either a normal turn request or a compaction request, so source
cannot replace request kind.
## Behavior / Impact
- Ordinary foreground requests send `request_kind="turn"`, their real
identity fields, and `window_id="<thread_id>:<window_generation>"`.
- Startup websocket warmup requests send `request_kind="prewarm"` so
they are not counted as foreground turns.
- Compaction requests send `request_kind="compaction"`, their real
owning turn identity, the existing `window_id`, and
`compaction.{trigger,reason,implementation,phase,strategy}`.
- Detached memory stage-one requests send `request_kind="memory"`
without `session_id`, `thread_id`, `turn_id`, or `window_id`; when no
workspace metadata exists, the kind-only header is still emitted.
- `session_id`, `thread_id`, `turn_id`, and `window_id` remain optional
in the header schema because detached memory requests do not own a
foreground turn or context window.
- `window_id` is not a new ID system: it is copied from the already-sent
`x-codex-window-id` / WS client metadata value at model-request dispatch
time.
- Existing `x-codex-window-id` HTTP/WS emission, value format,
generation advancement, resume behavior, and fork reset behavior are
unchanged.
- `request_kind`, `window_id`, and upstream turn-owned identity fields
remain schema-owned; input `responsesapi_client_metadata` cannot replace
their canonical values.
- No table, DAG, export, app-server API, or MCP `_meta` schema changes
are included.
A compaction attempt stopped by a pre-compact hook issues no model
request and therefore has no request header; its outcome remains in
analytics events. Status, error, duration, and token deltas also remain
analytics fields rather than request-header fields.
Future detached-memory attribution using a real initiating turn ID as
`trigger_turn_id` is intentionally not part of this PR.
## Sync With Main
- Final pushed head `716342e79` is rebased onto `origin/main@0d37db4b2`.
- The metadata conflict came from upstream `#24160`, which added
`forked_from_thread_id` on the same `turn_metadata` surface. Resolution
preserves that field and its protection from client metadata override
alongside this PR's request-kind, compaction, and window-id fields.
- While resolving the overlapping commits, I removed an accidental
recursive model-request overlay and a duplicate detached-memory header
builder before completing the rebase.
## Latency / User Experience Boundary
- Foreground turns perform no new filesystem, git, or network work. New
fields are inserted into metadata already serialized for outgoing
requests.
- Compaction issues the same model/HTTP requests with the same prompt,
model, service tier, and sampling settings; only metadata bytes change.
- Startup prewarm already sent metadata; it is now correctly classified
as `prewarm`.
- Non-git detached memory now sends a small kind-only metadata header
rather than no header.
- This client diff adds no user-visible latency mechanism beyond
negligible serialization and header bytes on already-existing requests.
## Validation
On conflict-resolved head `1d35c2cfb` based on `origin/main@487521733`:
- `just fmt` (passed)
- `just fix -p codex-core` (passed)
- `git diff --check origin/main...HEAD` (passed)
- `just test -p codex-core -E 'test(turn_metadata) |
test(websocket_first_turn_uses_startup_prewarm_and_create) |
test(responses_stream_includes_turn_metadata_header_for_git_workspace_e2e)
|
test(responses_websocket_forwards_turn_metadata_on_initial_and_incremental_create)
| test(remote_compact_v2_retries_failures_with_stream_retry_budget) |
test(window_id_advances_after_compact_persists_on_resume_and_resets_on_fork)'`
(`23 passed`; `bench-smoke` passed)
- `just test -p codex-app-server -E
'test(turn_start_forwards_client_metadata_to_responses_request_v2) |
test(turn_start_forwards_client_metadata_to_responses_websocket_request_body_v2)
| test(auto_compaction_remote_emits_started_and_completed_items)'` (`3
passed`; `bench-smoke` passed)
- `just test -p codex-memories-write` (`29 passed`; `bench-smoke`
passed)
514 lines
17 KiB
Rust
514 lines
17 KiB
Rust
use std::collections::BTreeMap;
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
use std::sync::Mutex;
|
|
use std::sync::RwLock;
|
|
use std::sync::atomic::AtomicBool;
|
|
use std::sync::atomic::Ordering;
|
|
|
|
use codex_analytics::CompactionImplementation;
|
|
use codex_analytics::CompactionPhase;
|
|
use codex_analytics::CompactionReason;
|
|
use codex_analytics::CompactionStrategy;
|
|
use codex_analytics::CompactionTrigger;
|
|
use codex_utils_string::to_ascii_json_string;
|
|
use serde::Serialize;
|
|
use serde_json::Value;
|
|
use tokio::task::JoinHandle;
|
|
|
|
use crate::sandbox_tags::permission_profile_sandbox_tag;
|
|
use codex_git_utils::get_git_remote_urls_assume_git_repo;
|
|
use codex_git_utils::get_git_repo_root;
|
|
use codex_git_utils::get_has_changes;
|
|
use codex_git_utils::get_head_commit_hash;
|
|
use codex_protocol::ThreadId;
|
|
use codex_protocol::config_types::WindowsSandboxLevel;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;
|
|
use codex_protocol::protocol::ThreadSource;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
|
|
const MODEL_KEY: &str = "model";
|
|
const REASONING_EFFORT_KEY: &str = "reasoning_effort";
|
|
const TURN_STARTED_AT_UNIX_MS_KEY: &str = "turn_started_at_unix_ms";
|
|
const USER_INPUT_REQUESTED_DURING_TURN_KEY: &str = "user_input_requested_during_turn";
|
|
const REQUEST_KIND_KEY: &str = "request_kind";
|
|
const COMPACTION_KEY: &str = "compaction";
|
|
const WINDOW_ID_KEY: &str = "window_id";
|
|
|
|
pub(crate) struct McpTurnMetadataContext<'a> {
|
|
pub(crate) model: &'a str,
|
|
pub(crate) reasoning_effort: Option<ReasoningEffortConfig>,
|
|
}
|
|
|
|
/// Metadata present only on outbound model requests that perform compaction.
|
|
///
|
|
/// These fields describe the operation at dispatch time. Post-response outcomes such as status,
|
|
/// error, duration, and token deltas remain in compaction analytics events.
|
|
#[derive(Clone, Copy, Debug, Serialize)]
|
|
pub(crate) struct CompactionTurnMetadata {
|
|
trigger: CompactionTrigger,
|
|
reason: CompactionReason,
|
|
implementation: CompactionImplementation,
|
|
phase: CompactionPhase,
|
|
strategy: CompactionStrategy,
|
|
}
|
|
|
|
impl CompactionTurnMetadata {
|
|
pub(crate) fn new(
|
|
trigger: CompactionTrigger,
|
|
reason: CompactionReason,
|
|
implementation: CompactionImplementation,
|
|
phase: CompactionPhase,
|
|
) -> Self {
|
|
Self {
|
|
trigger,
|
|
reason,
|
|
implementation,
|
|
phase,
|
|
strategy: CompactionStrategy::Memento,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
enum TurnMetadataRequestKind {
|
|
Turn,
|
|
Prewarm,
|
|
Compaction,
|
|
Memory,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
struct WorkspaceGitMetadata {
|
|
associated_remote_urls: Option<BTreeMap<String, String>>,
|
|
latest_git_commit_hash: Option<String>,
|
|
has_changes: Option<bool>,
|
|
}
|
|
|
|
impl WorkspaceGitMetadata {
|
|
fn is_empty(&self) -> bool {
|
|
self.associated_remote_urls.is_none()
|
|
&& self.latest_git_commit_hash.is_none()
|
|
&& self.has_changes.is_none()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Default)]
|
|
struct TurnMetadataWorkspace {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
associated_remote_urls: Option<BTreeMap<String, String>>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
latest_git_commit_hash: Option<String>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
has_changes: Option<bool>,
|
|
}
|
|
|
|
impl From<WorkspaceGitMetadata> for TurnMetadataWorkspace {
|
|
fn from(value: WorkspaceGitMetadata) -> Self {
|
|
Self {
|
|
associated_remote_urls: value.associated_remote_urls,
|
|
latest_git_commit_hash: value.latest_git_commit_hash,
|
|
has_changes: value.has_changes,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Base payload for the outbound model request `x-codex-turn-metadata` header.
|
|
///
|
|
/// Turn-owned state populates identity fields, including optional fork lineage. A concrete
|
|
/// request kind is added at outbound model dispatch so turns, startup prewarm, and compaction
|
|
/// remain distinguishable. Detached memory requests are constructed as `memory` directly.
|
|
#[derive(Clone, Debug, Serialize)]
|
|
pub(crate) struct TurnMetadataBag {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
request_kind: Option<TurnMetadataRequestKind>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
session_id: Option<String>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
thread_id: Option<String>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
forked_from_thread_id: Option<ThreadId>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
thread_source: Option<ThreadSource>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
turn_id: Option<String>,
|
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
workspaces: BTreeMap<String, TurnMetadataWorkspace>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
sandbox: Option<String>,
|
|
}
|
|
|
|
impl TurnMetadataBag {
|
|
fn new(
|
|
request_kind: Option<TurnMetadataRequestKind>,
|
|
session_id: Option<String>,
|
|
thread_id: Option<String>,
|
|
forked_from_thread_id: Option<ThreadId>,
|
|
thread_source: Option<ThreadSource>,
|
|
turn_id: Option<String>,
|
|
sandbox: Option<String>,
|
|
) -> Self {
|
|
Self {
|
|
request_kind,
|
|
session_id,
|
|
thread_id,
|
|
forked_from_thread_id,
|
|
thread_source,
|
|
turn_id,
|
|
workspaces: BTreeMap::new(),
|
|
sandbox,
|
|
}
|
|
}
|
|
|
|
fn with_workspace_git_metadata(
|
|
mut self,
|
|
repo_root: Option<String>,
|
|
workspace_git_metadata: Option<WorkspaceGitMetadata>,
|
|
) -> Self {
|
|
if let (Some(repo_root), Some(workspace_git_metadata)) = (repo_root, workspace_git_metadata)
|
|
&& !workspace_git_metadata.is_empty()
|
|
{
|
|
self.workspaces
|
|
.insert(repo_root, workspace_git_metadata.into());
|
|
}
|
|
self
|
|
}
|
|
|
|
fn to_header_value(&self) -> Option<String> {
|
|
to_ascii_json_string(self).ok()
|
|
}
|
|
}
|
|
|
|
fn merge_turn_metadata(
|
|
header: &str,
|
|
turn_started_at_unix_ms: Option<i64>,
|
|
responsesapi_client_metadata: Option<&HashMap<String, String>>,
|
|
) -> Option<String> {
|
|
if turn_started_at_unix_ms.is_none() && responsesapi_client_metadata.is_none() {
|
|
return None;
|
|
}
|
|
|
|
let mut metadata = serde_json::from_str::<serde_json::Map<String, Value>>(header).ok()?;
|
|
if let Some(turn_started_at_unix_ms) = turn_started_at_unix_ms {
|
|
metadata.insert(
|
|
TURN_STARTED_AT_UNIX_MS_KEY.to_string(),
|
|
Value::Number(turn_started_at_unix_ms.into()),
|
|
);
|
|
}
|
|
if let Some(responsesapi_client_metadata) = responsesapi_client_metadata {
|
|
for (key, value) in responsesapi_client_metadata {
|
|
if matches!(
|
|
key.as_str(),
|
|
"session_id"
|
|
| "thread_id"
|
|
| "turn_id"
|
|
| TURN_STARTED_AT_UNIX_MS_KEY
|
|
| "forked_from_thread_id"
|
|
| REQUEST_KIND_KEY
|
|
| COMPACTION_KEY
|
|
| WINDOW_ID_KEY
|
|
) {
|
|
continue;
|
|
}
|
|
metadata
|
|
.entry(key.clone())
|
|
.or_insert_with(|| Value::String(value.clone()));
|
|
}
|
|
}
|
|
to_ascii_json_string(&metadata).ok()
|
|
}
|
|
|
|
pub async fn build_turn_metadata_header(
|
|
cwd: &AbsolutePathBuf,
|
|
sandbox: Option<&str>,
|
|
) -> Option<String> {
|
|
let repo_root = get_git_repo_root(cwd).map(|root| root.to_string_lossy().into_owned());
|
|
|
|
let (head_commit_hash, associated_remote_urls, has_changes) = tokio::join!(
|
|
get_head_commit_hash(cwd),
|
|
get_git_remote_urls_assume_git_repo(cwd),
|
|
get_has_changes(cwd),
|
|
);
|
|
let latest_git_commit_hash = head_commit_hash.map(|sha| sha.0);
|
|
TurnMetadataBag::new(
|
|
Some(TurnMetadataRequestKind::Memory),
|
|
/*session_id*/ None,
|
|
/*thread_id*/ None,
|
|
/*forked_from_thread_id*/ None,
|
|
/*thread_source*/ None,
|
|
/*turn_id*/ None,
|
|
sandbox.map(ToString::to_string),
|
|
)
|
|
.with_workspace_git_metadata(
|
|
repo_root,
|
|
Some(WorkspaceGitMetadata {
|
|
associated_remote_urls,
|
|
latest_git_commit_hash,
|
|
has_changes,
|
|
}),
|
|
)
|
|
.to_header_value()
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub(crate) struct TurnMetadataState {
|
|
cwd: AbsolutePathBuf,
|
|
repo_root: Option<String>,
|
|
base_metadata: TurnMetadataBag,
|
|
base_header: Option<String>,
|
|
enriched_header: Arc<RwLock<Option<String>>>,
|
|
turn_started_at_unix_ms: Arc<RwLock<Option<i64>>>,
|
|
responsesapi_client_metadata: Arc<RwLock<Option<HashMap<String, String>>>>,
|
|
user_input_requested_during_turn: Arc<AtomicBool>,
|
|
enrichment_task: Arc<Mutex<Option<JoinHandle<()>>>>,
|
|
}
|
|
|
|
impl TurnMetadataState {
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub(crate) fn new(
|
|
session_id: String,
|
|
thread_id: String,
|
|
forked_from_thread_id: Option<ThreadId>,
|
|
thread_source: Option<ThreadSource>,
|
|
turn_id: String,
|
|
cwd: AbsolutePathBuf,
|
|
permission_profile: &PermissionProfile,
|
|
windows_sandbox_level: WindowsSandboxLevel,
|
|
enforce_managed_network: bool,
|
|
) -> Self {
|
|
let repo_root = get_git_repo_root(&cwd).map(|root| root.to_string_lossy().into_owned());
|
|
let sandbox = Some(
|
|
permission_profile_sandbox_tag(
|
|
permission_profile,
|
|
windows_sandbox_level,
|
|
enforce_managed_network,
|
|
)
|
|
.to_string(),
|
|
);
|
|
let base_metadata = TurnMetadataBag::new(
|
|
/*request_kind*/ None,
|
|
Some(session_id),
|
|
Some(thread_id),
|
|
forked_from_thread_id,
|
|
thread_source,
|
|
Some(turn_id),
|
|
sandbox,
|
|
);
|
|
let base_header = base_metadata.to_header_value();
|
|
|
|
Self {
|
|
cwd,
|
|
repo_root,
|
|
base_metadata,
|
|
base_header,
|
|
enriched_header: Arc::new(RwLock::new(None)),
|
|
turn_started_at_unix_ms: Arc::new(RwLock::new(None)),
|
|
responsesapi_client_metadata: Arc::new(RwLock::new(None)),
|
|
user_input_requested_during_turn: Arc::new(AtomicBool::new(false)),
|
|
enrichment_task: Arc::new(Mutex::new(None)),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn current_header_value(&self) -> Option<String> {
|
|
let header = if let Some(header) = self
|
|
.enriched_header
|
|
.read()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
|
.as_ref()
|
|
.cloned()
|
|
{
|
|
header
|
|
} else {
|
|
self.base_header.clone()?
|
|
};
|
|
let turn_started_at_unix_ms = *self
|
|
.turn_started_at_unix_ms
|
|
.read()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
let responsesapi_client_metadata = self
|
|
.responsesapi_client_metadata
|
|
.read()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
|
.clone();
|
|
merge_turn_metadata(
|
|
&header,
|
|
turn_started_at_unix_ms,
|
|
responsesapi_client_metadata.as_ref(),
|
|
)
|
|
.or(Some(header))
|
|
}
|
|
|
|
pub(crate) fn current_meta_value_for_mcp_request(
|
|
&self,
|
|
context: McpTurnMetadataContext<'_>,
|
|
) -> Option<serde_json::Value> {
|
|
let header = self.current_header_value()?;
|
|
let mut metadata = serde_json::from_str::<serde_json::Map<String, Value>>(&header).ok()?;
|
|
metadata.remove(REQUEST_KIND_KEY);
|
|
metadata.insert(
|
|
MODEL_KEY.to_string(),
|
|
Value::String(context.model.to_string()),
|
|
);
|
|
match context.reasoning_effort {
|
|
Some(reasoning_effort) => {
|
|
metadata.insert(
|
|
REASONING_EFFORT_KEY.to_string(),
|
|
Value::String(reasoning_effort.to_string()),
|
|
);
|
|
}
|
|
None => {
|
|
metadata.remove(REASONING_EFFORT_KEY);
|
|
}
|
|
}
|
|
if self
|
|
.user_input_requested_during_turn
|
|
.load(Ordering::Relaxed)
|
|
{
|
|
metadata.insert(
|
|
USER_INPUT_REQUESTED_DURING_TURN_KEY.to_string(),
|
|
Value::Bool(true),
|
|
);
|
|
} else {
|
|
metadata.remove(USER_INPUT_REQUESTED_DURING_TURN_KEY);
|
|
}
|
|
Some(Value::Object(metadata))
|
|
}
|
|
|
|
fn current_header_value_for_model_request_kind(
|
|
&self,
|
|
window_id: &str,
|
|
request_kind: TurnMetadataRequestKind,
|
|
) -> Option<String> {
|
|
let header = self.current_header_value()?;
|
|
let mut metadata = serde_json::from_str::<serde_json::Map<String, Value>>(&header).ok()?;
|
|
metadata.insert(
|
|
REQUEST_KIND_KEY.to_string(),
|
|
serde_json::to_value(request_kind).ok()?,
|
|
);
|
|
metadata.insert(
|
|
WINDOW_ID_KEY.to_string(),
|
|
Value::String(window_id.to_string()),
|
|
);
|
|
to_ascii_json_string(&metadata).ok()
|
|
}
|
|
|
|
pub(crate) fn current_header_value_for_model_request(&self, window_id: &str) -> Option<String> {
|
|
self.current_header_value_for_model_request_kind(window_id, TurnMetadataRequestKind::Turn)
|
|
}
|
|
|
|
pub(crate) fn current_header_value_for_prewarm(&self, window_id: &str) -> Option<String> {
|
|
self.current_header_value_for_model_request_kind(
|
|
window_id,
|
|
TurnMetadataRequestKind::Prewarm,
|
|
)
|
|
}
|
|
|
|
pub(crate) fn current_header_value_for_compaction(
|
|
&self,
|
|
window_id: &str,
|
|
compaction: CompactionTurnMetadata,
|
|
) -> Option<String> {
|
|
let header = self.current_header_value_for_model_request_kind(
|
|
window_id,
|
|
TurnMetadataRequestKind::Compaction,
|
|
)?;
|
|
let mut metadata = serde_json::from_str::<serde_json::Map<String, Value>>(&header).ok()?;
|
|
metadata.insert(
|
|
COMPACTION_KEY.to_string(),
|
|
serde_json::to_value(compaction).ok()?,
|
|
);
|
|
to_ascii_json_string(&metadata).ok()
|
|
}
|
|
|
|
pub(crate) fn mark_user_input_requested_during_turn(&self) {
|
|
self.user_input_requested_during_turn
|
|
.store(true, Ordering::Relaxed);
|
|
}
|
|
|
|
pub(crate) fn set_responsesapi_client_metadata(
|
|
&self,
|
|
responsesapi_client_metadata: HashMap<String, String>,
|
|
) {
|
|
*self
|
|
.responsesapi_client_metadata
|
|
.write()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner) =
|
|
Some(responsesapi_client_metadata);
|
|
}
|
|
|
|
pub(crate) fn set_turn_started_at_unix_ms(&self, turn_started_at_unix_ms: i64) {
|
|
*self
|
|
.turn_started_at_unix_ms
|
|
.write()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner) = Some(turn_started_at_unix_ms);
|
|
}
|
|
|
|
pub(crate) fn spawn_git_enrichment_task(&self) {
|
|
if self.repo_root.is_none() {
|
|
return;
|
|
}
|
|
|
|
let mut task_guard = self
|
|
.enrichment_task
|
|
.lock()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
if task_guard.is_some() {
|
|
return;
|
|
}
|
|
|
|
let state = self.clone();
|
|
*task_guard = Some(tokio::spawn(async move {
|
|
let workspace_git_metadata = state.fetch_workspace_git_metadata().await;
|
|
let Some(repo_root) = state.repo_root.clone() else {
|
|
return;
|
|
};
|
|
|
|
let enriched_metadata = state
|
|
.base_metadata
|
|
.clone()
|
|
.with_workspace_git_metadata(Some(repo_root), Some(workspace_git_metadata));
|
|
if enriched_metadata.workspaces.is_empty() {
|
|
return;
|
|
}
|
|
|
|
if let Some(header_value) = enriched_metadata.to_header_value() {
|
|
*state
|
|
.enriched_header
|
|
.write()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner) = Some(header_value);
|
|
}
|
|
}));
|
|
}
|
|
|
|
pub(crate) fn cancel_git_enrichment_task(&self) {
|
|
let mut task_guard = self
|
|
.enrichment_task
|
|
.lock()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
if let Some(task) = task_guard.take() {
|
|
task.abort();
|
|
}
|
|
}
|
|
|
|
async fn fetch_workspace_git_metadata(&self) -> WorkspaceGitMetadata {
|
|
let (head_commit_hash, associated_remote_urls, has_changes) = tokio::join!(
|
|
get_head_commit_hash(&self.cwd),
|
|
get_git_remote_urls_assume_git_repo(&self.cwd),
|
|
get_has_changes(&self.cwd),
|
|
);
|
|
let latest_git_commit_hash = head_commit_hash.map(|sha| sha.0);
|
|
|
|
WorkspaceGitMetadata {
|
|
associated_remote_urls,
|
|
latest_git_commit_hash,
|
|
has_changes,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "turn_metadata_tests.rs"]
|
|
mod tests;
|