Skip to content

fix: register a persistent context after its url opened, and trace outside a keyword - #5356

Merged
aaltat merged 3 commits into
MarketSquare:mainfrom
aaltat:persistent-context-register-order
Oct 17, 2026
Merged

aaltat merged 3 commits into
MarketSquare:mainfrom
aaltat:persistent-context-register-order

Conversation

@aaltat

@aaltat aaltat commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Two follow-ups to #5326. Closes #5357.

New Persistent Context registered before its url opened. #5326 moved the cache entry and the video embed before GoTo together with the trace groups; only the trace groups had to move. 20.6.0 had the right order.

 new_persistent_context
   NewPersistentContext
-  _register_context: trace groups, context cache, embed video
+  add trace groups
   if url: GoTo (on failure: close and raise)
+  _cache_context: context cache, embed video

A traced context registered outside a keyword raised IndexError. With tracing_group_mode=Browser, add_context_and_keyword_call_stack_to_trace read keyword_call_stack[-1]. On the Python path the stack is empty, so New Context, New Persistent Context (both since before 20.6.0) and the new register_adopted_context failed with tracing on.

 if mode == Browser:
+    if not keyword_call_stack:
+        return None          # traced, no trace groups, as in Full mode
     open_trace_group(keyword_call_stack[-1])

Trace groups exist only on the Robot Framework path (Browser/CONTEXT.md); now Browser mode agrees with Full mode.

Evidence

  • Before: new_persistent_context(url=..., recordVideo={}) with GoTo failing leaves context_cache["context=1"] and logs <video ...>; register_adopted_context(...) with tracing=True, Browser mode and no keyword raises IndexError: list index out of range.
    After: no cache entry, no <video>; the context is in tracing_contexts and no trace group is opened.
  • utest/test_adopted_context.py: 28 passed. Against main, ..._is_not_cached_when_its_url_fails_to_open and ..._outside_a_keyword_is_traced_without_trace_groups fail; the success path (cached, video embedded) and "traced before its url opens" pass on both.
  • inv utest: 845 passed. inv atest suites Video, Tracing Groups, Persistent State, Geolocation, 05 JS Tests: all passed.

Merge Danger

Door: two-way

Blast Radius: small

New Persistent Context with url and a video: the video is now embedded after the navigation instead of before. Plain-Python users of tracing with tracing_group_mode=Browser stop getting IndexError.

🤖 Generated with Claude Code

aaltat and others added 3 commits October 17, 2026 19:37
New Persistent Context added the context to the context cache and
embedded its video before navigating to url. When the navigation
failed, the log showed a video of a context that was closed again, and
the cache entry stayed. The trace groups are still added before the
navigation, so it is traced; the cache entry and the video follow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With tracing_group_mode Browser, registering a traced context read the
last entry of the keyword call stack, so New Context, New Persistent
Context or register_adopted_context called from plain Python, where the
stack is empty, raised IndexError. The context is now traced without
trace groups, as in Full mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One test per behaviour: the size is cached and the video embedded once
the url opened, the context is traced before the url opens, and nothing
is cached when it fails to open. _remember_context is renamed
_cache_context, and an empty keyword call stack returns explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aaltat
aaltat merged commit 5c1e521 into MarketSquare:main Oct 17, 2026
88 of 90 checks passed
@aaltat
aaltat deleted the persistent-context-register-order branch October 17, 2026 17:34
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.

Tracing with tracing_group_mode=Browser fails with IndexError when a context is created from plain Python

1 participant