Skip to content

Cookies are not propagated between parent and included runbooks (include scenario) - #1450

Merged
k2tzumi merged 11 commits into
mainfrom
fix/propagate-cookies-across-included-runbooks
Apr 12, 2026
Merged

k2tzumi merged 11 commits into
mainfrom
fix/propagate-cookies-across-included-runbooks

Conversation

@k2tzumi

@k2tzumi k2tzumi commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator

close #1449

@k2tzumi k2tzumi added enhancement New feature or request breaking-change labels Apr 11, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread include.go
@@ -211,6 +211,7 @@ func (rnr *includeRunner) run(ctx context.Context, oo *operator, s *step) error
}
rnr.runResults = append(rnr.runResults, ooo.runResult)
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread internal/store/store.go Outdated
s.parentVars = vars
if cookies, ok := vars[RootKeyCookie].(map[string]map[string]*http.Cookie); ok {
s.MergeCookies(cloneCookies(cookies))
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, thanks. The redundant copy was removed as part of moving propagation out of SetParentVars. Also, the now-unused clone helper was deleted.

Comment thread internal/store/store.go Outdated
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))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@k1LoW

k1LoW commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Pre-existing issue (not introduced by this PR): setCookieHeader is not called in the rnr.handler (httptest) path at http.go:533, so cookies are not sent when using http.Handler-based runners. This may affect test scenarios that rely on cookie propagation with httptest.

@k1LoW

k1LoW commented Apr 12, 2026

Copy link
Copy Markdown
Owner

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.

k2tzumi added 4 commits April 12, 2026 12:10
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
@github-actions

This comment has been minimized.

@k2tzumi

k2tzumi commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator Author

#1450 (comment)

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.

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.RecordCookie to accumulate/merge cookies instead of replacing the entire cookie map.
  • Add Store.MergeCookies and 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.

Comment thread include.go
Comment on lines 207 to 213
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)

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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())

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

k2tzumi added 2 commits April 12, 2026 21:48
address discussion_r3069398824 by propagating cookies between include chain iterations

add needs-based cookie include integration fixtures
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

BenchmarkManyRunbooks-4

main (-) #1450 (913b131) +/-
Number of iterations 1 1 0
Nanoseconds per iteration 3,835,901,796 ns/op 3,720,520,046 ns/op -115,381,750 ns/op
Bytes allocated per iteration 1,391,108,544 B/op 1,391,305,480 B/op 196,936 B/op
Allocs per iteration 19,360,456 allocs/op 19,360,771 allocs/op 315 allocs/op
Metadata
main (-) #1450 (913b131)
goos linux linux
goarch amd64 amd64
pkg github.com/k1LoW/runn github.com/k1LoW/runn
cpu AMD EPYC 7763 64-Core Processor AMD EPYC 7763 64-Core Processor

BenchmarkOpenAPI3-4

main (-) #1450 (913b131) +/-
Number of iterations 1 1 0
Nanoseconds per iteration 1,479,580,987 ns/op 1,447,132,728 ns/op -32,448,259 ns/op
Bytes allocated per iteration 818,223,960 B/op 818,223,168 B/op -792 B/op
Allocs per iteration 11,350,381 allocs/op 11,350,471 allocs/op 90 allocs/op
Metadata
main (-) #1450 (913b131)
goos linux linux
goarch amd64 amd64
pkg github.com/k1LoW/runn github.com/k1LoW/runn
cpu AMD EPYC 7763 64-Core Processor AMD EPYC 7763 64-Core Processor

BenchmarkSingleRunbook-4

main (-) #1450 (913b131) +/-
Number of iterations 22 22 0
Nanoseconds per iteration 48,223,481 ns/op 48,022,453 ns/op -201,028 ns/op
Bytes allocated per iteration 23,067,398 B/op 23,056,017 B/op -11,381 B/op
Allocs per iteration 186,957 allocs/op 186,952 allocs/op -5 allocs/op
Metadata
main (-) #1450 (913b131)
goos linux linux
goarch amd64 amd64
pkg github.com/k1LoW/runn github.com/k1LoW/runn
cpu AMD EPYC 7763 64-Core Processor AMD EPYC 7763 64-Core Processor

Reported by octocov

@github-actions

Copy link
Copy Markdown
Contributor

Code Metrics Report

main (de36e73) #1450 (913b131) +/-
Coverage 59.7% 59.8% +0.0%
Code to Test Ratio 1:0.8 1:0.8 +0.0
Test Execution Time 7m38s 7m30s -8s
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%)

Files Coverage +/- Status
include.go 90.2% +0.2% modified
internal/expr/expr.go 65.9% +0.7% affected
internal/store/store.go 54.3% +2.5% modified
internal/store/store_test.go 93.1% 0.0% modified

Reported by octocov

@k1LoW k1LoW left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM!

@k2tzumi
k2tzumi merged commit d1c8dea into main Apr 12, 2026
9 checks passed
@k2tzumi
k2tzumi deleted the fix/propagate-cookies-across-included-runbooks branch April 12, 2026 14:35
@github-actions github-actions Bot mentioned this pull request Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cookies are not propagated between parent and included runbooks (include scenario)

4 participants

⌂ 换网址