Skip to content

Commit d700b45

Browse files
committed
feat(sandbox): add /v1/proposals/{id} and /wait long-poll to policy.local
The agent feedback channel back from policy.local. Two new routes let the in-sandbox agent learn its proposal's outcome on a single blocking HTTP call — zero LLM tokens during the wait. - GET /v1/proposals/{chunk_id} returns the chunk's current state in one gateway call. - GET /v1/proposals/{chunk_id}/wait?timeout=<s> blocks until the chunk transitions out of pending. Default 60s, clamped [1, 300]. Agent re-issues on timeout to extend. Response carries the chunk's status plus the two feedback fields shipped in the prereq commit: rejection_reason (free-form reviewer text) and validation_result (gateway prover verdict, empty until #1097). On timeout: same shape with timed_out: true so the agent can disambiguate without parsing. Wait handler short-polls GetDraftPolicy every 1s inside the request with a tokio::time::Instant deadline. One gateway connection is opened per request and reused across all polls, so a 60s wait does one TLS handshake instead of sixty. A future commit can swap the loop body for a tokio::sync::broadcast driven by a watcher task — the agent-visible contract (URL, query, response shape) is independent of the polling implementation. All routes stay behind agent_policy_proposals_enabled. Closes #1092. Signed-off-by: Alexander Watson <[email protected]>
1 parent 9883a70 commit d700b45

2 files changed

Lines changed: 350 additions & 5 deletions

File tree

‎crates/openshell-sandbox/src/grpc_client.rs‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use std::time::Duration;
99

1010
use miette::{IntoDiagnostic, Result, WrapErr};
1111
use openshell_core::proto::{
12-
DenialSummary, GetInferenceBundleRequest, GetInferenceBundleResponse, GetSandboxConfigRequest,
13-
GetSandboxProviderEnvironmentRequest, PolicySource, PolicyStatus, ReportPolicyStatusRequest,
14-
SandboxPolicy as ProtoSandboxPolicy, SubmitPolicyAnalysisRequest, SubmitPolicyAnalysisResponse,
15-
UpdateConfigRequest, inference_client::InferenceClient, open_shell_client::OpenShellClient,
12+
DenialSummary, GetDraftPolicyRequest, GetInferenceBundleRequest, GetInferenceBundleResponse,
13+
GetSandboxConfigRequest, GetSandboxProviderEnvironmentRequest, PolicyChunk, PolicySource,
14+
PolicyStatus, ReportPolicyStatusRequest, SandboxPolicy as ProtoSandboxPolicy,
15+
SubmitPolicyAnalysisRequest, SubmitPolicyAnalysisResponse, UpdateConfigRequest,
16+
inference_client::InferenceClient, open_shell_client::OpenShellClient,
1617
};
1718
use tonic::service::interceptor::InterceptedService;
1819
use tonic::transport::{Certificate, Channel, ClientTlsConfig, Endpoint, Identity};
@@ -339,7 +340,7 @@ impl CachedOpenShellClient {
339340
&self,
340341
sandbox_name: &str,
341342
summaries: Vec<DenialSummary>,
342-
proposed_chunks: Vec<openshell_core::proto::PolicyChunk>,
343+
proposed_chunks: Vec<PolicyChunk>,
343344
analysis_mode: &str,
344345
) -> Result<SubmitPolicyAnalysisResponse> {
345346
let response = self
@@ -357,6 +358,27 @@ impl CachedOpenShellClient {
357358
Ok(response.into_inner())
358359
}
359360

361+
/// Fetch the current draft chunks for a sandbox. `status_filter` may be
362+
/// `"pending"`, `"approved"`, `"rejected"`, or empty for all. Used by
363+
/// `policy.local`'s `GET /v1/proposals/{id}` and `/wait` routes to
364+
/// inspect proposal state.
365+
pub async fn get_draft_policy(
366+
&self,
367+
sandbox_name: &str,
368+
status_filter: &str,
369+
) -> Result<Vec<PolicyChunk>> {
370+
let response = self
371+
.client
372+
.clone()
373+
.get_draft_policy(GetDraftPolicyRequest {
374+
name: sandbox_name.to_string(),
375+
status_filter: status_filter.to_string(),
376+
})
377+
.await
378+
.into_diagnostic()?;
379+
Ok(response.into_inner().chunks)
380+
}
381+
360382
/// Report policy load status back to the server.
361383
pub async fn report_policy_status(
362384
&self,

0 commit comments

Comments
 (0)