Skip to content

Commit c1ef65e

Browse files
committed
Merge origin/main into feat/mcp-server
Resolve the anyio conflict that forced the mcp isolation: - main widened the workflow pin to anyio>=4.9,<4.14, compatible with mcp>=2 - drop [tool.uv] conflicts and the separate test dependency group - add mcp to the all extra and to the dev group - relock
2 parents 951a66e + 0d32bc2 commit c1ef65e

11 files changed

Lines changed: 683 additions & 206 deletions

‎CHANGELOG.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@
1010
1111
<!-- version list -->
1212

13+
## v2.0.2 (2026-08-28)
14+
15+
### Bug Fixes
16+
17+
- Keep WtSite deep-copyable after adding the session lock
18+
([`aa0d359`](https://github.com/OpenSemanticLab/osw-python/commit/aa0d359e188b6fe0a12aa1a8a1ac819a6ea2ce87))
19+
20+
- Make _clear_cookies safe against concurrent jar mutation
21+
([`e5fb473`](https://github.com/OpenSemanticLab/osw-python/commit/e5fb473f4740c180930a4a7be08d6843cb61fca5))
22+
23+
- Prevent silent page loss in store_entity parallel upload
24+
([`fc2fe36`](https://github.com/OpenSemanticLab/osw-python/commit/fc2fe364022c0549e8fe891a238c84592f7f14c1))
25+
26+
27+
## v2.0.1 (2026-08-28)
28+
29+
### Bug Fixes
30+
31+
- **deps**: Widen workflow anyio pin to >=4.9,<4.14
32+
([`21c4043`](https://github.com/OpenSemanticLab/osw-python/commit/21c4043a168379de43a7fe8ccabd1c266fe1a656))
33+
34+
### Documentation
35+
36+
- Add citation and authorship section to CONTRIBUTING.md
37+
([`a3a8119`](https://github.com/OpenSemanticLab/osw-python/commit/a3a8119cd047cee741812b11e3f1f26c3f91c639))
38+
39+
1340
## v2.0.0 (2026-08-05)
1441

1542
### Bug Fixes

‎CITATION.cff‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ message: "If you use this software, please cite it as below."
33
type: software
44
title: "OpenSemanticWorld Python Package (osw-python)"
55
# Managed by python-semantic-release (version_variables). Do not edit by hand.
6-
version: 2.0.0
6+
version: 2.0.2
77
abstract: "Python toolset for data processing, queries, wikicode generation and page manipulation within OpenSemanticLab: work with OpenSemanticLab instances as typed pydantic entities, query with semantic search, generate models from wiki schemas, and write changes back."
88
repository-code: "https://github.com/OpenSemanticLab/osw-python"
99
url: "https://opensemanticlab.github.io/osw-python/"

‎pyproject.toml‎

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license-files = ["LICENSE.txt"]
88
requires-python = ">=3.10,<3.14"
99
# Managed by python-semantic-release (see [tool.semantic_release]). Do not
1010
# edit by hand; it is bumped automatically on merge to main.
11-
version = "2.0.0"
11+
version = "2.0.2"
1212
classifiers = [
1313
"Development Status :: 3 - Alpha",
1414
"Intended Audience :: Developers",
@@ -83,16 +83,15 @@ workflow = [
8383
"prefect>=2.20.25,<3.0",
8484
# prefect 2.20.25 is the final 2.x release (no backports). Its
8585
# GatherTaskGroup subclasses anyio's TaskGroup but doesn't implement
86-
# create_task, which newer anyio 4.x made abstract (broken on 4.14,
87-
# verified good on 4.6.2); hold anyio to the last verified-good 4.6 line
88-
# so the prefect-2.x flow engine can still instantiate task groups.
89-
"anyio>=4.4.0,<4.7",
86+
# create_task, which anyio 4.14.0 promoted to an abstract method
87+
# (start_soon stopped being the abstract one). 4.13.x is the last line
88+
# where the prefect-2.x flow engine can still instantiate task groups.
89+
# The floor is 4.9 so this stays compatible with mcp>=2, see
90+
# https://github.com/OpenSemanticLab/osw-python/issues/139
91+
"anyio>=4.9,<4.14",
9092
]
9193
tutorial = ["osw[dataimport]"]
92-
# mcp is deliberately excluded here: it requires anyio>=4.9, which conflicts
93-
# with the workflow extra's anyio cap. Install it explicitly with osw[mcp].
94-
# See https://github.com/OpenSemanticLab/osw-python/issues/139
95-
all = ["osw[dataimport,DB,UI,S3,wikitext]"]
94+
all = ["osw[dataimport,DB,UI,S3,wikitext,mcp]"]
9695

9796
[project.scripts]
9897
# command-line access to a live OSL instance, built from the same
@@ -106,31 +105,17 @@ requires = ["hatchling"]
106105
build-backend = "hatchling.build"
107106

108107
[dependency-groups]
109-
# pytest stack in its own group so it can be installed alongside the mcp
110-
# extra, which conflicts with the dev group (see [tool.uv] below).
111-
# tests/test_service_*.py run in a plain `uv sync` dev env (no mcp extra
112-
# needed). Run the MCP-extra tests (tests/test_mcp_*.py) with:
113-
# uv sync --extra mcp --group test --no-dev
114-
# uv run --extra mcp --group test --no-dev --no-sync python -m pytest tests/test_mcp_*.py
115-
test = [
108+
dev = [
109+
# test stack
116110
"pytest",
117111
"pytest-cov",
118112
"pytest-mock",
119113
"pytest-asyncio",
120-
# not part of the mcp conflict set, so the shared service layer (which reads
121-
# .env lazily) stays importable and testable in a plain `uv sync` env.
122-
"python-dotenv>=1.0",
123-
]
124-
dev = [
125-
{ include-group = "test" },
126-
# prefect/anyio are listed directly rather than via osw[workflow]: the
127-
# workflow extra is in a uv conflict set (see [tool.uv] below), so a
128-
# self-referential osw[workflow] entry here would only activate when
129-
# --extra workflow is passed, leaving a bare `uv sync` on the anyio that
130-
# breaks prefect 2.20. Keep these pins in sync with the workflow extra.
131-
# Tracked in https://github.com/OpenSemanticLab/osw-python/issues/139
132-
"prefect>=2.20.25,<3.0",
133-
"anyio>=4.4.0,<4.7",
114+
# inherit the capped prefect pin (<3.0); a bare "prefect" here resolved to
115+
# 3.x in CI, whose server API breaks the prefect-2.20-targeted tests.
116+
# mcp is included so the MCP server and its tests run in the same
117+
# environment as everything else.
118+
"osw[workflow,mcp]",
134119
"geopy",
135120
"deepl",
136121
"sqlalchemy",
@@ -327,19 +312,6 @@ insertion_flag = "<!-- version list -->"
327312
[tool.semantic_release.changelog.default_templates]
328313
changelog_file = "CHANGELOG.md"
329314

330-
[tool.uv]
331-
# mcp 2.x needs anyio>=4.9; the workflow extra caps anyio<4.7 for prefect 2.20
332-
# (see the workflow extra above). They cannot share one resolution, so uv is
333-
# told to resolve them in separate splits. Install the MCP server standalone:
334-
# pip install "osw[mcp]".
335-
# The dev group is included too since it carries the same anyio cap directly
336-
# (see the dev group above). Tracked in
337-
# https://github.com/OpenSemanticLab/osw-python/issues/139
338-
conflicts = [
339-
[{ extra = "mcp" }, { extra = "workflow" }],
340-
[{ extra = "mcp" }, { group = "dev" }],
341-
]
342-
343315
[tool.ty.environment]
344316
python = "./.venv"
345317
python-version = "3.10"
@@ -350,10 +322,8 @@ python-version = "3.10"
350322
# - examples, scripts: illustrative/maintenance code, not part of the package
351323
# - tests: not yet type-clean, tightened in a follow-up
352324
#
353-
# src/osw/mcp is no longer excluded. The mcp extra still cannot be installed
354-
# alongside the dev group (issue #139), so the two SDK imports in server.py
355-
# carry an inline `ty: ignore[unresolved-import]`; everything else there, and
356-
# all of src/osw/service and src/osw/cli, is checked.
325+
# src/osw/mcp, src/osw/service and src/osw/cli are checked: the mcp extra is
326+
# part of the dev group, so the SDK imports resolve.
357327
exclude = [
358328
"src/osw/model/entity.py",
359329
"examples",

‎src/osw/core.py‎

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,11 +1593,34 @@ class StoreEntityResult(OswBaseModel):
15931593
change_id: str
15941594
"""The ID of the change"""
15951595
pages: Dict[str, WtPage]
1596-
"""The pages that have been stored"""
1596+
"""The pages that have been successfully stored, keyed by full page title.
1597+
On partial failure this contains only the successfully-stored pages."""
1598+
failed: Dict[str, Exception] = {}
1599+
"""Entities that could not be stored, keyed by full page title and mapped to
1600+
the exception that caused the failure. Empty on full success."""
15971601

15981602
class Config:
15991603
arbitrary_types_allowed = True
16001604

1605+
class StoreEntityPartialError(Exception):
1606+
"""Raised by store_entity() when one or more entities could not be stored.
1607+
1608+
Carries the partial ``StoreEntityResult`` so callers can learn exactly which
1609+
entities were written (``stored`` / ``result.pages``) and which failed
1610+
(``failed`` / ``result.failed``) without a separate existence query.
1611+
"""
1612+
1613+
def __init__(self, result: OSW.StoreEntityResult):
1614+
self.result = result
1615+
self.stored = list(result.pages.keys())
1616+
self.failed = result.failed
1617+
total = len(result.pages) + len(result.failed)
1618+
failed_titles = ", ".join(result.failed.keys())
1619+
super().__init__(
1620+
f"store_entity failed for {len(result.failed)} of {total} "
1621+
f"entities: {failed_titles}"
1622+
)
1623+
16011624
def store_entity(
16021625
self, param: Union[StoreEntityParam, OswBaseModel, List[OswBaseModel]]
16031626
) -> StoreEntityResult:
@@ -1790,27 +1813,63 @@ class UploadObject(BaseModel):
17901813
upload_index += 1
17911814

17921815
def handle_upload_object_(upload_object: UploadObject) -> None:
1816+
# Let exceptions propagate: the caller collects them per entity below,
1817+
# so a single failure neither aborts the batch nor is silently
1818+
# swallowed (store_entity_ only records created_pages on success).
1819+
store_entity_(
1820+
upload_object.entity,
1821+
upload_object.namespace,
1822+
upload_object.index,
1823+
upload_object.overwrite_class_param,
1824+
)
1825+
1826+
def failure_title_(upload_object: UploadObject) -> str:
1827+
"""Best-effort full page title of a failed entity, for error reporting."""
17931828
try:
1794-
store_entity_(
1795-
upload_object.entity,
1796-
upload_object.namespace,
1797-
upload_object.index,
1798-
upload_object.overwrite_class_param,
1829+
namespace = upload_object.namespace or get_namespace(
1830+
upload_object.entity
1831+
)
1832+
return f"{namespace}:{get_title(upload_object.entity)}"
1833+
except Exception:
1834+
return (
1835+
getattr(upload_object.entity, "name", None)
1836+
or getattr(upload_object.entity, "uuid", None)
1837+
or "unknown"
17991838
)
1800-
except Exception as e:
1801-
entity_name = getattr(upload_object.entity, "name", None) or "unknown"
1802-
_logger.error(f"Error storing entity '{entity_name}': {e}")
18031839

18041840
if param.parallel:
1805-
_ = parallelize(
1806-
handle_upload_object_, upload_object_list, flush_at_end=param.debug
1841+
# return_exceptions=True keeps results aligned with upload_object_list
1842+
# and lets every entity be attempted even if some fail.
1843+
results = parallelize(
1844+
handle_upload_object_,
1845+
upload_object_list,
1846+
flush_at_end=param.debug,
1847+
return_exceptions=True,
18071848
)
18081849
else:
1809-
_ = [
1810-
handle_upload_object_(upload_object)
1811-
for upload_object in upload_object_list
1812-
]
1813-
return OSW.StoreEntityResult(change_id=param.change_id, pages=created_pages)
1850+
results = []
1851+
for upload_object in upload_object_list:
1852+
try:
1853+
handle_upload_object_(upload_object)
1854+
results.append(None)
1855+
except Exception as e:
1856+
results.append(e)
1857+
1858+
failed: Dict[str, Exception] = {}
1859+
for upload_object, result in zip(upload_object_list, results):
1860+
if isinstance(result, Exception):
1861+
title = failure_title_(upload_object)
1862+
_logger.error(f"Error storing entity '{title}': {result}")
1863+
failed[title] = result
1864+
1865+
store_result = OSW.StoreEntityResult(
1866+
change_id=param.change_id, pages=created_pages, failed=failed
1867+
)
1868+
if failed:
1869+
# Surface partial/total failure so callers cannot mistake a dropped
1870+
# page for a success. The result (successes + failures) rides along.
1871+
raise OSW.StoreEntityPartialError(store_result)
1872+
return store_result
18141873

18151874
class DeleteEntityParam(OswBaseModel):
18161875
entities: Union[OswBaseModel, List[OswBaseModel]]

‎src/osw/utils/util.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def parallelize(
274274
iterable: Iterable,
275275
flush_at_end: bool = False,
276276
progress_bar: bool = True,
277+
return_exceptions: bool = False,
277278
**kwargs,
278279
):
279280
"""A function to parallelize tasks with a progress bar and a message buffer.
@@ -289,6 +290,11 @@ def parallelize(
289290
execution.
290291
progress_bar:
291292
If True, a progress bar will be displayed.
293+
return_exceptions:
294+
If True, exceptions raised by ``func`` are returned in the result list at the
295+
position of the corresponding item (instead of aborting the whole batch on the
296+
first failure). Mirrors ``asyncio.gather(return_exceptions=...)``. Results stay
297+
aligned with the input order, so callers can zip them back to ``iterable``.
292298
kwargs:
293299
Keyword arguments to be passed to the function.z
294300
"""
@@ -324,6 +330,18 @@ async def _run_tasks():
324330
print(
325331
f"Performing parallel execution of {func.__name__} ({len(tasks)} tasks)."
326332
)
333+
if return_exceptions:
334+
# tqdm.gather() re-raises the first exception (it has no
335+
# return_exceptions kwarg), which would abandon the remaining
336+
# results. Capture each task's exception instead so the batch
337+
# completes and results stay aligned with the input order.
338+
async def _capture(task):
339+
try:
340+
return await task
341+
except Exception as exc:
342+
return exc
343+
344+
tasks = [_capture(task) for task in tasks]
327345
res = await tqdm.gather(
328346
*tasks
329347
) # like asyncio.gather, but with a progress bar

0 commit comments

Comments
 (0)