xihaian251 commented on PR #931:
URL: https://github.com/apache/burr/pull/931#issuecomment-6555539267
Following up on the resume-seeded memo point.
I prepared an isolated two-commit patch series on top of
`06d02aec8713f193720bb082583337e529397d55`.
**The lifecycle issue reproduces on both resume paths.**
`_serialization_context_factory()` builds a
new `SerializationContext` on every call, and a resumed build calls it twice
— once for the
initializer load (`_load_from_sync_persister` /
`_load_from_async_persister`) and once in
`Application.__init__` for the hook context. Recording the construction site
and the context object
each (de)serializer receives, on the unmodified head:
```
sync (SQLitePersister + ArtifactStore) resumed build -> 2 contexts
0x…1bd0 application.py:2814 _load_from_sync_persister() <- the
deserializer gets this
0x…20d0 application.py:912 __init__() <- the
application installs this
load-time context == run-time context? NO
async (AsyncSQLitePersister + AsyncArtifactStore) resumed build -> 2 contexts
0x…1c40 application.py:2837 _load_from_async_persister() -> OVERLAP? NO
```
A cold build creates exactly one context, so this is specific to
`initialize_from` — i.e. to the
short-lived-app-per-request pattern the docs are aiming at.
**The series**
1. `fix(core): share serialization context across resume` —
`build()`/`abuild()` create the context
once and hand the same manager to the load and to the application.
`Application.__init__` still
builds its own from `object_store` when no `hook_context` is passed, and
nothing is created at all
when there is no object store.
2. `feat(core): add per-application serialization memo` — the `memo` field
(`default_factory=dict`, with `compare=False, hash=False` so the class
keeps the hashability and
store-based equality it has today), the cache-key caveat in the
docstring, and the regression
tests.
**Results, from this run** (Python 3.13.1; black 23.11.0 / isort 5.12.0 /
flake8 6.1.0, the versions
`.pre-commit-config.yaml` pins):
| | before (`06d02aec`) | after |
|---|---|---|
| `tests/core` + `tests/tracking` | 12 failed, **514** passed | 12 failed,
**524** passed — failing test names identical |
| CI-shaped full run | 18 failed, 654 passed, 9 errors | 18 failed, **664**
passed, 9 errors — FAILED+ERROR names identical (36 lines) |
| `tests/core/test_serialization_context.py` | 20 tests | **30 passed** (the
10 new ones included) |
| repro after the fix | — | 1 context per build, sync **and** async:
`OVERLAP? YES` |
Commit 1 in isolation is worth a reviewer's attention: applied **without**
`memo` and without any new
test, the existing suite is `514 passed` with the same 12 failures as the
base — so the part that
changes control flow is behaviour-neutral today, and only decides *when* a
context is constructed.
The 12/18/9 pre-existing failures are environmental here and unchanged by
this: missing `graphviz`,
`jinja2`, `boto3`, `pandas`, `langchain_*`, `hamilton`, `haystack`, `ray`;
three symlink tests in
`test_artifacts.py` that error on Windows rather than skipping (`WinError
1314`, needs symlink
privilege); and
`test_apache_release.py::test_build_sdist_uses_artifact_specific_license`, which
fails on `main` too from CRLF in a Windows checkout. Nothing was skipped,
deleted or weakened.
Ten new tests, the ones a reviewer probably wants to look at first:
- resume seeds a memo the first persist can use, sync and async — asserted
as **the store seeing no
calls at all** after the resume, not as a smaller count;
- load-time context `is` the application's context, sync and async (identity
with `is`, never `==`,
because `compare=False` makes two contexts wrapping one store compare
equal);
- two applications, and one builder used twice, never share a memo;
- no object store → no context installed, `_serialization_hook_context()`
returns `None`, and
`SerializationContext` is still hashable with store-based equality;
- the cache-key case: two values with identical bytes and different metadata
keep their own metadata
(the memo caches the `ArtifactRef` and the payload's metadata part is
rebuilt per value);
- persister and tracker attached together → exactly one `put`, and the
tracker log holds the
reference rather than the payload.
**To be clear about what this is not:** #931 does not implement `memo`
today, so this is not a claim
that the current branch has a memo bug. `SerializationContext` is stateless
right now and the double
construction is invisible. It's a note that the resume-seeding semantics
proposed for the memo need
the context to be one object per application, and that wiring it in is small
now and would be an API
question later.
Scope kept deliberately narrow: it does not touch the async trackers, so the
async-serde-plus-
`LocalTrackingClient` failure in your gap table still stands; it does not
change
`put_artifact`'s `exists`-then-`digest` round-trips; and it does not add a
bounded/own memo.
Not verified, and I'd rather list it than imply it:
- **Python 3.9/3.10/3.11** — I have 3.12/3.13 locally. 3.12 runs the sync
subset clean; the async
tests need `aiosqlite`/`pytest-asyncio`, so they are 3.13-verified only.
No 3.10+ syntax in the
diff, but the floor is CI's to confirm.
- **Real S3** — no `boto3` here, so `put_artifact`'s conditional-write path
is covered only by the
local and in-memory stores.
- **Ray** — `tests/integrations/test_burr_ray.py` won't even collect without
`ray`. The claim that
each worker gets its own context is read off `parallelism.py:126`, not run.
- **`MapStates` sub-applications** — the existing cascade test passes, but I
did not add an assertion
that a sub-application starts with a fresh memo. That looks like a natural
eleventh test.
Patch branch:
https://github.com/xihaian251/burr/tree/pr931-f4-resume-memo-lifecycle
Compare against the PR head:
https://github.com/xihaian251/burr/compare/06d02aec8713f193720bb082583337e529397d55...pr931-f4-resume-memo-lifecycle
(2 commits, 3 files, +511/−13 — `burr/core/application.py` +48/−12,
`burr/core/serde.py` +16/−1,
`tests/core/test_serialization_context.py` +447)
- Commit 1:
https://github.com/xihaian251/burr/commit/1b6733eff3926843a7ee5f096d24a7e99300b625
- Commit 2:
https://github.com/xihaian251/burr/commit/c33dd0045e619a34aadac59ee7444c7b262a102c
Happy for you to cherry-pick or adapt either commit if this direction fits
the intended API — and if
you would rather the context be created differently (e.g. threading the
`SerializationContext` object
itself instead of its manager, so a second context cannot be produced by
accident), that is a
reasonable objection and the threading half is cheap to reshape.
*Prepared with AI assistance; every number above comes from running it on my
machine, not from recall.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]