Non-deterministic input/output mapping: overlapping destination paths silently drop data
Maintainer thường phản hồi trong vòng 1 ngày
@lokewate đang làm issue này rồi.
Từ ngày 14/6/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the Bug
mapTaskInputs (and mapTaskOutputs) apply a node's input_mapping / output_mapping by ranging over a Go map and calling setNestedKey for each entry. When two mapping entries write to overlapping destination paths — one a leaf (submission) and one a nested child of it (submission.reference_number) — the final result depends on the iteration order of a Go map, which is randomized. Because setNestedKey overwrites on a leaf assignment but merges on a nested assignment, the two possible orders produce different results, and one of them silently drops data.
This is a latent, ~50/50 flaky data-loss bug for any workflow whose mapping has a destination path that is a prefix of another destination path.
Where (code references)
workflow/dsl.go—InputMapping map[string]stringis documented asWorkflowVariables Key -> Task Input Key, i.e. the map value is the destination path.workflow/workflow.go—mapTaskInputsiterates the mapping nondeterministically and applies each entry:for rawGlobalKey, localKey := range inputMapping { // <-- Go map range: randomized order globalKey, optional := parseMappingKey(rawGlobalKey) val, exists := getNestedKey(g.instance.WorkflowVariables, globalKey) // ... setNestedKey(inputs, localKey, val) // <-- destination path }workflow/utils.go—setNestedKeyoverwrites a leaf but merges a nested path:func setNestedKey(m map[string]any, dotPath string, value any) { // ... for a path WITH a dot: descends, REUSES/creates the intermediate map (merge) // setNestedKey(subMap, rest, value); m[key] = subMap; return // ... for a leaf path (no dot): m[dotPath] = value // <-- WHOLESALE OVERWRITE }workflow/mapTaskOutputshas the identical pattern overoutput_mapping, so it is affected too.
Mechanism
Given this (real) mapping, where both entries resolve to destination key submission:
"input_mapping": {
"reference_number": "submission.reference_number",
"userform": "submission"
}
| Iteration order | setNestedKey effect |
Result |
|---|---|---|
submission.reference_number then submission |
nested write creates {submission:{reference_number}}, then leaf write overwrites the whole submission |
{submission: <userform>} — reference_number lost |
submission then submission.reference_number |
leaf write sets {submission:<userform>}, then nested write merges into it |
{submission: {<userform fields>, reference_number}} — correct |
Because range over a map randomizes order, which result you get varies per process/run.
To Reproduce
A minimal unit test in workflow/utils_test.go demonstrates the order-dependence directly (this is exactly what mapTaskInputs does, with the two possible orderings):
func TestSetNestedKey_OverlappingDestinationsAreOrderDependent(t *testing.T) {
userform := map[string]any{"exporter_name": "Acme"}
// Order A: nested first, leaf second -> reference_number is DROPPED
a := map[string]any{}
setNestedKey(a, "submission.reference_number", "REF-123")
setNestedKey(a, "submission", userform)
// a == {"submission": {"exporter_name": "Acme"}} (reference_number gone)
// Order B: leaf first, nested second -> both present
b := map[string]any{}
setNestedKey(b, "submission", userform)
setNestedKey(b, "submission.reference_number", "REF-123")
// b == {"submission": {"exporter_name": "Acme", "reference_number": "REF-123"}}
// a and b differ -> result depends on iteration order, which range() randomizes.
}
To see the flakiness end-to-end:
- Define a TASK node with the
input_mappingabove (a leaf destinationsubmissionand a nested destinationsubmission.reference_number). - Activate the node repeatedly across multiple process runs.
- Observe that
inputs["submission"]intermittently is missingreference_number, with no error.
Expected Behavior
- Expected: applying a node's mapping is deterministic; overlapping/parent-child destination paths either merge predictably or are rejected as a misconfiguration.
- Actual: the outcome depends on Go's randomized map iteration order; a parent-leaf assignment can silently clobber a sibling nested assignment (or vice-versa).
Version
github.com/OpenNSW/core at commit 66c100d4aa8a (line numbers in the references above are from this commit). Consuming project currently pins v0.0.0-20260612190859-9c090fdca33c; the logic is unchanged there.
Environment Details (with versions)
Go (workflow engine github.com/OpenNSW/core). Language-level behavior (randomized map iteration order) means this reproduces on any Go version / OS.
Additional Context
Impact / severity
- Silent data loss in task inputs (and outputs) — e.g. a payload dispatched to an external government agency intermittently omits a field.
- Flaky / hard to diagnose: passes in most runs, fails in others, with no error.
- Triggered by an ordinary, reasonable-looking config; nothing warns the author.
Secondary observation
In the "good" ordering, getNestedKey returns the live source value (not a copy), so the subsequent nested setNestedKey mutates the original WorkflowVariables entry as a side effect (aliasing). This is independently undesirable under deterministic replay and worth addressing alongside the ordering fix.
Suggested fixes
- Deterministic application order (primary). Before applying, sort mapping entries by destination-path depth ascending (fewer dots first) so a parent/leaf assignment is always applied before its nested children. This makes the parent-then-child merge the defined behavior and removes the randomness.
- Validate overlapping destinations (guard). At definition load/validation time, detect when one destination path is a prefix of another (or two entries share a leaf destination) and reject/warn, so misconfigurations fail loudly instead of silently.
- Copy-on-read for mapped values. Deep-copy the value returned by
getNestedKeybefore inserting it into the target bag, to remove the aliasing side effect noted above.
Recommend (1) + (2) together; (3) closes the related mutation hazard. The same fix should be applied to both mapTaskInputs and mapTaskOutputs.
Notes
Surfaced while authoring FCAU sub-workflow configs in OpenNSW/nsw-srilanka (six configs/fcau/**/workflow.json nodes use the overlapping submission / submission.reference_number mapping to flatten the OGA payload envelope). The configs are a legitimate use of nested destination paths; the defect is the engine's nondeterministic, overwrite-vs-merge handling.
- Ngôn ngữ chính
- Go
- Star
- 6
- Fork
- 8
- Merge trung bình
- 21 giờ 36 phút
- Pull request đã merge (30 ngày)
- 42
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenNSW/core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
payment: test fixtures hardcode real gateway names (govpay/lankapay) instead of generic placeholdersĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
nsw-sl cleanup Type/Improvement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
remote: let the host inject a logger, and log with one consistent policyCó thể đã có người làm @mushrafmim đã nhận 5 ngày trước. Đang mởType/Improvement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
agent-research-finding chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jordansmall/spindrift#7370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
☢️ Bug v3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The repo's gates check is clean and runs need no swapsCó thể đã có người làm @turbot-agent-fleet đã nhận hôm nay. Đang mởagent:ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
turbot/tailpipe#677 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-kind needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
crossplane-contrib/provider-keycloak#806 ·
Maintainer thường phản hồi trong vòng 1 ngày