Retain prompt resume resize until route transition
This commit is contained in:
parent
46b52b4b43
commit
29bc02fd7b
1 changed files with 84 additions and 13 deletions
|
|
@ -188,12 +188,14 @@ struct PendingPrompt {
|
|||
authority: VerifiedSession,
|
||||
prompt: TerminalPrompt,
|
||||
emitted: bool,
|
||||
resumed_size: Option<TerminalResize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct RoutedPromptDecision {
|
||||
pub signed_decision: Vec<u8>,
|
||||
pub decision: DeveloperDecision,
|
||||
pub resumed_size: Option<TerminalResize>,
|
||||
}
|
||||
|
||||
pub struct SessionPromptTransport {
|
||||
|
|
@ -264,6 +266,7 @@ impl SessionPromptTransport {
|
|||
authority,
|
||||
prompt: prompt.clone(),
|
||||
emitted: false,
|
||||
resumed_size: None,
|
||||
},
|
||||
);
|
||||
Ok(prompt)
|
||||
|
|
@ -288,7 +291,7 @@ impl SessionPromptTransport {
|
|||
&self,
|
||||
session_id: SessionId,
|
||||
signed_decision: Vec<u8>,
|
||||
) -> Result<DeveloperDecision, TerminalError> {
|
||||
) -> Result<RoutedPromptDecision, TerminalError> {
|
||||
let mut prompts = self
|
||||
.pending
|
||||
.lock()
|
||||
|
|
@ -304,19 +307,40 @@ impl SessionPromptTransport {
|
|||
pending.prompt.request_sha256,
|
||||
)
|
||||
.map_err(|_| TerminalError::PromptValidation)?;
|
||||
let resumed_size = pending.resumed_size;
|
||||
prompts.remove(&session_id);
|
||||
drop(prompts);
|
||||
Ok(RoutedPromptDecision {
|
||||
signed_decision,
|
||||
decision,
|
||||
resumed_size,
|
||||
})
|
||||
}
|
||||
|
||||
fn retain_prompt_resize(&self, resize: TerminalResize) -> Result<bool, TerminalError> {
|
||||
let mut prompts = self
|
||||
.pending
|
||||
.lock()
|
||||
.map_err(|_| TerminalError::PromptValidation)?;
|
||||
let Some(pending) = prompts.get_mut(&resize.session_id) else {
|
||||
return Ok(false);
|
||||
};
|
||||
if !pending.emitted {
|
||||
return Err(TerminalError::InactiveRoute);
|
||||
}
|
||||
pending.resumed_size = Some(resize);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn publish_decision(
|
||||
&self,
|
||||
session_id: SessionId,
|
||||
decision: RoutedPromptDecision,
|
||||
) -> Result<(), TerminalError> {
|
||||
self.routed
|
||||
.lock()
|
||||
.map_err(|_| TerminalError::PromptValidation)?
|
||||
.insert(
|
||||
session_id,
|
||||
RoutedPromptDecision {
|
||||
signed_decision,
|
||||
decision: decision.clone(),
|
||||
},
|
||||
);
|
||||
Ok(decision)
|
||||
.insert(session_id, decision);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restore_sandbox_route(&self, session_id: SessionId) -> Result<(), TerminalError> {
|
||||
|
|
@ -719,6 +743,19 @@ impl InteractiveControlSession for RunscInteractiveControlSession {
|
|||
) -> Result<InteractiveSessionBatch, ControlError> {
|
||||
let mut engine = self.engine.lock().map_err(|_| ControlError::LockPoisoned)?;
|
||||
let mut messages = match event {
|
||||
InteractiveSessionEvent::Terminal(SessionTerminalEvent::Resize(resize)) => {
|
||||
if self
|
||||
.prompt_transport
|
||||
.retain_prompt_resize(resize)
|
||||
.map_err(|error| terminal_control_error(&error))?
|
||||
{
|
||||
Vec::new()
|
||||
} else {
|
||||
engine
|
||||
.handle(self.generation_id, SessionTerminalEvent::Resize(resize))
|
||||
.map_err(|error| terminal_control_error(&error))?
|
||||
}
|
||||
}
|
||||
InteractiveSessionEvent::Terminal(event) => engine
|
||||
.handle(self.generation_id, event)
|
||||
.map_err(|error| terminal_control_error(&error))?,
|
||||
|
|
@ -733,14 +770,23 @@ impl InteractiveControlSession for RunscInteractiveControlSession {
|
|||
.prompt_transport
|
||||
.route_decision(session_id, signed_decision)
|
||||
.map_err(|error| terminal_control_error(&error))?;
|
||||
if decision.decision == lazaret_core::records::DeveloperDecisionKind::Deny {
|
||||
if decision.decision.decision == lazaret_core::records::DeveloperDecisionKind::Deny
|
||||
{
|
||||
self.prompt_transport
|
||||
.restore_sandbox_route(session_id)
|
||||
.map_err(|error| terminal_control_error(&error))?;
|
||||
engine
|
||||
.set_route(session_id, self.generation_id, TerminalRoute::Sandbox)
|
||||
.map_err(|error| terminal_control_error(&error))?;
|
||||
if let Some(resize) = decision.resumed_size {
|
||||
engine
|
||||
.handle(self.generation_id, SessionTerminalEvent::Resize(resize))
|
||||
.map_err(|error| terminal_control_error(&error))?;
|
||||
}
|
||||
}
|
||||
self.prompt_transport
|
||||
.publish_decision(session_id, decision)
|
||||
.map_err(|error| terminal_control_error(&error))?;
|
||||
Vec::new()
|
||||
}
|
||||
InteractiveSessionEvent::PromptDecision { .. }
|
||||
|
|
|
|||
Loading…
Reference in a new issue