docs: fix determinism return-value-passing example (closes #217)#218
Merged
Conversation
The wrong version of the Pass data through return values example did not demonstrate a replay divergence. The mutation accumulated total from event data, which is a pure function of handler input, so replay reconstructed the same total. The example matched the page's own rule for allowed outside-step code rather than the anti-pattern the prose was teaching. Rewrite the section around the real failure mode. A step body that writes to outer state through a closure loses the write on replay, because replay returns the cached value and skips the body. The new wrong version writes to an outer list from inside the step body and returns void, so replay leaves the list empty. The new right version returns the value from the step and the handler appends to the list outside. - Rewrite the prose and danger admonition to match the concept - Replace TypeScript and Python wrong/right pairs - Add a wrong companion to the Java example, which previously showed only the right implementation Closes #217
ParidelPooya
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the "Pass data through return values, not closures" example so it demonstrates the failure mode the surrounding prose describes.
The current wrong example accumulates
totalfromitem["price"]inevent["items"]. Both values are pure functions of the handler input, which is stable across replays. Replay reconstructs the same total. The example matches the page's own rule for allowed outside-step code rather than the anti-pattern the prose is teaching.The new wrong example writes to an outer list from inside the step body via a closure. Replay returns the cached value without running the body, so the write does not land and the list stays empty. The handler's return value differs between the first invocation and replay. The new right example returns the receipt id from the step and appends it to the list in the handler.
Changes
return-value-passingwrong and right examples.return-value-passingexample, which previously showed only the right implementation.Trace on replay (Python wrong version)
First invocation returns
{"receipts": [id1, id2, ...]}. Replay returns{"receipts": []}. Same shape for TypeScript and Java.Verification
mdformaton the edited page.zensical build --clean. Build finished cleanly, no issues.context.stepsignatures against SDK source for all three languages before writing examples.Closes