-
Notifications
You must be signed in to change notification settings - Fork 809
nits: warning retry #6760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
nits: warning retry #6760
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -85,6 +85,38 @@ pub fn global_service() -> Router { | |||||||||||||||||||||
.route("/hub/get/:id", get(get_hub_flow_by_id)) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
fn validate_flow_value(flow_value: &serde_json::Value) -> Result<()> { | ||||||||||||||||||||||
#[cfg(not(feature = "enterprise"))] | ||||||||||||||||||||||
if flow_value | ||||||||||||||||||||||
.get("ws_error_handler_muted") | ||||||||||||||||||||||
.map(|val| val.as_bool().unwrap_or(false)) | ||||||||||||||||||||||
.is_some_and(|val| val) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
return Err(Error::BadRequest( | ||||||||||||||||||||||
"Muting the error handler for certain flow is only available in enterprise version" | ||||||||||||||||||||||
.to_string(), | ||||||||||||||||||||||
)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if let Some(modules) = flow_value.get("modules").and_then(|m| m.as_array()) { | ||||||||||||||||||||||
for module in modules { | ||||||||||||||||||||||
if let Some(retry) = module.get("retry") { | ||||||||||||||||||||||
if let Some(exponential) = retry.get("exponential") { | ||||||||||||||||||||||
let seconds = exponential.get("seconds").and_then(|s| s.as_u64()).ok_or( | ||||||||||||||||||||||
Error::BadRequest("Exponential backoff base (seconds) must be a valid positive integer".to_string()), | ||||||||||||||||||||||
)?; | ||||||||||||||||||||||
if seconds == 0 { | ||||||||||||||||||||||
return Err(Error::BadRequest( | ||||||||||||||||||||||
"Exponential backoff base (seconds) must be greater than 0. A base of 0 would cause immediate retries.".to_string(), | ||||||||||||||||||||||
)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+108
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validation logic is inconsistent between the backend and frontend. The backend rejects only when
This would align with the frontend validation in
Suggested change
Spotted by Diamond |
||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Ok(()) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
#[derive(Serialize, FromRow)] | ||||||||||||||||||||||
pub struct SearchFlow { | ||||||||||||||||||||||
path: String, | ||||||||||||||||||||||
|
@@ -411,18 +443,8 @@ async fn create_flow( | |||||||||||||||||||||
)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
#[cfg(not(feature = "enterprise"))] | ||||||||||||||||||||||
if nf | ||||||||||||||||||||||
.value | ||||||||||||||||||||||
.get("ws_error_handler_muted") | ||||||||||||||||||||||
.map(|val| val.as_bool().unwrap_or(false)) | ||||||||||||||||||||||
.is_some_and(|val| val) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
return Err(Error::BadRequest( | ||||||||||||||||||||||
"Muting the error handler for certain flow is only available in enterprise version" | ||||||||||||||||||||||
.to_string(), | ||||||||||||||||||||||
)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
validate_flow_value(&nf.value)?; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// cron::Schedule::from_str(&ns.schedule).map_err(|e| error::Error::BadRequest(e.to_string()))?; | ||||||||||||||||||||||
let authed = maybe_refresh_folders(&nf.path, &w_id, authed, &db).await; | ||||||||||||||||||||||
|
@@ -744,18 +766,7 @@ async fn update_flow( | |||||||||||||||||||||
let flow_path = flow_path.to_path(); | ||||||||||||||||||||||
check_scopes(&authed, || format!("flows:write:{}", flow_path))?; | ||||||||||||||||||||||
|
||||||||||||||||||||||
#[cfg(not(feature = "enterprise"))] | ||||||||||||||||||||||
if nf | ||||||||||||||||||||||
.value | ||||||||||||||||||||||
.get("ws_error_handler_muted") | ||||||||||||||||||||||
.map(|val| val.as_bool().unwrap_or(false)) | ||||||||||||||||||||||
.is_some_and(|val| val) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
return Err(Error::BadRequest( | ||||||||||||||||||||||
"Muting the error handler for certain flow is only available in enterprise version" | ||||||||||||||||||||||
.to_string(), | ||||||||||||||||||||||
)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
validate_flow_value(&nf.value)?; | ||||||||||||||||||||||
|
||||||||||||||||||||||
let authed = maybe_refresh_folders(&flow_path, &w_id, authed, &db).await; | ||||||||||||||||||||||
let mut tx = user_db.clone().begin(&authed).await?; | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -80,6 +80,7 @@ | |||||
import { StepsInputArgs } from './flows/stepsInputArgs.svelte' | ||||||
import { aiChatManager } from './copilot/chat/AIChatManager.svelte' | ||||||
import type { GraphModuleState } from './graph' | ||||||
import { validateRetryConfig } from '$lib/utils' | ||||||
import { | ||||||
setStepHistoryLoaderContext, | ||||||
StepHistoryLoader, | ||||||
|
@@ -427,6 +428,15 @@ | |||||
loadingSave = true | ||||||
try { | ||||||
const flow = cleanInputs(flowStore.val) | ||||||
if (flow.value?.modules) { | ||||||
for (const module of flow.value.modules) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that only validate the first level, use dfs function to go through all the modules |
||||||
const error = validateRetryConfig(module.retry) | ||||||
if (error) { | ||||||
throw new Error(error) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider including module identification (e.g. module id) in the error message when throwing an error from validateRetryConfig. This will help trace which module's retry config is invalid.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
// console.log('flow', computeUnlockedSteps(flow)) // del | ||||||
// loadingSave = false // del | ||||||
// return | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import type { FlowEditorContext } from '../types' | ||
import { getStepPropPicker } from '../previousResults' | ||
import { NEVER_TESTED_THIS_FAR } from '../models' | ||
import { validateRetryConfig } from '$lib/utils' | ||
|
||
interface Props { | ||
flowModuleRetry: Retry | undefined | ||
|
@@ -59,6 +60,10 @@ | |
: NEVER_TESTED_THIS_FAR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of derived stores to show the validation error. Consider if similar validation is needed for the constant retry settings or adding comments to clarify why only the exponential section is validated. |
||
) | ||
|
||
let validationError = $derived.by(() => { | ||
return validateRetryConfig(flowModuleRetry) | ||
}) | ||
|
||
function setConstantRetries() { | ||
flowModuleRetry = { | ||
...flowModuleRetry, | ||
|
@@ -247,7 +252,20 @@ | |
<span class="text-xs text-tertiary">delay = multiplier * base ^ (number of attempt)</span> | ||
<input bind:value={flowModuleRetry.exponential.multiplier} type="number" /> | ||
<div class="text-xs font-bold !mt-2">Base (in seconds)</div> | ||
<input bind:value={flowModuleRetry.exponential.seconds} type="number" step="1" /> | ||
<input | ||
bind:value={flowModuleRetry.exponential.seconds} | ||
type="number" | ||
step="1" | ||
min="1" | ||
class={validationError ? 'border-red-500' : ''} | ||
/> | ||
{#if validationError} | ||
<span class="text-xs text-red-500">{validationError}</span> | ||
{:else} | ||
<span class="text-xs text-tertiary" | ||
>Must be ≥ 1. A base of 0 would cause immediate retries.</span | ||
> | ||
{/if} | ||
<div class="text-xs font-bold !mt-2">Randomization factor (percentage)</div> | ||
<div class="flex w-full gap-4"> | ||
{#if !$enterpriseLicense} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ components: | |
type: integer | ||
seconds: | ||
type: integer | ||
minimum: 1 | ||
random_factor: | ||
type: integer | ||
minimum: 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it only go through first level, there is likely a dfs function somewhere however I think it might be the wrong approach, you likely want to try to deserialize each module and fail at first module that can't be deserializing with giving the id + error from the deserializer. Much more generic. You can then just apply a validate function on a FlowModuleValue directly for anything post validation.