Skip to content

Commit 3623670

Browse files
Document worker history paging contracts
1 parent 67dfbf2 commit 3623670

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

docs/polyglot/cli-python-parity.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ repositories:
2222
| Query workflow | `tests/fixtures/control-plane/workflow-query-parity.json` |
2323
| Update workflow | `tests/fixtures/control-plane/workflow-update-parity.json` |
2424
| Cancel workflow | `tests/fixtures/control-plane/workflow-cancel-parity.json` |
25+
| Workflow task history page | `tests/fixtures/control-plane/workflow-task-history-parity.json` |
2526

2627
The CLI sends JSON caller payloads directly. The Python SDK wraps the same
2728
semantic payload in its Avro envelope. Both target the same endpoint and
@@ -195,6 +196,41 @@ Both calls mean `POST /workflows/{workflow_id}/cancel`. Cancellation is
195196
cooperative: workflow code can observe it and clean up. Use termination only
196197
for the force-stop operator path.
197198

199+
## Workflow Task History Page
200+
201+
Worker-history paging is a worker-plane operation, not the ordinary
202+
control-plane run-history listing. Use it when a workflow-task poll response
203+
contains `next_history_page_token` and the worker needs the next replay page
204+
for the same leased task.
205+
206+
CLI:
207+
208+
```bash
209+
dw workflow-task:history workflow-task-231 history-page-2 \
210+
--lease-owner=polyglot-worker-231 \
211+
--attempt=2 \
212+
--json
213+
```
214+
215+
Python:
216+
217+
```python
218+
async with client:
219+
page = await client.workflow_task_history(
220+
task_id="workflow-task-231",
221+
next_history_page_token="history-page-2",
222+
lease_owner="polyglot-worker-231",
223+
workflow_task_attempt=2,
224+
)
225+
```
226+
227+
Both calls mean `POST /worker/workflow-tasks/{task_id}/history` with
228+
`next_history_page_token`, `lease_owner`, and `workflow_task_attempt` in the
229+
JSON request body. Both surfaces preserve the canonical server response fields:
230+
`history_events`, `total_history_events`, and `next_history_page_token`.
231+
Do not treat the control-plane aliases `events` or `next_page_token` as valid
232+
worker-history response fields.
233+
198234
## Parity Checklist
199235

200236
When adding a new CLI or SDK operation, keep the contract language-neutral:

docs/polyglot/cli-reference.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,41 @@ worker loops.
196196
| Command | Purpose | Important options |
197197
| --- | --- | --- |
198198
| `dw workflow-task:poll <worker-id>` | Poll one workflow task. | `--task-queue`, `--build-id`, `--poll-request-id`, `--history-page-size`, `--accept-history-encoding`, `--json` |
199+
| `dw workflow-task:history <task-id> <page-token>` | Fetch the next history page for a leased workflow task. | `--lease-owner`, `--attempt`, `--json` |
199200
| `dw workflow-task:complete <task-id> <attempt>` | Complete one workflow task with command payloads. | `--lease-owner`, `--complete-result`, `--command`, `--json` |
200201
| `dw activity:complete <task-id> <attempt-id>` | Complete one leased activity attempt. | `--lease-owner`, input options, `--json` |
201202
| `dw activity:fail <task-id> <attempt-id>` | Fail one leased activity attempt. | `--lease-owner`, `--message`, `--type`, `--non-retryable`, `--json` |
202203

204+
### Workflow Task History Pages
205+
206+
`workflow-task:history` is the CLI diagnostic wrapper around the worker-plane
207+
history-page endpoint. Use it only after `workflow-task:poll` returns a leased
208+
workflow task with `next_history_page_token`; normal workers should let their
209+
SDK fetch extra history pages.
210+
211+
```bash
212+
dw workflow-task:history workflow-task-01 history-page-2 \
213+
--lease-owner=python-worker-1 \
214+
--attempt=2 \
215+
--json
216+
```
217+
218+
JSON output is the server response without field renaming:
219+
220+
```json
221+
{
222+
"history_events": [
223+
{"event_id": 2, "event_type": "ActivityScheduled", "payload": {}}
224+
],
225+
"total_history_events": 4,
226+
"next_history_page_token": "history-page-3"
227+
}
228+
```
229+
230+
Automation should read `history_events`, `total_history_events`, and
231+
`next_history_page_token`. The worker-history endpoint does not use the
232+
control-plane run-history fields `events` or `next_page_token`.
233+
203234
## Namespace And Search Attribute Commands
204235

205236
| Command | Purpose | Important options |

docs/polyglot/python.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,25 @@ These methods send `X-Durable-Workflow-Protocol-Version` and use `worker_token`
277277
when one is configured. Prefer the higher-level `Worker` unless you are writing
278278
an SDK adapter or protocol conformance test.
279279

280+
`workflow_task_history(...)` pages replay history for one already leased
281+
workflow task. Call it only after `poll_workflow_task(...)` returns
282+
`next_history_page_token`:
283+
284+
```python
285+
page = await client.workflow_task_history(
286+
task_id="workflow-task-01",
287+
next_history_page_token="history-page-2",
288+
lease_owner="python-worker-1",
289+
workflow_task_attempt=2,
290+
)
291+
```
292+
293+
The request body uses `next_history_page_token`, `lease_owner`, and
294+
`workflow_task_attempt`. The decoded response uses the worker-protocol field
295+
names `history_events`, `total_history_events`, and
296+
`next_history_page_token`; it does not use the control-plane run-history names
297+
`events` or `next_page_token`.
298+
280299
## Defining Workflows
281300

282301
Workflows are Python classes decorated with `@workflow.defn`. The `run` method is a generator that yields commands to the server.

0 commit comments

Comments
 (0)