fix: new script versions not picked up by other workers (#5069)

This commit is contained in:
pedrohsdb 2026-03-12 11:15:40 -07:00 committed by GitHub
parent 913b15d618
commit 3b4f72e513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 6 deletions

View file

@ -6393,7 +6393,7 @@ class AgentDB(BaseAlchemyDB):
if statuses is not None and len(statuses) > 0:
query = query.where(WorkflowScriptModel.status.in_(statuses))
query = query.order_by(ScriptModel.created_at.desc(), ScriptModel.version.desc()).limit(1)
query = query.order_by(ScriptModel.version.desc()).limit(1)
script = (await session.scalars(query)).first()
return convert_to_script(script) if script else None

View file

@ -1019,14 +1019,34 @@ class WorkflowService:
# Trigger AI Script Reviewer for adaptive caching workflows
# Include terminated and failed runs (triage will filter non-code-fixable failures)
# Skip canceled (user stopped) and timed_out (infrastructure issue)
# Only trigger if this run used the latest script version — stale runs produce
# episodes that may already be fixed in newer versions, and reviewing them creates
# redundant/regressive versions.
if is_adaptive_caching(workflow, workflow_run) and pre_finally_status not in (
WorkflowRunStatus.canceled,
WorkflowRunStatus.timed_out,
):
asyncio.create_task(
self._trigger_script_reviewer(workflow, workflow_run),
name=f"script_reviewer_{workflow_run.workflow_run_id}",
)
should_trigger_reviewer = True
current_ctx = skyvern_context.current()
if current_ctx and current_ctx.script_id:
latest_script = await app.DATABASE.get_latest_script_version(
script_id=current_ctx.script_id,
organization_id=workflow.organization_id,
)
if latest_script and latest_script.script_revision_id != current_ctx.script_revision_id:
should_trigger_reviewer = False
LOG.info(
"Skipping script reviewer - run used stale script version",
workflow_run_id=workflow_run.workflow_run_id,
used_revision=current_ctx.script_revision_id,
latest_revision=latest_script.script_revision_id,
latest_version=latest_script.version,
)
if should_trigger_reviewer:
asyncio.create_task(
self._trigger_script_reviewer(workflow, workflow_run),
name=f"script_reviewer_{workflow_run.workflow_run_id}",
)
# Execute finally block if configured. Skip for: canceled (user explicitly stopped)
should_run_finally = finally_block_label and pre_finally_status != WorkflowRunStatus.canceled

View file

@ -215,7 +215,6 @@ async def get_workflow_script(
workflow_permanent_id=workflow.workflow_permanent_id,
cache_key_value=rendered_cache_key_value,
statuses=[status],
use_cache=True,
)
if existing_script: