Skip to content

Automate browser based workflows with AI

SKY-13979: derive the extraction schema instead of asking to confirm it (#8199)

Andrew Neilson7138ce8786b7
diff --git a/alembic/versions/2026_08_14_0137-ceb0b2b5836b_add_secure_runner_pinned_to_workflow_runs.py b/alembic/versions/2026_08_14_0137-ceb0b2b5836b_add_secure_runner_pinned_to_workflow_runs.py
new file mode 100644
index 000000000..536ee0865
--- /dev/null
+++ b/alembic/versions/2026_08_14_0137-ceb0b2b5836b_add_secure_runner_pinned_to_workflow_runs.py
@@ -0,0 +1,29 @@
+"""add secure_runner_pinned to workflow_runs
+
+Revision ID: ceb0b2b5836b
+Revises: a3b94b945dac
+Create Date: 2026-08-14T01:37:28.825016+00:00
+
+"""
+
+from typing import Sequence, Union
+
+import sqlalchemy as sa
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision: str = "ceb0b2b5836b"
+down_revision: Union[str, None] = "a3b94b945dac"
+branch_labels: Union[str, Sequence[str], None] = None
+depends_on: Union[str, Sequence[str], None] = None
+
+
+def upgrade() -> None:
+ op.execute("SET LOCAL lock_timeout = '5s'")
+ op.add_column("workflow_runs", sa.Column("secure_runner_pinned", sa.Boolean(), nullable=True))
+
+
+def downgrade() -> None:
+ op.execute("SET LOCAL lock_timeout = '5s'")
+ op.drop_column("workflow_runs", "secure_runner_pinned")
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index aad84097b..52ebab0ca 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -1114,9 +1114,13 @@ class AgentFunction:
organization_id: str | None,
workflow_permanent_id: str | None = None,
workflow_id: str | None = None,
+ pin_verdict: bool = False,
) -> bool:
"""Whether a run containing a CodeBlock should get an auto-provisioned browser session.
+ ``pin_verdict`` asks the resolver to freeze an authoritative verdict onto the run, and is
+ for the caller whose routing decision depends on it. OSS has nothing to pin.
+
The secure CodeBlock runner brokers page operations against a live persistent browser
session, so a run that has a CodeBlock but no caller-supplied session needs one created
for it before block execution. OSS has no runner and returns False; cloud overrides to
@@ -1124,6 +1128,15 @@ class AgentFunction:
"""
return False
+ async def pin_secure_runner_verdict(self, *, workflow_run_id: str, enabled: bool) -> None:
+ """Record the secure-runner verdict a run was routed on, so later gates honor it.
+
+ OSS no-op: with no runner there is no routing decision to keep consistent. Cloud overrides
+ to store it on the run, because the publisher and the gates that consume the verdict run in
+ different processes and would otherwise re-resolve a rollout flag that moved in between.
+ """
+ return None
+
async def execute_code_block_override(
self,
*,
diff --git a/skyvern/forge/sdk/db/models.py b/skyvern/forge/sdk/db/models.py
index eb200a024..4999ef506 100644
--- a/skyvern/forge/sdk/db/models.py
+++ b/skyvern/forge/sdk/db/models.py
@@ -775,6 +775,12 @@ class WorkflowRunModel(Base):
ignore_inherited_workflow_system_prompt = Column(
Boolean, nullable=False, default=False, server_default=sqlalchemy.false()
)
+ # The secure-CodeBlock verdict resolved when this run was routed. The routing decision it
+ # feeds (which cluster the run lands on) is made once, at publication, but the gates that
+ # consume it run later in a different process; re-resolving the rollout flag there lets a
+ # mid-run flag edit strand the run on a cluster with no runner. NULL means the run predates
+ # the pin, and the gates resolve the flag as before.
+ secure_runner_pinned = Column(Boolean, nullable=True)
copilot_session_id = Column(String, nullable=True)
credits_used = Column(Integer, nullable=True, default=0, server_default="0")
diff --git a/skyvern/forge/sdk/db/repositories/workflow_runs.py b/skyvern/forge/sdk/db/repositories/workflow_runs.py
index 2e6e55c48..c10dec739 100644
--- a/skyvern/forge/sdk/db/repositories/workflow_runs.py
+++ b/skyvern/forge/sdk/db/repositories/workflow_runs.py
@@ -306,6 +306,8 @@ class WorkflowRunsRepository(BaseRepository):
waiting_for_verification_code: bool | None = None,
verification_code_identifier: str | None = None,
verification_code_polling_started_at: datetime | None = None,
+ # Sentinel-guarded because False is a meaningful pin, not "leave unchanged".
+ secure_runner_pinned: bool | None | object = _UNSET,
browser_profile_id: str | None | object = _UNSET,
browser_seed_source: str | None | object = _UNSET,
browser_sink_profile_id: str | None | object = _UNSET,
@@ -396,6 +398,8 @@ class WorkflowRunsRepository(BaseRepository):
workflow_run.sequential_credential_id = sequential_credential_id
if ai_fallback is not None:
workflow_run.ai_fallback = ai_fallback
+ if secure_runner_pinned is not _UNSET:
+ workflow_run.secure_runner_pinned = secure_runner_pinned
if depends_on_workflow_run_id:
workflow_run.depends_on_workflow_run_id = depends_on_workflow_run_id
if browser_session_id:
@@ -920,6 +924,19 @@ class WorkflowRunsRepository(BaseRepository):
return convert_to_workflow_run(workflow_run)
return None
+ async def get_secure_runner_pin(self, workflow_run_id: str, organization_id: str | None = None) -> bool | None:
+ """The secure-runner verdict frozen onto this run, or None when it carries no pin.
+
+ Selects the column rather than the run because ``WorkflowRun`` is a published API schema:
+ carrying an internal rollout verdict on it would document the field as part of the public
+ contract. None covers both "no such run" and "no pin", which the caller treats alike.
+ """
+ async with self.Session() as session:
+ query = select(WorkflowRunModel.secure_runner_pinned).filter_by(workflow_run_id=workflow_run_id)
+ if organization_id:
+ query = query.filter_by(organization_id=organization_id)
+ return await session.scalar(query)
+
async def get_run(self, run_id: str, organization_id: str | None = None) -> WorkflowRun | None:
"""Alias satisfying the RunReader protocol."""
return await self.get_workflow_run(run_id, organization_id=organization_id)
diff --git a/tests/unit/force_stub_app.py b/tests/unit/force_stub_app.py
index 5fdae1ead..edfae3837 100644
--- a/tests/unit/force_stub_app.py
+++ b/tests/unit/force_stub_app.py
@@ -66,6 +66,7 @@ def create_forge_stub_app() -> ForgeApp:
fake_app_module.DATABASE.workflow_runs.create_or_update_workflow_run_output_parameter = AsyncMock()
fake_app_module.DATABASE.tasks.get_last_task_for_workflow_run = AsyncMock()
fake_app_module.DATABASE.workflow_runs.get_workflow_run = AsyncMock()
+ fake_app_module.DATABASE.workflow_runs.get_secure_runner_pin = AsyncMock(return_value=None)
fake_app_module.DATABASE.observer.get_workflow_run_block = AsyncMock()
fake_app_module.DATABASE.tasks.get_task = AsyncMock()
fake_app_module.DATABASE.tasks.update_task = AsyncMock()