Repository navigation
Cookies are not propagated between parent and included runbooks (include scenario) - #1450
Conversation
…tion and register the scenario in HTTPBin integration tests.
…ntext, merge child cookies back to parent after include, and update store tests.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -211,6 +211,7 @@ func (rnr *includeRunner) run(ctx context.Context, oo *operator, s *step) error | |||
| } | |||
| rnr.runResults = append(rnr.runResults, ooo.runResult) | |||
| } | |||
There was a problem hiding this comment.
When the child runbook fails, this line is not reached because of the early return at L210. If the parent uses force: true, it will continue execution but without the cookies that the child had already set. Should MergeCookies be called before the early return as well, or use defer?
There was a problem hiding this comment.
Thanks for the great catch. I updated the include error path so cookies are merged before returning on child failure. This preserves child-set cookies even when the parent continues with force: true.
| s.parentVars = vars | ||
| if cookies, ok := vars[RootKeyCookie].(map[string]map[string]*http.Cookie); ok { | ||
| s.MergeCookies(cloneCookies(cookies)) | ||
| } |
There was a problem hiding this comment.
Cookie propagation as a side effect of SetParentVars is not obvious from the method name. Consider moving this logic to newNestedOperator in include.go as an explicit call:
oo.store.MergeCookies(o.store.Cookies())This makes the cookie propagation visible at the orchestration layer rather than hidden inside a setter.
There was a problem hiding this comment.
Good point, thanks. The redundant copy was removed as part of moving propagation out of SetParentVars. Also, the now-unused clone helper was deleted.
| func (s *Store) SetParentVars(vars map[string]any) { | ||
| s.parentVars = vars | ||
| if cookies, ok := vars[RootKeyCookie].(map[string]map[string]*http.Cookie); ok { | ||
| s.MergeCookies(cloneCookies(cookies)) |
There was a problem hiding this comment.
MergeCookies already calls cloneCookie for each cookie internally. Wrapping the argument with cloneCookies here results in a double deep copy. You can simplify this to:
s.MergeCookies(cookies)There was a problem hiding this comment.
Agreed. I removed cookie propagation from SetParentVars and made it explicit in newNestedOperator. This makes the flow visible at the orchestration layer and avoids hidden setter side effects.
|
Pre-existing issue (not introduced by this PR): |
|
The overall direction of this PR looks good to me! I've added (and am still working on) AI-assisted reviews, but I'm fine with making final adjustments after merging. |
align MergeCookies behavior with RecordCookie add TestMergeCookies cases for expiration and merge behavior
remove implicit cookie merge side effect from SetParentVars merge parent cookies explicitly in newNestedOperator
merge child cookies before returning includedRunErr
This comment has been minimized.
This comment has been minimized.
|
Thanks for highlighting this. I confirmed it is pre-existing and out of scope for this PR. I will handle it separately in a follow-up issue/PR so this change stays focused. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR fixes cookie handling across include: runbook execution by making cookie storage accumulative (browser-like) and explicitly propagating cookies between parent and included operators, addressing issue #1449.
Changes:
- Update
Store.RecordCookieto accumulate/merge cookies instead of replacing the entire cookie map. - Add
Store.MergeCookiesand wire cookie propagation parent→child (on nested operator creation) and child→parent (after include execution). - Add integration runbooks to validate cookie propagation/accumulation across
include:and run them in integration tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
internal/store/store.go |
Adds cookie cloning/merging support and changes cookie recording to accumulate rather than overwrite. |
internal/store/store_test.go |
Expands unit coverage for accumulated cookie recording and new cookie merge behavior. |
include.go |
Propagates cookies into nested operators and merges cookies back into the parent after includes. |
testdata/book/cookie_include_main.yml |
New integration runbook validating parent-side visibility of cookies set in included runbook. |
testdata/book/cookie_include_child.yml |
New integration runbook validating child-side visibility of parent cookies and accumulation. |
integration_test.go |
Adds the new include cookie runbook to the HTTPBin integration test suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ooo.parent = oo.parent | ||
| if err := ooo.run(ctx); err != nil { | ||
| rnr.runResults = append(rnr.runResults, ooo.runResult) | ||
| oo.store.MergeCookies(ooo.store.Cookies()) | ||
| return newIncludedRunErr(err) | ||
| } | ||
| rnr.runResults = append(rnr.runResults, ooo.runResult) |
There was a problem hiding this comment.
In includeRunner.run, cookies are only merged back to the parent from oo at the end, and (only on error) from a failing ooo into oo. When the include has needs: runbooks (or the sorted list contains multiple operators), cookies set by earlier successfully-run ooo operators won’t be available to later operators (including oo), and won’t be propagated back to the parent. Consider merging cookies after each successful ooo.run(ctx) into a shared jar (e.g., oo.store.MergeCookies(ooo.store.Cookies())), and also seeding each ooo with the current jar before running so cookies propagate through the whole include execution chain.
| ooo.parent = oo.parent | |
| if err := ooo.run(ctx); err != nil { | |
| rnr.runResults = append(rnr.runResults, ooo.runResult) | |
| oo.store.MergeCookies(ooo.store.Cookies()) | |
| return newIncludedRunErr(err) | |
| } | |
| rnr.runResults = append(rnr.runResults, ooo.runResult) | |
| ooo.parent = oo.parent | |
| ooo.store.MergeCookies(oo.store.Cookies()) | |
| if err := ooo.run(ctx); err != nil { | |
| rnr.runResults = append(rnr.runResults, ooo.runResult) | |
| oo.store.MergeCookies(ooo.store.Cookies()) | |
| return newIncludedRunErr(err) | |
| } | |
| rnr.runResults = append(rnr.runResults, ooo.runResult) | |
| oo.store.MergeCookies(ooo.store.Cookies()) |
There was a problem hiding this comment.
I intentionally kept this as a one-line change in includeRunner.run to minimize behavioral impact while fixing the reported propagation gap.
Reasoning:
- The issue in this thread is that cookies from a successfully executed child operator were not merged into the include-level store before the next operator context.
- Adding a merge right after successful execution addresses that gap directly with the smallest possible change.
- The existing error-path merge and final parent merge already cover failure and end-of-include propagation, so this addition makes success-path behavior symmetric without restructuring the flow.
- This keeps the fix easy to review, low risk for regressions, and scoped to the specific concern raised in this discussion.
If we want stronger chain-wide guarantees across more complex include and needs topologies, we can discuss an additional follow-up refactor separately.
address discussion_r3069398824 by propagating cookies between include chain iterations add needs-based cookie include integration fixtures
This comment has been minimized.
This comment has been minimized.
BenchmarkManyRunbooks-4
Metadata
BenchmarkOpenAPI3-4
Metadata
BenchmarkSingleRunbook-4
Metadata
Reported by octocov |
Code Metrics Report
Details | | main (de36e73) | #1450 (913b131) | +/- |
|---------------------|----------------|-----------------|-------|
+ | Coverage | 59.7% | 59.8% | +0.0% |
| Files | 85 | 85 | 0 |
| Lines | 9812 | 9831 | +19 |
+ | Covered | 5865 | 5886 | +21 |
+ | Code to Test Ratio | 1:0.8 | 1:0.8 | +0.0 |
| Code | 18419 | 18451 | +32 |
+ | Test | 15182 | 15351 | +169 |
+ | Test Execution Time | 7m38s | 7m30s | -8s |Code coverage of files in pull request scope (65.3% → 66.7%)
Reported by octocov |
close #1449