Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/decodex/src/orchestrator/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub(crate) fn print_status(
eyre::bail!("`status --limit` must be greater than zero.");
}

let state_store = runtime::open_runtime_store()?;
let state_store = runtime::open_runtime_store_lazy()?;
let Some(config_path) = resolve_config_path(config_path, &state_store)? else {
eyre::bail!(
"No Decodex project config found. Pass this command's --config <PROJECT_DIR> or register one with `decodex project add <PROJECT_DIR>`."
Expand Down
11 changes: 9 additions & 2 deletions apps/decodex/src/orchestrator/operator_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,23 @@ fn build_operator_run_activity_event(
};
let (leased_runs, recent_runs) =
state_store.list_project_runs(project.service_id(), DEFAULT_OPERATOR_DASHBOARD_RUN_LIMIT)?;
let loop_evidence = state_store.project_loop_evidence_snapshot(project.service_id())?;
let project_display_name = operator_project_display_name(&project);
let recent_runs = recent_runs
.into_iter()
.map(|run| {
operator_run_status(&project, state_store, &project_display_name, run, now_unix_epoch)
operator_run_status(
&project,
&loop_evidence,
&project_display_name,
run,
now_unix_epoch,
)
})
.collect::<Result<Vec<_>>>()?;
let project_active_runs = operator_active_run_statuses(
&project,
state_store,
&loop_evidence,
&project_display_name,
leased_runs,
&recent_runs,
Expand Down
103 changes: 61 additions & 42 deletions apps/decodex/src/orchestrator/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use github::GhCommandResolution;
use state::WORKTREE_PROVENANCE_FILESYSTEM_SCAN;
use state::WORKTREE_PROVENANCE_GIT_HYGIENE_SCAN;
use state::WORKTREE_PROVENANCE_LEGACY_UNKNOWN;
use state::ProjectLoopEvidenceSnapshot;

use crate::pull_request::{self, PullRequestLandingGateView};
use crate::worktree;
Expand Down Expand Up @@ -306,16 +307,23 @@ fn build_operator_status_snapshot_with_account_mode(
) -> crate::prelude::Result<OperatorStatusSnapshot> {
let now_unix_epoch = OffsetDateTime::now_utc().unix_timestamp();
let (leased_runs, recent_runs) = state_store.list_project_runs(project.service_id(), limit)?;
let loop_evidence = state_store.project_loop_evidence_snapshot(project.service_id())?;
let project_display_name = operator_project_display_name(project);
let recent_runs = recent_runs
.into_iter()
.map(|run| {
operator_run_status(project, state_store, &project_display_name, run, now_unix_epoch)
operator_run_status(
project,
&loop_evidence,
&project_display_name,
run,
now_unix_epoch,
)
})
.collect::<crate::prelude::Result<Vec<_>>>()?;
let active_runs = operator_active_run_statuses(
project,
state_store,
&loop_evidence,
&project_display_name,
leased_runs,
&recent_runs,
Expand Down Expand Up @@ -376,6 +384,7 @@ fn build_lane_inspect_operator_runs(
) -> crate::prelude::Result<Vec<OperatorRunStatus>> {
let now_unix_epoch = OffsetDateTime::now_utc().unix_timestamp();
let (active_runs, recent_runs) = state_store.list_project_runs(project.service_id(), limit)?;
let loop_evidence = state_store.project_loop_evidence_snapshot(project.service_id())?;
let project_display_name = operator_project_display_name(project);
let mut seen_run_ids = HashSet::new();
let mut runs = Vec::new();
Expand All @@ -393,7 +402,7 @@ fn build_lane_inspect_operator_runs(

runs.push(operator_run_status(
project,
state_store,
&loop_evidence,
&project_display_name,
run,
now_unix_epoch,
Expand Down Expand Up @@ -421,15 +430,23 @@ fn project_run_status_issue_matches(run: &ProjectRunStatus, issue: &str) -> bool

fn operator_active_run_statuses(
project: &ServiceConfig,
state_store: &StateStore,
loop_evidence: &ProjectLoopEvidenceSnapshot,
project_display_name: &str,
leased_runs: Vec<ProjectRunStatus>,
recent_runs: &[OperatorRunStatus],
now_unix_epoch: i64,
) -> crate::prelude::Result<Vec<OperatorRunStatus>> {
let mut active_runs = leased_runs
.into_iter()
.map(|run| operator_run_status(project, state_store, project_display_name, run, now_unix_epoch))
.map(|run| {
operator_run_status(
project,
loop_evidence,
project_display_name,
run,
now_unix_epoch,
)
})
.collect::<crate::prelude::Result<Vec<_>>>()?
.into_iter()
.filter(operator_run_counts_as_active)
Expand Down Expand Up @@ -4960,7 +4977,7 @@ fn append_primary_account_if_missing(

fn operator_run_status(
project: &ServiceConfig,
state_store: &StateStore,
loop_evidence: &ProjectLoopEvidenceSnapshot,
project_display_name: &str,
run: ProjectRunStatus,
now_unix_epoch: i64,
Expand All @@ -4970,7 +4987,7 @@ fn operator_run_status(
let app_server_state = operator_run_app_server_state(&run, marker.as_ref());
let protocol_summary = operator_run_protocol_summary(&run, marker.as_ref());
let terminal_finalize_projection =
operator_run_terminal_finalize_projection(project, state_store, &run)?;
operator_run_terminal_finalize_projection(loop_evidence, &run);
let lifecycle = operator_run_lifecycle_projection(
&run,
marker.as_ref(),
Expand Down Expand Up @@ -5005,7 +5022,7 @@ fn operator_run_status(
let loop_status =
operator_run_loop_status(
project,
state_store,
loop_evidence,
&run,
&lifecycle.status,
&lifecycle.phase,
Expand Down Expand Up @@ -5188,15 +5205,15 @@ fn operator_run_private_evidence(

fn operator_run_loop_status(
project: &ServiceConfig,
state_store: &StateStore,
loop_evidence: &ProjectLoopEvidenceSnapshot,
run: &ProjectRunStatus,
status: &str,
phase: &str,
current_operation: &str,
) -> crate::prelude::Result<OperatorLoopStatus> {
operator_loop_status_for_run(
operator_loop_status_for_run_with_evidence(
project,
state_store,
loop_evidence,
run.issue_id(),
run.run_id(),
run.attempt_number(),
Expand Down Expand Up @@ -5260,22 +5277,38 @@ fn operator_loop_status_for_run(
default_review_phase: Option<&str>,
lifecycle_summary: Option<String>,
) -> crate::prelude::Result<OperatorLoopStatus> {
let review_level = project.codex().review_level();
let review = operator_review_loop_status(
review_level,
state_store,
project.service_id(),
let loop_evidence = state_store.project_loop_evidence_snapshot(project.service_id())?;

operator_loop_status_for_run_with_evidence(
project,
&loop_evidence,
issue_id,
run_id,
attempt_number,
default_review_phase,
)?;
let events = state_store.list_private_execution_events(
project.service_id(),
lifecycle_summary,
)
}

fn operator_loop_status_for_run_with_evidence(
project: &ServiceConfig,
loop_evidence: &ProjectLoopEvidenceSnapshot,
issue_id: &str,
run_id: &str,
attempt_number: i64,
default_review_phase: Option<&str>,
lifecycle_summary: Option<String>,
) -> crate::prelude::Result<OperatorLoopStatus> {
let review_level = project.codex().review_level();
let review = operator_review_loop_status(
review_level,
loop_evidence,
issue_id,
run_id,
attempt_number,
default_review_phase,
)?;
let events = loop_evidence.private_events(issue_id, run_id, attempt_number);
let architecture_recovery = events
.iter()
.rev()
Expand Down Expand Up @@ -5320,8 +5353,7 @@ fn operator_loop_status_for_run(

fn operator_review_loop_status(
review_level: ReviewLevel,
state_store: &StateStore,
project_id: &str,
loop_evidence: &ProjectLoopEvidenceSnapshot,
issue_id: &str,
run_id: &str,
attempt_number: i64,
Expand All @@ -5330,12 +5362,8 @@ fn operator_review_loop_status(
let latest_checkpoint = ["handoff", "repair"]
.into_iter()
.filter_map(|phase| {
state_store
.review_policy_checkpoint(project_id, issue_id, run_id, attempt_number, phase)
.transpose()
loop_evidence.review_policy_checkpoint(issue_id, run_id, attempt_number, phase)
})
.collect::<crate::prelude::Result<Vec<_>>>()?
.into_iter()
.max_by(|left, right| {
left.updated_at_unix()
.cmp(&right.updated_at_unix())
Expand Down Expand Up @@ -5797,27 +5825,18 @@ fn operator_run_protocol_summary(
}

fn operator_run_terminal_finalize_projection(
project: &ServiceConfig,
state_store: &StateStore,
loop_evidence: &ProjectLoopEvidenceSnapshot,
run: &ProjectRunStatus,
) -> crate::prelude::Result<Option<OperatorTerminalFinalizeProjection>> {
let events = state_store.list_private_execution_events(
project.service_id(),
run.issue_id(),
run.run_id(),
run.attempt_number(),
)?;
let Some(path) = events
) -> Option<OperatorTerminalFinalizeProjection> {
let events = loop_evidence.private_events(run.issue_id(), run.run_id(), run.attempt_number());
let path = events
.iter()
.rev()
.find(|event| event.event_type() == "terminal_finalize")
.and_then(|event| event.payload().get("path"))
.and_then(Value::as_str)
else {
return Ok(None);
};
.and_then(Value::as_str)?;

Ok(match path {
match path {
"review_handoff" => Some(OperatorTerminalFinalizeProjection {
status: "review_handoff_pending",
phase: "terminal_pending",
Expand All @@ -5843,7 +5862,7 @@ fn operator_run_terminal_finalize_projection(
current_operation: RUN_OPERATION_REVIEW_WRITEBACK,
}),
_ => None,
})
}
}

fn operator_run_visible_status(
Expand Down
5 changes: 5 additions & 0 deletions apps/decodex/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ pub(crate) fn open_runtime_store() -> Result<StateStore> {
StateStore::open(runtime_db_path()?)
}

/// Open the global runtime database without preloading all durable rows.
pub(crate) fn open_runtime_store_lazy() -> Result<StateStore> {
StateStore::open_lazy(runtime_db_path()?)
}

/// Register or refresh one project config in the global runtime DB.
pub(crate) fn register_project_config(
state_store: &StateStore,
Expand Down
2 changes: 1 addition & 1 deletion apps/decodex/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
cmp,
collections::{HashMap, HashSet},
fs::{self, File, OpenOptions, TryLockError},
io::{Error, ErrorKind, Read, Seek, SeekFrom, Write},
io::{ErrorKind, Read, Seek, SeekFrom, Write},
path::{Path, PathBuf},
process,
sync::{Mutex, MutexGuard, OnceLock},
Expand Down
Loading