Skip to content

fix(workflow): catch IndexError in _resolve_placeholders for positional format specifiers#155

Open
devteamaegis wants to merge 1 commit into
browser-use:mainfrom
devteamaegis:fix/unhandledexception
Open

fix(workflow): catch IndexError in _resolve_placeholders for positional format specifiers#155
devteamaegis wants to merge 1 commit into
browser-use:mainfrom
devteamaegis:fix/unhandledexception

Conversation

@devteamaegis
Copy link
Copy Markdown

@devteamaegis devteamaegis commented May 31, 2026

What's broken

_resolve_placeholders in service.py calls str.format(**context) on workflow field values to substitute named placeholders. When a field value contains a positional format specifier such as {0} — which appears in copy-pasted JSON, URL templates, and CSS strings — Python raises IndexError: Replacement index 0 out of range for positional args tuple. Because the except clause only caught KeyError, this IndexError was unhandled and crashed the entire workflow run.

Why it happens

str.format(**kwargs) raises KeyError for unknown named placeholders and IndexError for positional placeholders ({0}, {1}, …) when no positional args are supplied. The original code only guarded against KeyError.

Fix

Changed except KeyError: to except (KeyError, IndexError): in _resolve_placeholders. Both exceptions now result in the original string being returned unchanged, which is the existing intended behavior for unresolvable placeholders.

Test

Added test_resolve_placeholders_ignores_positional_format_specifiers to workflows/tests/test_workflow_execution.py. It passes a string containing {0} with a keyword-only context and asserts the string is returned unchanged rather than raising.

Fixes #154


Summary by cubic

Fixes workflow crashes when field values contain positional placeholders like {0}. _resolve_placeholders now also catches IndexError (along with KeyError) and returns the original string; adds a unit test to cover this behavior. Fixes #154.

Written for commit ce37d80. Summary will update on new commits.

Review in cubic

…al format specifiers

Strings containing positional format placeholders like {0} (e.g. from
copy-pasted JSON values, URL templates, or CSS) caused an uncaught
IndexError when str.format(**context) was called in _resolve_placeholders.
Only KeyError was caught before; now both KeyError and IndexError are
caught so the original string is returned unchanged instead of crashing
the workflow.

Fixes browser-use#154
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="workflows/tests/test_workflow_execution.py">

<violation number="1" location="workflows/tests/test_workflow_execution.py:174">
P2: The new placeholder test is tautological and never exercises `_resolve_placeholders`, so it cannot fail if the production regression persists.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

data = 'Input field value: {0}'
try:
if '{' in data and '}' in data:
result = data.format(**context)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot May 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new placeholder test is tautological and never exercises _resolve_placeholders, so it cannot fail if the production regression persists.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At workflows/tests/test_workflow_execution.py, line 174:

<comment>The new placeholder test is tautological and never exercises `_resolve_placeholders`, so it cannot fail if the production regression persists.</comment>

<file context>
@@ -164,7 +164,19 @@ def test_semantic_strategies_format(self):
+		data = 'Input field value: {0}'
+		try:
+			if '{' in data and '}' in data:
+				result = data.format(**context)
+		except (KeyError, IndexError):
+			result = data
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: _resolve_placeholders crashes with IndexError on positional format placeholders like {0}

1 participant