forkreduce 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {forkreduce-0.2.0 → forkreduce-0.2.1}/CHANGELOG.md +7 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/PKG-INFO +1 -1
- {forkreduce-0.2.0 → forkreduce-0.2.1}/pyproject.toml +1 -1
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/__init__.py +1 -1
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/contrib/temporal.py +8 -2
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/session.py +7 -3
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_failures.py +123 -1
- {forkreduce-0.2.0 → forkreduce-0.2.1}/.github/workflows/ci.yml +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/.github/workflows/release.yml +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/.gitignore +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/LICENSE +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/README.md +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/README.zh-CN.md +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/docs/assets/logo.png +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/docs/assets/logo.svg +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/docs/assets/overview.svg +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/docs/assets/overview.zh-CN.svg +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/__init__.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/notice.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/run_live.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/run_offline.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/run_spec_refs_offline.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/examples/run_temporal_offline.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/checks.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/context.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/contrib/__init__.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/contrib/_temporal_specs.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/contrib/_temporal_store.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/coverage.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/documents.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/errors.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/executor.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/failures.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/followup.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/models.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/output_modes.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/output_specs.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/plan.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/policy.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/prefix.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/py.typed +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/query.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/reduce.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/schemas.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/stats.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/temporal_options.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/src/forkreduce/textutil.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/conftest.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/support.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_checks.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_context.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_document_layout.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_example.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_executor.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_feedback_aggregation.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_instrumentation.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_models.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_output_feedback.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_output_modes.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_output_specs.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_prefix.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_query_refinements.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_reduce.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_delete.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_features.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_feedback.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_fresh.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_hooks.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_layout.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_names.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_options.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_output_specs.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_runtime.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_scheduling.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_snapshots.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_spec_refs.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_store_context.py +0 -0
- {forkreduce-0.2.0 → forkreduce-0.2.1}/tests/test_temporal_validator_identity.py +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 — 2026-11-19
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Sanitize classified model failures at the Temporal boundary; retry, cancellation propagation, and failure metadata remain unchanged. This is not blanket protection for storage or factory errors, and it does not rewrite existing history.
|
|
8
|
+
- CI-only: combine the existing `SIM102` condition in `Session._check_output_mode`; no runtime behavior change.
|
|
9
|
+
|
|
3
10
|
## 0.2.0 — 2026-10-25
|
|
4
11
|
|
|
5
12
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: forkreduce
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Share one frozen prompt prefix across many LLM queries, MapReduce style, on Pydantic AI.
|
|
5
5
|
Project-URL: Homepage, https://github.com/426ai/forkreduce
|
|
6
6
|
Project-URL: Repository, https://github.com/426ai/forkreduce
|
|
@@ -75,7 +75,7 @@ with workflow.unsafe.imports_passed_through():
|
|
|
75
75
|
)
|
|
76
76
|
from forkreduce.documents import Document, DocumentFormat
|
|
77
77
|
from forkreduce.errors import ForkReduceError
|
|
78
|
-
from forkreduce.failures import Failure
|
|
78
|
+
from forkreduce.failures import Failure, FailureKind
|
|
79
79
|
from forkreduce.models import canonical_value, request_body_settings
|
|
80
80
|
from forkreduce.output_modes import OutputMode, ResolvedOutputMode, UnforcedToolsPolicy
|
|
81
81
|
from forkreduce.output_specs import DynamicOutputs, OutputSpec
|
|
@@ -439,7 +439,7 @@ def to_application_error(failure: Failure, *, feedback_retries_used: int = 0) ->
|
|
|
439
439
|
if feedback_retries_used:
|
|
440
440
|
detail["feedback_retries_used"] = feedback_retries_used
|
|
441
441
|
return ApplicationError(
|
|
442
|
-
failure.
|
|
442
|
+
_APPLICATION_ERROR_MESSAGES[failure.kind],
|
|
443
443
|
failure.kind.value,
|
|
444
444
|
detail,
|
|
445
445
|
type=failure.kind.value,
|
|
@@ -1011,6 +1011,12 @@ _FAILURE_MESSAGES: dict[QueryFailureKind, str] = {
|
|
|
1011
1011
|
"cancelled": "Query activity was cancelled.",
|
|
1012
1012
|
"unknown": "Query failed without a query-level failure classification.",
|
|
1013
1013
|
}
|
|
1014
|
+
_APPLICATION_ERROR_MESSAGES: dict[FailureKind, str] = {
|
|
1015
|
+
FailureKind.VALIDATION: "Query failed with a validation error.",
|
|
1016
|
+
FailureKind.TRANSPORT: "Query failed with a transport error.",
|
|
1017
|
+
FailureKind.PERMANENT: _FAILURE_MESSAGES["permanent"],
|
|
1018
|
+
FailureKind.BUDGET: _FAILURE_MESSAGES["budget"],
|
|
1019
|
+
}
|
|
1014
1020
|
_FAILURE_TYPES = frozenset(
|
|
1015
1021
|
{
|
|
1016
1022
|
"validation",
|
|
@@ -205,9 +205,13 @@ class Session:
|
|
|
205
205
|
f"to {actual!r}. Build a separate session for these settings or choose an explicit output_mode.",
|
|
206
206
|
code="output_mode_conflict",
|
|
207
207
|
)
|
|
208
|
-
elif
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
elif (
|
|
209
|
+
diagnose
|
|
210
|
+
and self.output_mode == "tools"
|
|
211
|
+
and self._forced_tools_available
|
|
212
|
+
and not forced_tools_available(self.model, settings)
|
|
213
|
+
):
|
|
214
|
+
diagnose_unforced_tools(self.on_unforced_tools)
|
|
211
215
|
|
|
212
216
|
def history_for(self, query: Query[Any]) -> list[ModelMessage]:
|
|
213
217
|
"""Prefix messages, or a copy of the continuation history."""
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import json
|
|
7
|
+
import logging
|
|
7
8
|
from dataclasses import asdict
|
|
8
9
|
from datetime import timedelta
|
|
9
10
|
from types import SimpleNamespace
|
|
@@ -26,7 +27,7 @@ from temporalio.worker import Replayer, Worker
|
|
|
26
27
|
with workflow.unsafe.imports_passed_through():
|
|
27
28
|
from pydantic import BaseModel
|
|
28
29
|
from pydantic_ai.durable_exec.temporal import PydanticAIPlugin
|
|
29
|
-
from pydantic_ai.exceptions import ModelHTTPError
|
|
30
|
+
from pydantic_ai.exceptions import ModelHTTPError, UnexpectedModelBehavior
|
|
30
31
|
from temporalio.client import WorkflowFailureError
|
|
31
32
|
from tests.support import Scripted, tool_result
|
|
32
33
|
from tests.test_temporal_runtime import sandbox_runner, server_options
|
|
@@ -403,6 +404,127 @@ def test_failure_details_preserve_kind_and_add_observed_attempt(monkeypatch) ->
|
|
|
403
404
|
assert error.details == ("transport", {"forkreduce_attempt": 3})
|
|
404
405
|
|
|
405
406
|
|
|
407
|
+
@pytest.mark.parametrize(
|
|
408
|
+
("kind", "retryable"),
|
|
409
|
+
[
|
|
410
|
+
(FailureKind.VALIDATION, True),
|
|
411
|
+
(FailureKind.TRANSPORT, True),
|
|
412
|
+
(FailureKind.PERMANENT, False),
|
|
413
|
+
(FailureKind.BUDGET, False),
|
|
414
|
+
],
|
|
415
|
+
)
|
|
416
|
+
def test_application_error_conversion_uses_safe_classification_message(
|
|
417
|
+
monkeypatch, kind: FailureKind, retryable: bool
|
|
418
|
+
) -> None: # type: ignore[no-untyped-def]
|
|
419
|
+
marker = "synthetic-conversion-error-sentinel"
|
|
420
|
+
monkeypatch.setattr(adapter.activity, "in_activity", lambda: True)
|
|
421
|
+
monkeypatch.setattr(adapter.activity, "info", lambda: SimpleNamespace(attempt=3))
|
|
422
|
+
failure = Failure(kind, marker, retryable, detail={"raw_error": marker})
|
|
423
|
+
|
|
424
|
+
error = adapter.to_application_error(failure, feedback_retries_used=2)
|
|
425
|
+
|
|
426
|
+
assert failure.message == marker
|
|
427
|
+
assert error.message == adapter._APPLICATION_ERROR_MESSAGES[kind]
|
|
428
|
+
assert marker not in str(error)
|
|
429
|
+
assert marker not in json.dumps(error.details)
|
|
430
|
+
assert error.type == kind.value
|
|
431
|
+
assert error.non_retryable is not retryable
|
|
432
|
+
assert error.details == (kind.value, {"forkreduce_attempt": 3, "feedback_retries_used": 2})
|
|
433
|
+
assert error.__cause__ is None and error.__context__ is None
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
@pytest.mark.parametrize("batch_size", [None, 1])
|
|
437
|
+
@pytest.mark.parametrize("mode", ["raise", "return"])
|
|
438
|
+
async def test_model_error_sentinel_is_absent_from_temporal_logs_and_history(
|
|
439
|
+
caplog: pytest.LogCaptureFixture, batch_size: int | None, mode: str
|
|
440
|
+
) -> None:
|
|
441
|
+
marker = "synthetic-template-parse-error-sentinel-71b4"
|
|
442
|
+
attempts: list[int] = []
|
|
443
|
+
|
|
444
|
+
def handler(_messages, _info, _n): # type: ignore[no-untyped-def]
|
|
445
|
+
attempts.append(activity.info().attempt)
|
|
446
|
+
raise UnexpectedModelBehavior(marker)
|
|
447
|
+
|
|
448
|
+
session = build(
|
|
449
|
+
Scripted(handler).model(),
|
|
450
|
+
documents="Synthetic parsing evidence.",
|
|
451
|
+
instructions="Answer.",
|
|
452
|
+
outputs=[FailureAnswer],
|
|
453
|
+
warmup=False,
|
|
454
|
+
policy=Policy(retries=1, retry_backoff=0.001, max_backoff=0.001),
|
|
455
|
+
)
|
|
456
|
+
prefix = adapter.register_session(session)
|
|
457
|
+
adapter.set_message_store(adapter.InMemoryMessageStore() if batch_size else None)
|
|
458
|
+
caplog.set_level(logging.WARNING, logger="temporalio.activity")
|
|
459
|
+
try:
|
|
460
|
+
async with await WorkflowEnvironment.start_time_skipping(**server_options()) as env:
|
|
461
|
+
queue = f"safe-model-error-{uuid4()}"
|
|
462
|
+
async with Worker(
|
|
463
|
+
env.client,
|
|
464
|
+
task_queue=queue,
|
|
465
|
+
workflows=[adapter.MapQueriesWorkflow, adapter.QueryBatchWorkflow],
|
|
466
|
+
activities=[adapter.run_query_activity],
|
|
467
|
+
workflow_runner=sandbox_runner(),
|
|
468
|
+
):
|
|
469
|
+
handle = await env.client.start_workflow(
|
|
470
|
+
adapter.MapQueriesWorkflow.run,
|
|
471
|
+
adapter.MapQueriesInput(
|
|
472
|
+
queries=[
|
|
473
|
+
adapter.query_activity_input(
|
|
474
|
+
session, query_id="parse-error", tail="Question", output_name="FailureAnswer"
|
|
475
|
+
)
|
|
476
|
+
],
|
|
477
|
+
batch_size=batch_size,
|
|
478
|
+
on_query_failure=mode,
|
|
479
|
+
),
|
|
480
|
+
id=f"safe-model-error-{uuid4()}",
|
|
481
|
+
task_queue=queue,
|
|
482
|
+
execution_timeout=timedelta(seconds=30),
|
|
483
|
+
)
|
|
484
|
+
if mode == "return":
|
|
485
|
+
result = (await asyncio.wait_for(handle.result(), 30))[0]
|
|
486
|
+
assert result.failure_kind == "retryable_exhausted"
|
|
487
|
+
assert result.failure_type == "validation"
|
|
488
|
+
assert result.attempts == 2
|
|
489
|
+
assert marker not in json.dumps(asdict(result))
|
|
490
|
+
else:
|
|
491
|
+
with pytest.raises(WorkflowFailureError) as caught:
|
|
492
|
+
await asyncio.wait_for(handle.result(), 30)
|
|
493
|
+
cause: BaseException | None = caught.value
|
|
494
|
+
while cause is not None and not isinstance(cause, ApplicationError):
|
|
495
|
+
cause = cause.__cause__
|
|
496
|
+
assert isinstance(cause, ApplicationError)
|
|
497
|
+
assert cause.type == "validation"
|
|
498
|
+
assert cause.non_retryable is False
|
|
499
|
+
assert cause.details[0] == "validation"
|
|
500
|
+
assert cause.details[1] == {"forkreduce_attempt": 2}
|
|
501
|
+
assert marker not in str(caught.value)
|
|
502
|
+
assert marker not in cause.message
|
|
503
|
+
assert cause.__cause__ is None and cause.__context__ is None
|
|
504
|
+
|
|
505
|
+
history = await handle.fetch_history()
|
|
506
|
+
child_ids = [
|
|
507
|
+
event.start_child_workflow_execution_initiated_event_attributes.workflow_id
|
|
508
|
+
for event in history.events
|
|
509
|
+
if event.HasField("start_child_workflow_execution_initiated_event_attributes")
|
|
510
|
+
]
|
|
511
|
+
child_histories = [
|
|
512
|
+
await env.client.get_workflow_handle(child_id).fetch_history() for child_id in child_ids
|
|
513
|
+
]
|
|
514
|
+
|
|
515
|
+
histories = [history, *child_histories]
|
|
516
|
+
assert attempts == [1, 2]
|
|
517
|
+
assert any(
|
|
518
|
+
event.HasField("activity_task_failed_event_attributes") for item in histories for event in item.events
|
|
519
|
+
)
|
|
520
|
+
assert marker not in "\n".join(item.to_json() for item in histories)
|
|
521
|
+
assert "Completing activity as failed" in caplog.text
|
|
522
|
+
assert marker not in caplog.text
|
|
523
|
+
finally:
|
|
524
|
+
adapter.unregister_session(prefix)
|
|
525
|
+
adapter.set_message_store(None)
|
|
526
|
+
|
|
527
|
+
|
|
406
528
|
async def test_activity_payload_carries_parent_workflow_identity(monkeypatch) -> None: # type: ignore[no-untyped-def]
|
|
407
529
|
captured = []
|
|
408
530
|
query = adapter.QueryActivityInput("prefix", "q", "question", "FailureAnswer")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|