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(observation): classify opt-in plan-quality read failures (#201)

澄潭974ec9c7f146
diff --git a/crates/application/src/lib.rs b/crates/application/src/lib.rs
index 110258e0..b461bba0 100644
--- a/crates/application/src/lib.rs
+++ b/crates/application/src/lib.rs
@@ -713,7 +713,12 @@ impl ApplicationService {
.and_then(|intent| intent.get("view"))
.and_then(Value::as_str),
Some("analysis" | "routing_timeline")
- );
+ ) || matches!(operation, ObservationOperation::PlanQuality)
+ && request
+ .payload
+ .pointer("/intent/query/include_routing_observations")
+ .and_then(Value::as_bool)
+ == Some(true);
let result = match operation {
ObservationOperation::CapacityRead | ObservationOperation::CapacityUpdate => control
.capacity(
diff --git a/crates/daemon/src/control/runtime_timeline_retry_tests.rs b/crates/daemon/src/control/runtime_timeline_retry_tests.rs
index e434d768..4cd31815 100644
--- a/crates/daemon/src/control/runtime_timeline_retry_tests.rs
+++ b/crates/daemon/src/control/runtime_timeline_retry_tests.rs
@@ -3,10 +3,10 @@ use hiroute_application_api::{ErrorCode, ObservationReadIntentV2, ObservationRea
use hiroute_domain::RoutingTimelineQueryV1;
#[test]
-fn review_timeline_dispatch_exhausts_real_readers_then_recovers() {
+fn review_timeline_and_quality_dispatch_exhaust_real_readers_then_recover() {
#[cfg(unix)]
if crate::test_support::isolated_agent_home(
- "control::runtime::tests::timeline_retry_tests::review_timeline_dispatch_exhausts_real_readers_then_recovers",
+ "control::runtime::tests::timeline_retry_tests::review_timeline_and_quality_dispatch_exhaust_real_readers_then_recover",
) {
return;
}
@@ -47,21 +47,55 @@ fn review_timeline_dispatch_exhausts_real_readers_then_recovers() {
payload: serde_json::to_value(query).unwrap(),
protected_grant: None,
};
- // Keep all production reader permits held across two real dispatches. No
- // port or failure envelope is mocked; releasing the permits permits recovery.
- runtime.observation.with_all_query_permits_for_test(|| {
- for _ in 0..2 {
+ let quality = ObservationReadRequestV2::new(ObservationReadIntentV2::PlanQuality(Box::new(
+ serde_json::from_value(json!({
+ "plan_id": "plan/codex-daily", "limit": 50,
+ "include_routing_observations": true,
+ }))
+ .unwrap(),
+ )));
+ let quality_request = LocalControlRequestV2 {
+ request_id: "quality-busy".into(),
+ operation_id: quality.operation().into(),
+ payload: serde_json::to_value(quality).unwrap(),
+ ..request.clone()
+ };
+ let mut legacy_request = quality_request.clone();
+ legacy_request.payload["intent"]["query"]
+ .as_object_mut()
+ .unwrap()
+ .remove("include_routing_observations");
+ let mut disabled_request = quality_request.clone();
+ disabled_request.payload["intent"]["query"]["include_routing_observations"] = json!(false);
+ for (request, detailed) in [
+ (request, true),
+ (quality_request, true),
+ (legacy_request, false),
+ (disabled_request, false),
+ ] {
+ // Exercise real permit exhaustion and recovery through Application.
+ // Released strict quality readers retain their original failure shape.
+ runtime.observation.with_all_query_permits_for_test(|| {
let response = application.dispatch(request.clone());
let wire = serde_json::to_value(&response).unwrap();
+ assert_eq!(
+ response.request_id.as_deref(),
+ Some(request.request_id.as_str())
+ );
let error = response.error.unwrap();
assert_eq!(error.code, ErrorCode::ObservationUnavailable, "{wire}");
- assert!(error.retryable, "{wire}");
- assert_eq!(error.details_schema, "hiroute.observation.read-failure/v1");
- assert_eq!(wire["error"]["observation_read"]["reason"], "reader_busy");
- assert_eq!(wire["error"]["observation_read"]["retry_after_ms"], 100);
- }
- });
- let response = application.dispatch(request);
- assert!(response.error.is_none(), "{response:?}");
- assert!(response.data.is_some());
+ assert_eq!(error.retryable, detailed, "{wire}");
+ if detailed {
+ assert_eq!(error.details_schema, "hiroute.observation.read-failure/v1");
+ assert_eq!(wire["error"]["observation_read"]["reason"], "reader_busy");
+ assert_eq!(wire["error"]["observation_read"]["retry_after_ms"], 100);
+ } else {
+ assert_eq!(error.details_schema, "hiroute.error-details/none-v1");
+ assert!(error.observation_read.is_none());
+ }
+ });
+ let response = application.dispatch(request);
+ assert!(response.error.is_none(), "{response:?}");
+ assert!(response.data.is_some());
+ }
}
diff --git a/issue-spec/specs/session-history/spec.md b/issue-spec/specs/session-history/spec.md
index 45f0c866..faf765b0 100644
--- a/issue-spec/specs/session-history/spec.md
+++ b/issue-spec/specs/session-history/spec.md
@@ -274,6 +274,13 @@ body stays unavailable and cannot be rebuilt from a score explanation. Public
read-only facts, help/schema discovery, and cursor without content/model calls.
Competence is stage performance, not task acceptance rate or universal model ranking.
+Plan-quality reads opting into `include_routing_observations=true` SHALL expose
+bounded-read failures through the existing `hiroute.observation.read-failure/v1`
+details. Timeout and reader exhaustion remain retryable failures with their
+distinct reasons and bounded retry hints, never empty success. This does not
+increase the read deadline, reader count or automatic retries. Omitted/false
+retains the released strict failure shape.
+
#### Scenario: Read routing evidence beside unrelated retained facts
- **WHEN** a Plan-quality read includes routing observations and the workspace retains many unrelated safe facts