Skip to content

Commit 8765783

Browse files
committed
Reject missing and null root task codecs before Python worker decoding
1 parent 038ca7f commit 8765783

10 files changed

Lines changed: 382 additions & 28 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
The Python SDK advances to prerelease `2.0.0-rc.31`. PyPI displays the normalized
10-
PEP 440 identity `2.0.0rc31`. This Avro-only SDK release is qualified with Server
9+
The Python SDK advances to prerelease `2.0.0-rc.32`. PyPI displays the normalized
10+
PEP 440 identity `2.0.0rc32`. This Avro-only SDK release is qualified with Server
1111
`2.0.0-rc.32`; JSON remains HTTP transport and is no longer a workflow payload
1212
codec.
1313
Earlier SDK versions remain historical releases and are not alternate supported
@@ -56,6 +56,10 @@ Earlier SDK versions remain historical releases and are not alternate supported
5656
`NamespaceDescription.deleted`.
5757

5858
### Fixed
59+
- Worker workflow, activity, query, update, and update-validation tasks now
60+
reject every missing, null, or otherwise non-exact root payload codec before
61+
decoding envelopes or invoking application code. Customer-owned Avro values
62+
and metadata remain free to use `codec` and `payload_codec` keys.
5963
- Explicit JSON and unknown payload-codec tags now fail closed before null,
6064
absent, empty-argument, or already-decoded replay shortcuts. Untagged
6165
no-payload sentinels and Avro-encoded null values retain their intended

‎pyproject.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "durable-workflow"
7-
version = "2.0.0-rc.31"
7+
version = "2.0.0-rc.32"
88
description = "Release candidate Python SDK for the Durable Workflow 2.0 train"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -68,8 +68,8 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
6868
durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
6969

7070
[tool.durable-workflow]
71-
product-train = "2.0.0-rc.31"
72-
registry-version = "2.0.0rc31"
71+
product-train = "2.0.0-rc.32"
72+
registry-version = "2.0.0rc32"
7373
supported-server-versions = "2.0.0-rc.32"
7474
worker-protocol-version = "1.1"
7575
control-plane-version = "2"

‎scripts/ci/run-codec-regression-fixture.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ def execute_fixture(fixture: dict[str, Any], codec: Any) -> None:
4343
)
4444
_require("python" in fixture["bindings"], "fixture must name the python binding")
4545
protocol = fixture["protocol"]
46+
if protocol["codec"] == "task-root":
47+
from durable_workflow.worker import _validate_payload_codec
48+
49+
wire = base64.b64decode(fixture["framing"]["wire_base64"], validate=True).decode("utf-8")
50+
tasks = json.loads(wire)
51+
_require(tasks == _tagged_value(fixture["value"]), "task fixture value does not match its wire bytes")
52+
_require(
53+
fixture["failure_policy"]
54+
== {
55+
"operation": "decode_reject",
56+
"error": "unsupported_payload_codec",
57+
},
58+
"task-root fixture must declare the stable codec rejection",
59+
)
60+
_require(isinstance(tasks, list) and tasks, "task-root fixture must contain rejected tasks")
61+
for task in tasks:
62+
_require(isinstance(task, dict), "task-root fixture entries must be task objects")
63+
try:
64+
_validate_payload_codec(task.get("payload_codec"))
65+
except ValueError as caught:
66+
_require("unsupported_payload_codec" in str(caught), "task-root rejection is not actionable")
67+
continue
68+
raise AssertionError("non-exact root task payload codec did not fail closed")
69+
return
70+
4671
if protocol["codec"] == "json":
4772
from durable_workflow import serializer
4873

@@ -63,7 +88,7 @@ def execute_fixture(fixture: dict[str, Any], codec: Any) -> None:
6388
return
6489
raise AssertionError("json-tagged workflow payload did not fail closed")
6590

66-
_require(protocol["codec"] == "avro", "fixture codec must be avro or a JSON rejection")
91+
_require(protocol["codec"] == "avro", "fixture codec must be avro, task-root, or a JSON rejection")
6792
_require(
6893
protocol["version"] == AVRO_PROTOCOL_VERSION,
6994
"fixture protocol.version must be the canonical version supported by "

‎src/durable_workflow/worker.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,19 @@
125125

126126

127127
def _command_payload_codec(codec: object) -> str:
128-
return _validate_payload_codec(codec) or serializer.AVRO_CODEC
128+
if codec is None:
129+
return serializer.AVRO_CODEC
130+
return _validate_payload_codec(codec)
129131

130132

131-
def _validate_payload_codec(codec: object) -> str | None:
132-
if codec is None:
133-
return None
134-
if isinstance(codec, str) and codec in serializer.SUPPORTED_CODECS:
133+
def _validate_payload_codec(codec: object) -> str:
134+
if isinstance(codec, str) and codec == serializer.AVRO_CODEC:
135135
return codec
136-
raise ValueError(
136+
raise _unsupported_payload_codec(codec)
137+
138+
139+
def _unsupported_payload_codec(codec: object) -> ValueError:
140+
return ValueError(
137141
"unsupported_payload_codec: workflow payload codec "
138142
f"{codec!r} is not supported by Durable Workflow 2.0; use codec='avro' "
139143
"with the fixed Avro Value schema and single-object framing. JSON remains "
@@ -1526,7 +1530,7 @@ async def _run_activity_task(self, task: dict[str, Any]) -> str:
15261530
raw_args = task.get("arguments")
15271531
inbound_codec = task.get("payload_codec")
15281532
try:
1529-
inbound_codec = _validate_payload_codec(inbound_codec) or serializer.AVRO_CODEC
1533+
inbound_codec = _validate_payload_codec(inbound_codec)
15301534
args = serializer.decode_envelope(
15311535
raw_args,
15321536
codec=inbound_codec,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json",
3+
"fixture_schema": "durable-workflow.codec-regression/v1",
4+
"id": "missing-null-root-task-codecs-rejected",
5+
"protocol": {
6+
"codec": "task-root",
7+
"schema": "durable_workflow.worker.Task",
8+
"version": "1",
9+
"fingerprint": null
10+
},
11+
"bindings": [
12+
"python"
13+
],
14+
"value": {
15+
"type": "array",
16+
"items": [
17+
{
18+
"type": "map",
19+
"entries": []
20+
},
21+
{
22+
"type": "map",
23+
"entries": [
24+
{
25+
"key": "payload_codec",
26+
"value": {
27+
"type": "null"
28+
}
29+
}
30+
]
31+
}
32+
]
33+
},
34+
"framing": {
35+
"encoding": "utf8-json-task",
36+
"wire_base64": "W3t9LCB7InBheWxvYWRfY29kZWMiOiBudWxsfV0="
37+
},
38+
"failure_policy": {
39+
"operation": "decode_reject",
40+
"error": "unsupported_payload_codec"
41+
}
42+
}

‎tests/test_api_reference_install.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def run_requirement(
195195
]
196196

197197

198-
def test_public_rc24_does_not_mask_an_unpublished_exact_rc31(
198+
def test_public_rc24_does_not_mask_an_unpublished_exact_rc32(
199199
monkeypatch: pytest.MonkeyPatch,
200200
) -> None:
201201
identity = load_release_identity(REPO_ROOT)
@@ -214,26 +214,26 @@ def run_requirement(
214214
raise PublicRequirementUnavailable(1, ["pip", "install", requirement])
215215
raise subprocess.CalledProcessError(
216216
1,
217-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc31"],
217+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc32"],
218218
)
219219

220220
monkeypatch.setattr("scripts.check_api_reference_install._run_clean_requirement", run_requirement)
221221

222222
with pytest.raises(PublicRequirementUnavailable):
223223
run_clean_install(identity.requirement, identity, install_attempts=1, install_retry_sleep=0)
224224

225-
assert identity.registry_version == "2.0.0rc31"
225+
assert identity.registry_version == "2.0.0rc32"
226226
assert calls == [identity.exact_requirement]
227227

228228

229-
def test_stale_documented_range_is_a_hard_failure_after_exact_rc31_exists(
229+
def test_stale_documented_range_is_a_hard_failure_after_exact_rc32_exists(
230230
monkeypatch: pytest.MonkeyPatch,
231231
) -> None:
232232
identity = load_release_identity(REPO_ROOT)
233233
calls: list[str] = []
234234
stale_range = subprocess.CalledProcessError(
235235
1,
236-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc31"],
236+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc32"],
237237
)
238238

239239
def run_requirement(

‎tests/test_pypi_project_surface.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
def source_metadata(*, stable: bool = False) -> SourceMetadata:
25-
version = "2.0.0" if stable else "2.0.0-rc.31"
26-
registry_version = "2.0.0" if stable else "2.0.0rc31"
25+
version = "2.0.0" if stable else "2.0.0-rc.32"
26+
registry_version = "2.0.0" if stable else "2.0.0rc32"
2727
return SourceMetadata(
2828
commit="a" * 40,
2929
name="durable-workflow",
@@ -163,7 +163,7 @@ def resolve(requirement: str, *, prerelease: bool) -> object:
163163
monkeypatch.setattr("scripts.check_pypi_project_surface._pip_report", resolve)
164164
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
165165

166-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc31"):
166+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc32"):
167167
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
168168

169169
assert requirements == [
@@ -191,14 +191,14 @@ def run_pip(command: list[str], **_: object) -> subprocess.CompletedProcess[str]
191191
if "==" in requirement and pip_attempts[requirement] == 1:
192192
detail = (
193193
f"ERROR: Could not find a version that satisfies the requirement {requirement} "
194-
"(from versions: 0.4.106, 2.0.0rc30)\n"
194+
"(from versions: 0.4.106, 2.0.0rc31)\n"
195195
f"ERROR: No matching distribution found for {requirement}\n"
196196
)
197197
return subprocess.CompletedProcess(command, 1, stdout="", stderr=detail)
198198

199199
version = source.registry_version
200200
if "~=" in requirement and pip_attempts[requirement] == 1:
201-
version = "2.0.0rc30"
201+
version = "2.0.0rc31"
202202
report_path = Path(command[command.index("--report") + 1])
203203
report_path.write_text(json.dumps(pip_report(version)), encoding="utf-8")
204204
return subprocess.CompletedProcess(command, 0, stdout="", stderr="")
@@ -262,7 +262,7 @@ def test_exact_pip_semantic_mismatch_fails_without_retrying(monkeypatch: pytest.
262262
)
263263
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
264264

265-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc31"):
265+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc32"):
266266
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
267267

268268
assert requirements == [f"{source.name}=={source.registry_version}"]

‎tests/test_release_docs_source.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
REPO_ROOT = Path(__file__).resolve().parents[1]
77
VALIDATOR = REPO_ROOT / "scripts" / "ci" / "validate-release-docs-source.py"
8-
VERSION = "2.0.0-rc.31"
8+
VERSION = "2.0.0-rc.32"
99

1010

1111
def git(repo: Path, *arguments: str) -> str:

‎tests/test_release_metadata.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def source_metadata() -> SourceMetadata:
1313
return SourceMetadata(
1414
commit="a" * 40,
1515
name="durable-workflow",
16-
version="2.0.0-rc.31",
17-
registry_version="2.0.0rc31",
16+
version="2.0.0-rc.32",
17+
registry_version="2.0.0rc32",
1818
summary="Release candidate Python SDK for the Durable Workflow 2.0 train",
1919
classifiers=("Programming Language :: Python :: 3",),
2020
readme=(

0 commit comments

Comments
 (0)