Skip to content

Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.

fix(worker): report pending when no public progress has been saved (#106)

澄潭a4d72b8ceaf0
diff --git a/crates/daemon/src/control/runtime/delegation_reads.rs b/crates/daemon/src/control/runtime/delegation_reads.rs
index eb68235c..bc0e66da 100644
--- a/crates/daemon/src/control/runtime/delegation_reads.rs
+++ b/crates/daemon/src/control/runtime/delegation_reads.rs
@@ -77,9 +77,10 @@ impl LocalControlAdapter {
truncated: None,
};
match read {
+ // Prompt intent is execution evidence, not evidence that public text was saved.
ManagedTextProgressRead::Missing {
visibility_generation,
- } if !run.progress.prompt_may_have_executed => {
+ } => {
let cursor = ManagedTextProgressCursor {
visibility_generation,
segment: 0,
@@ -94,7 +95,6 @@ impl LocalControlAdapter {
data.truncated = Some(false);
Ok(data)
}
- ManagedTextProgressRead::Missing { .. } => Err(WorkerReadErrorV1::Unavailable),
ManagedTextProgressRead::Available(page) => {
let cursor = ManagedTextProgressCursor {
visibility_generation: page.visibility_generation,
diff --git a/crates/daemon/src/control/runtime_observation_tests.rs b/crates/daemon/src/control/runtime_observation_tests.rs
index 44583faf..261dc1db 100644
--- a/crates/daemon/src/control/runtime_observation_tests.rs
+++ b/crates/daemon/src/control/runtime_observation_tests.rs
@@ -32,6 +32,9 @@ use serde_json::json;
use super::*;
+#[path = "runtime_worker_read_empty_tests.rs"]
+mod worker_read_empty_tests;
+
#[test]
fn production_writer_store_drives_application_owned_defaults_and_all_plan_scope() {
#[cfg(unix)]
@@ -520,6 +523,16 @@ fn worker_read_uses_signed_run_cursors_reports_gap_and_preserves_b6_privacy() {
hiroute_application_api::ErrorCode::InvalidArguments
);
+ let running = worker_read_empty_tests::start_prompt(&runtime, &accepted);
+ let empty = worker_read(&service, run_id, Some(&pending_cursor), Some(32));
+ assert!(empty.error.is_none(), "{empty:?}");
+ let empty: WorkerReadDataV1 = serde_json::from_value(empty.data.unwrap()).unwrap();
+ assert!(empty.valid());
+ assert_eq!(empty.content_state, WorkerReadContentStateV1::Pending);
+ assert_eq!(empty.run_state, running.progress.state);
+ assert_eq!(empty.state_revision, running.progress.revision);
+ assert_eq!(empty.next_cursor.as_deref(), Some(pending_cursor.as_str()));
+
let target = ManagedTextProgressTarget {
scope: ManagedTextScope {
workspace_id: WorkspaceId::default(),
diff --git a/crates/daemon/src/control/runtime_worker_read_empty_tests.rs b/crates/daemon/src/control/runtime_worker_read_empty_tests.rs
new file mode 100644
index 00000000..61807165
--- /dev/null
+++ b/crates/daemon/src/control/runtime_worker_read_empty_tests.rs
@@ -0,0 +1,323 @@
+//! Public reads keep saved content independent of execution and cleanup evidence.
+
+use super::*;
+use hiroute_domain::delegation::{
+ DelegationProcessBindingV1, DelegationSessionBindingV1, RunCleanupV1, RunStateV1,
+};
+use rusqlite::{Connection, OpenFlags};
+
+#[test]
+fn worker_read_empty_progress_survives_reopen_and_residual_acknowledgement() {
+ #[cfg(unix)]
+ if crate::test_support::isolated_agent_home(
+ "control::runtime::tests::worker_read_empty_tests::worker_read_empty_progress_survives_reopen_and_residual_acknowledgement",
+ ) {
+ return;
+ }
+ let root = crate::test_support::private_tempdir();
+ let (runtime, mut run) = empty_progress_run(root.path());
+ let service = ApplicationService::new(runtime.application_ports());
+ let cursor = assert_pending(&runtime, &service, &run, None);
+ run = start_prompt(&runtime, &run);
+ assert_pending(&runtime, &service, &run, Some(&cursor));
+ assert_eq!(run.progress.state, RunStateV1::Running);
+ assert!(run.progress.prompt_may_have_executed);
+ run = advance(&runtime, &run, RunEventV1::ProcessUnknown);
+ assert_eq!(run.progress.state, RunStateV1::Unknown);
+ assert_eq!(run.progress.cleanup, RunCleanupV1::Unknown);
+ drop(service);
+ drop(runtime);
+
+ let reopened = ProductionControlRuntime::open_with_release_catalog(
+ root.path(),
+ crate::release_catalog::fixture_catalog(),
+ )
+ .unwrap();
+ let saved =
+ DelegationRuntimePort::run(reopened.adapter.as_ref(), &run.workspace_id, &run.run_id)
+ .unwrap()
+ .unwrap();
+ assert_eq!(saved, run);
+ let service = ApplicationService::new(reopened.application_ports());
+ assert_pending(&reopened, &service, &saved, Some(&cursor));
+ let acknowledged = checkpoint(
+ &reopened,
+ &saved,
+ DelegationCheckpointV1::ResidualConfirmed {
+ operation_id: hiroute_domain::OperationId::parse("op_00112233445566778899aabbccddeeff")
+ .unwrap(),
+ actor_id: "empty-progress-test".into(),
+ },
+ );
+ assert_eq!(acknowledged.progress.state, RunStateV1::Unknown);
+ assert_eq!(
+ acknowledged.progress.cleanup,
+ RunCleanupV1::ResidualAcknowledged
+ );
+ assert!(acknowledged.progress.workspace_releasable());
+ assert_pending(&reopened, &service, &acknowledged, Some(&cursor));
+}
+
+#[test]
+fn worker_read_empty_progress_preserves_terminal_execution_states() {
+ #[cfg(unix)]
+ if crate::test_support::isolated_agent_home(
+ "control::runtime::tests::worker_read_empty_tests::worker_read_empty_progress_preserves_terminal_execution_states",
+ ) {
+ return;
+ }
+ for (event, expected) in [
+ (RunEventV1::PromptCompleted, RunStateV1::Succeeded),
+ (RunEventV1::PromptFailed, RunStateV1::Failed),
+ (
+ RunEventV1::ManagedScopeStopped { success: true },
+ RunStateV1::Cancelled,
+ ),
+ ] {
+ let root = crate::test_support::private_tempdir();
+ let (runtime, mut run) = empty_progress_run(root.path());
+ run = start_prompt(&runtime, &run);
+ if expected == RunStateV1::Cancelled {
+ run = advance(&runtime, &run, RunEventV1::CancelRequested);
+ }
+ run = advance(&runtime, &run, event);
+ assert_eq!(run.progress.state, expected);
+ assert!(run.progress.prompt_may_have_executed);
+ let service = ApplicationService::new(runtime.application_ports());
+ assert_pending(&runtime, &service, &run, None);
+ }
+}
+
+#[test]
+fn worker_read_real_storage_failure_remains_an_error() {
+ #[cfg(unix)]
+ if crate::test_support::isolated_agent_home(
+ "control::runtime::tests::worker_read_empty_tests::worker_read_real_storage_failure_remains_an_error",
+ ) {
+ return;
+ }
+ let root = crate::test_support::private_tempdir();
+ let (runtime, run) = empty_progress_run(root.path());
+ let service = ApplicationService::new(runtime.application_ports());
+ let cursor = assert_pending(&runtime, &service, &run, None);
+ // Fault injection affects only this isolated fixture's observation database.
+ let connection = Connection::open(&runtime.adapter.observation_activity_path).unwrap();
+ connection
+ .execute("DROP TABLE managed_text_progress", [])
+ .unwrap();
+ let response = worker_read(&service, &run.run_id, Some(&cursor), Some(32));
+ assert!(response.data.is_none());
+ let error = response.error.unwrap();
+ assert_eq!(
+ error.code,
+ hiroute_application_api::ErrorCode::ObservationUnavailable
+ );
+ assert_eq!(error.message_key, "worker.read.storage_unavailable");
+ assert_eq!(
+ DelegationRuntimePort::run(runtime.adapter.as_ref(), &run.workspace_id, &run.run_id)
+ .unwrap()
+ .unwrap(),
+ run
+ );
+}
+
+fn empty_progress_run(root: &std::path::Path) -> (ProductionControlRuntime, DelegationRunV1) {
+ let runtime = ProductionControlRuntime::open_with_release_catalog(
+ root,
+ crate::release_catalog::fixture_catalog(),
+ )
+ .unwrap();
+ let now = SystemTime::now()
+ .duration_since(UNIX_EPOCH)
+ .unwrap()
+ .as_millis() as u64;
+ let body = runtime
+ .adapter
+ .persist_task_input(
+ &WorkspaceId::default(),
+ "task-empty",
+ "run-empty",
+ "goal",
+ now,
+ )
+ .unwrap();
+ let version = frozen_plan_version();
+ // Seed this query fixture's current frozen version; this is not publication evidence.
+ let connection = Connection::open(root.join("live/control.db")).unwrap();
+ connection
+ .execute(
+ "INSERT INTO plan_versions(
+ workspace_id,plan_id,content_revision,content_digest,version_json,state,
+ owner_operation_id
+ ) VALUES(?1,?2,?3,?4,?5,'published','empty-progress-fixture')",
+ rusqlite::params![
+ version.reference.workspace_id.as_str(),
+ version.reference.plan_id.as_str(),
+ version.reference.content_revision,
+ version.reference.content_digest.as_str(),
+ serde_json::to_string(&version).unwrap(),
+ ],
+ )
+ .unwrap();
+ let mut acceptance = worker_list_acceptance("task-empty", "run-empty", body, now);
+ acceptance.task.plan.plan_id = version.reference.plan_id.clone();
+ acceptance.task.plan.plan_revision = version.reference.content_revision;
+ acceptance.task.plan.plan_digest = version.reference.content_digest.clone();
+ acceptance.task.plan.model_alias = version.compiled.model_alias().as_str().into();
+ let run = DelegationRuntimePort::accept(runtime.adapter.as_ref(), &acceptance).unwrap();
+ (runtime, run)
+}
+
+fn frozen_plan_version() -> hiroute_domain::PlanVersionV1 {
+ use hiroute_domain::{
+ AgentPlanAuthoringV2, AgentPlanStrategyV2, CandidateSelectionV1, CapabilityRequirementsV1,
+ ExactNativeReasoningV1, PLAN_AUTHORING_SCHEMA_V2, PlanEditorMode, ReasoningSelectionV1,
+ };
+ let publication: hiroute_domain::GatewayPublicationV1 = serde_json::from_slice(include_bytes!(
+ "../../../../e2e/product/fixtures/routing/current-publication.v3.json"
+ ))
+ .unwrap();
+ let compiled = publication
+ .plans
+ .into_iter()
+ .find(|plan| plan.agent_plan_id().as_str() == "plan/custom")
+ .unwrap();
+ let candidates = compiled.body.materialized.attempt_owned.groups[0]
+ .candidates
+ .iter()
+ .map(|candidate| CandidateSelectionV1 {
+ binding_id: candidate.binding_id.clone(),
+ reasoning: match &candidate.exact_reasoning {
+ ExactNativeReasoningV1::Fixed { .. } => None,
+ ExactNativeReasoningV1::Toggle { enabled, .. } => {
+ Some(ReasoningSelectionV1::Toggle { enabled: *enabled })
+ }
+ ExactNativeReasoningV1::Profile { profile, .. } => {
+ Some(ReasoningSelectionV1::Profile {
+ profile: profile.clone(),
+ })
+ }
+ ExactNativeReasoningV1::Budget { tokens, .. } => {
+ Some(ReasoningSelectionV1::Budget { tokens: *tokens })
+ }
+ },
+ })
+ .collect();
+ hiroute_domain::PlanVersionV1::new(
+ WorkspaceId::default(),
+ AgentPlanAuthoringV2 {
+ schema: PLAN_AUTHORING_SCHEMA_V2.into(),
+ display_name: compiled.body.identity.display_name.clone(),
+ purpose: compiled.body.identity.purpose.clone(),
+ mode: PlanEditorMode::FixedModel,
+ requirements: CapabilityRequirementsV1::default(),
+ limits: compiled.body.materialized.attempt_owned.limits.clone(),
+ strategy: AgentPlanStrategyV2::Custom { candidates },
+ delegation_enabled: false,
+ work: None,
+ },
+ compiled,
+ )
+ .unwrap()
+}
+
+pub(super) fn start_prompt(
+ runtime: &ProductionControlRuntime,
+ accepted: &DelegationRunV1,
+) -> DelegationRunV1 {
+ let mut run = advance(runtime, accepted, RunEventV1::Preparing);
+ for event in [
+ DelegationCheckpointV1::ProcessSpawned {
+ binding: DelegationProcessBindingV1 {
+ launch_nonce: run.launch_nonce.clone(),
+ handle_id: "empty-progress-process".into(),
+ creation_identity: "empty-progress-created".into(),
+ },
+ },
+ DelegationCheckpointV1::SessionBound {
+ binding: DelegationSessionBindingV1 {
+ acp_session_id: "empty-progress-session".into(),
+ native_session_id: Some("empty-progress-native".into()),
+ },
+ },
+ DelegationCheckpointV1::Progress {
+ event: RunEventV1::PromptSendIntent,
+ },
+ ] {
+ run = checkpoint(runtime, &run, event);
+ }
+ run
+}
+
+fn advance(
+ runtime: &ProductionControlRuntime,
+ run: &DelegationRunV1,
+ event: RunEventV1,
+) -> DelegationRunV1 {
+ checkpoint(runtime, run, DelegationCheckpointV1::Progress { event })
+}
+
+fn checkpoint(
+ runtime: &ProductionControlRuntime,
+ run: &DelegationRunV1,
+ event: DelegationCheckpointV1,
+) -> DelegationRunV1 {
+ DelegationRuntimePort::checkpoint(
+ runtime.adapter.as_ref(),
+ &run.workspace_id,
+ &run.run_id,
+ run.progress.revision,
+ &format!("empty-progress-{}", run.progress.revision),
+ &event,
+ )
+ .unwrap()
+}
+
+fn assert_pending(
+ runtime: &ProductionControlRuntime,
+ service: &ApplicationService,
+ run: &DelegationRunV1,
+ cursor: Option<&str>,
+) -> String {
+ let before = progress_metadata(runtime);
+ assert_eq!(before, (0, 0, 0));
+ let response = worker_read(service, &run.run_id, cursor, Some(32));
+ assert!(response.error.is_none(), "{response:?}");
+ let data: WorkerReadDataV1 = serde_json::from_value(response.data.unwrap()).unwrap();
+ assert!(data.valid());
+ assert_eq!(data.content_state, WorkerReadContentStateV1::Pending);
+ assert_eq!(data.run_state, run.progress.state);
+ assert_eq!(data.state_revision, run.progress.revision);
+ assert_eq!(data.task_id, run.task_id);
+ assert_eq!(data.run_id, run.run_id);
+ assert_eq!(progress_metadata(runtime), before);
+ assert_eq!(
+ DelegationRuntimePort::run(runtime.adapter.as_ref(), &run.workspace_id, &run.run_id)
+ .unwrap()
+ .unwrap(),
+ *run
+ );
+ let next = data.next_cursor.unwrap();
+ if let Some(cursor) = cursor {
+ assert_eq!(next, cursor);
+ }
+ next
+}
+
+fn progress_metadata(runtime: &ProductionControlRuntime) -> (u64, u64, u64) {
+ let connection = Connection::open_with_flags(
+ &runtime.adapter.observation_activity_path,
+ OpenFlags::SQLITE_OPEN_READ_ONLY,
+ )
+ .unwrap();
+ connection
+ .query_row(
+ "SELECT
+ (SELECT COUNT(*) FROM managed_text_progress),
+ (SELECT COUNT(*) FROM managed_text_progress_blocks),
+ (SELECT next_order_seq FROM managed_text_progress_meta WHERE singleton=1)",
+ [],
+ |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
+ )
+ .unwrap()
+}
diff --git a/docs/code-map/worker-context.md b/docs/code-map/worker-context.md
index 6d3b3071..06f08d5d 100644
--- a/docs/code-map/worker-context.md
+++ b/docs/code-map/worker-context.md
@@ -35,7 +35,7 @@ restoration must verify ownership rather than infer it from a provider name.
| Confirm the native session/model | [ACP model confirmation](../../crates/daemon/src/delegation/acp/model.rs), [ACP driver](../../crates/daemon/src/delegation/acp/mod.rs) | Confirm the exact native model before prompt; missing capability cannot silently change the route |
| Continue the same task | [History binding](../../crates/daemon/src/delegation/profile/native_history.rs), [resume](../../crates/daemon/src/delegation/executor/resume.rs) | Restore the exact frozen context/session with a fresh credential; never select the newest history or start a replacement conversation |
| Start, cancel and finalize processes | [Executor](../../crates/daemon/src/delegation/executor.rs), [OS launcher](../../crates/daemon/src/delegation/local_worker/README.md), [finalization](../../crates/daemon/src/delegation/finalization.rs) | Explicit argv/environment/materials and owned process identity; stopping and successful task completion are separate facts |
-| Read, hide, expire or clean up content | [Reads](../../crates/daemon/src/control/runtime/delegation_reads.rs), [Continue admission](../../crates/daemon/src/control/runtime/delegation_continue.rs), [maintenance](../../crates/daemon/src/control/runtime/delegation_maintenance.rs), [native cleanup](../../crates/daemon/src/delegation/native_cleanup.rs) | Current content permission and exact cleanup ownership; borrowed history is not a deletion target |
+| Read, hide, expire or clean up content | [Reads](../../crates/daemon/src/control/runtime/delegation_reads.rs), [Continue admission](../../crates/daemon/src/control/runtime/delegation_continue.rs), [maintenance](../../crates/daemon/src/control/runtime/delegation_maintenance.rs), [native cleanup](../../crates/daemon/src/delegation/native_cleanup.rs) | Saved progress is independent of execution/cleanup state; current content permission and exact cleanup ownership still apply; borrowed history is not a deletion target |
## Ecosystem differences