Keep gRPC and WebSocket versioning the request they loaded

The previous commit had connect re-read the request by id inside its
transaction, which runs after template rendering and auth. An edit made
during those awaits would have been versioned even though the
connection used the earlier copy. Connect already holds the stored row
it loaded, so it goes back to snapshotting that; only the HTTP send,
whose request may arrive rendered, reads the stored row by id, through
the new snapshot_stored_request_for_send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Gregory SchierandClaude Opus 5.5 authored and Stetta task tk_mw563e1dcqtc4sqh committed 2026-11-06 10:42:41 -07:00
1 parent 34d0aed906
commit 17e719a646
4 files changed
+37 -20

No files matched your search

+3 -1
View File
@@ -40,6 +40,7 @@ use yaak_models::models::{
CookieJar, Environment, GrpcConnection, GrpcConnectionState, GrpcEvent, GrpcEventType,
HttpRequest, HttpResponse, HttpResponseState, Workspace,
};
use yaak_models::queries::any_request::AnyRequest;
use yaak_models::util::{BatchUpsertResult, ImportDestination, ImportPlan, UpdateSource};
use yaak_plugins::events::{
Color, ErrorResponse, FilterResponse, InternalEvent, InternalEventPayload, PluginContext,
@@ -334,7 +335,8 @@ async fn cmd_grpc_go<R: Runtime>(
let conn = app_handle.with_tx(|tx| {
// Capture the stored request, not the rendered one: what a restore should
// put back is what the user typed
let version_id = tx.snapshot_request_for_send(&unrendered_request.id);
let version_id =
tx.snapshot_request_for_send(&AnyRequest::GrpcRequest(unrendered_request.clone()));
tx.upsert_grpc_connection(
&GrpcConnection {
workspace_id: request.workspace_id.clone(),
+3 -1
View File
@@ -21,6 +21,7 @@ use yaak_models::models::{
HttpResponseHeader, WebsocketConnection, WebsocketConnectionState, WebsocketEvent,
WebsocketEventType,
};
use yaak_models::queries::any_request::AnyRequest;
use yaak_models::util::UpdateSource;
use yaak_plugins::events::{CallHttpAuthenticationRequest, HttpHeader, RenderPurpose};
use yaak_plugins::template_callback::PluginTemplateCallback;
@@ -175,7 +176,8 @@ pub async fn cmd_ws_connect<R: Runtime>(
let connection = app_handle.with_tx(|tx| {
// Capture the stored request, not the rendered one: what a restore should
// put back is what the user typed
let version_id = tx.snapshot_request_for_send(&unrendered_request.id);
let version_id =
tx.snapshot_request_for_send(&AnyRequest::WebsocketRequest(unrendered_request.clone()));
tx.upsert_websocket_connection(
&WebsocketConnection {
workspace_id: request.workspace_id.clone(),
@@ -104,30 +104,41 @@ impl<'a> WriteDb<'a> {
self.snapshot_request(&self.get_any_request(request_id)?, reason)
}
/// What every send calls: capture the request, and don't make a fuss.
/// What a send calls when all it has is the request's id: capture the
/// stored row, and don't make a fuss.
///
/// Takes an id rather than a request because the request a send holds is
/// not always the stored one: a plugin can send a request it has already
/// rendered, and a version of that would hold literal values, secrets
/// included, where the user wrote templates. The stored row is what a
/// restore should put back, so that is what gets captured.
///
/// A send is not worth failing over history that couldn't be written, and
/// a request with no id or no stored row is ephemeral and has nothing to
/// version. Either way the response just has no version to offer.
pub fn snapshot_request_for_send(&self, request_id: &str) -> Option<String> {
/// For sends whose request may not be the stored one: a plugin can send a
/// request it has already rendered, and a version of that would hold
/// literal values, secrets included, where the user wrote templates. The
/// stored row is what a restore should put back. A request with no id or
/// no stored row is ephemeral and has nothing to version.
pub fn snapshot_stored_request_for_send(&self, request_id: &str) -> Option<String> {
if request_id.is_empty() {
return None;
}
let stored = match self.get_any_request(request_id) {
Ok(stored) => stored,
Err(Error::ModelNotFound(_)) => return None,
match self.get_any_request(request_id) {
Ok(stored) => self.snapshot_request_for_send(&stored),
Err(Error::ModelNotFound(_)) => None,
Err(err) => {
warn!("Failed to load request to snapshot before send: {err}");
return None;
None
}
};
match self.snapshot_request(&stored, ModelVersionReason::Send) {
}
}
/// What a send calls with the stored request it loaded: capture it, and
/// don't make a fuss.
///
/// The caller must pass the request as stored, never a resolved or rendered
/// copy; with only an id, use [`Self::snapshot_stored_request_for_send`].
/// A send is not worth failing over history that couldn't be written, and
/// a request with no id is ephemeral and has nothing to version. Either way
/// the response just has no version to offer.
pub fn snapshot_request_for_send(&self, request: &AnyRequest) -> Option<String> {
if request.id().is_empty() {
return None;
}
match self.snapshot_request(request, ModelVersionReason::Send) {
Ok(version) => Some(version.id),
Err(err) => {
warn!("Failed to snapshot request before send: {err}");
+3 -1
View File
@@ -453,7 +453,9 @@ fn snapshot_request_for_send(query_manager: &QueryManager, request_id: &str) ->
return None;
}
query_manager
.with_tx(|tx| Ok::<_, yaak_models::error::Error>(tx.snapshot_request_for_send(request_id)))
.with_tx(|tx| {
Ok::<_, yaak_models::error::Error>(tx.snapshot_stored_request_for_send(request_id))
})
.unwrap_or_else(|err| {
warn!("Failed to snapshot request before send: {err}");
None