Skip to content

fix(runtime): isolate template context per render (#166)#627

Closed
KrisSimon wants to merge 1 commit intomainfrom
migrate-open-230
Closed

fix(runtime): isolate template context per render (#166)#627
KrisSimon wants to merge 1 commit intomainfrom
migrate-open-230

Conversation

@KrisSimon
Copy link
Copy Markdown
Member

Migrated from GitLab MR !230 (open)
feature/166-isolate-template-contextmain
Originally created: 2026-04-06
Author: Kris Simon
Labels: 0.9

Summary

Closes #166. TemplateExecutor.render() / renderAndTrack() each create a child RuntimeContext via createTemplateContext(), but that helper eagerly snapshotted every parent variable into the child. That defeated the point of a child context: the snapshot went stale the moment the parent bound anything new, and because bind() marks user variables immutable after the first write, the copied names could not be shadowed by template-local bindings. Concurrent renders off the same parent (two HTTP handlers rendering templates at once) could also observe each other's intermediate bindings through the snapshot surface.

What changed

  • Sources/ARORuntime/Core/RuntimeContext.swiftcreateTemplateContext() no longer copies variables or services into the child. The child starts with empty storage; reads walk up to the parent via the existing resolve / resolveAny / service fall-through; writes stay local and are discarded when the render completes.
  • Tests/AROuntimeTests/TemplateEngineTests.swift — new Template Context Isolation Tests suite with 4 regression tests:
    • child bindings do not leak back to the parent
    • child can shadow a parent binding without mutating the parent
    • sibling template contexts off the same parent are independent
    • 64-way concurrent render under Task.yield interleaving: no cross-child leakage, no leakage to parent

Test plan

  • swift build
  • swift test — 1580/1580 pass
  • swift run aro run Examples/TemplateEngine — output unchanged

@KrisSimon KrisSimon closed this Apr 12, 2026
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.

1 participant