From 6b576443b76235a387e21965fd32cd23dfcd6fb4 Mon Sep 17 00:00:00 2001 From: Dmitrii Karataev Date: Fri, 30 Oct 2026 08:08:25 -0700 Subject: [PATCH 1/4] feat(server): record each seed's bundle digest, so deploys can re-seed only changed apps A seeded app version now records the sha256 of the bundle it was copied from (metadata.build.bundleSha256), on the first copy and on a self-heal retry. bundle_changed() compares the pod's local bundle with the newest seed row's digest: an orchestrator can force only the apps whose build moved, instead of skipping them all (plain seed) or bumping all of them (--reseed). Seed rows from before this field count as changed once. The SaaS seed job wires it in rocketride-saas; nothing calls it here yet, and the plain and forced seeds behave as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015nTVr6jfSFYm1GppxbjghP --- CHANGELOG.md | 1 + packages/ai/src/ai/account/seed_apps.py | 80 ++++++- .../ai/tests/ai/account/test_seed_apps.py | 204 ++++++++++++++++++ 3 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 packages/ai/tests/ai/account/test_seed_apps.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b34383605e..74c45fd89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] — since 2026-10-16 ### Added +- **server**: a seeded app version records the sha256 of the bundle it was copied from (`metadata.build.bundleSha256`), and `bundle_changed()` tells an orchestrator whether the pod's build differs from the app's newest seed, so a deploy can re-seed only the apps whose build changed - **typescript**: add `SignupProperties`, `PkceCredential` and `normalizeSignupProperties` for optional validated signup attribution resolved immediately before PKCE authentication; credentials without context retain their existing bytes (#2890). - **shell**: freeze additive API v8 with consent-gated `signupProperties` in `startOAuth` and `shell:loginRequest`, kept only in the PKCE credential and out of native telemetry facts; recheck privacy signals, consent and expiry after redirects and before authentication (#2890). - **nodes**: the vector-store tools gain `soft_delete` and `restore` on all nine store nodes (`rocketride_vector`, `store_astra`, `store_atlas`, `store_chroma`, `store_milvus`, `store_pinecone`, `store_postgres`, `store_qdrant`, `store_weaviate`): they move documents to the trash and back over the drivers' existing soft-delete support, are offered beside `upsert` and `delete` only while writes through tools are allowed, and report `matched_chunks` where the store counts the rows it marks (the two Postgres stores and Chroma). `rocketride_vector` and `store_postgres` also offer `list_documents` (one entry per document with its parent path and chunk count, paged and ordered by object ID, active documents or the trash) and report `document_count` in `stats`; both come from an optional driver capability (`DocumentStoreBase.listDocuments`, `countDocuments`, `supports_document_listing`) any other driver can adopt (#2587) diff --git a/packages/ai/src/ai/account/seed_apps.py b/packages/ai/src/ai/account/seed_apps.py index 9c2454da56..b652e0ae9a 100644 --- a/packages/ai/src/ai/account/seed_apps.py +++ b/packages/ai/src/ai/account/seed_apps.py @@ -42,6 +42,7 @@ """Edition-neutral seeding of the fixed platform apps from apps.json.""" +import hashlib import json import os import sys @@ -116,6 +117,39 @@ def load_manifest_entries() -> List[Dict[str, Any]]: return data.get('apps', []) +# ============================================================================= +# THE BUNDLE — the local built tree, and its digest +# ============================================================================= + + +def _local_bundle_root(app_id: str) -> str: + """Where the app build emits an app's bundle: ``/static/apps//``.""" + return os.path.join(os.path.dirname(sys.executable), 'static', 'apps', app_id) + + +def bundle_digest(app_id: str) -> Optional[str]: + """sha256 of an app's built bundle in the local static tree, or None when there is none. + + Covers each file's path relative to the bundle root and its bytes, walked + in sorted order, so the same build gives the same digest on every pod and + a changed, added, removed or renamed file changes it. Seeded rows record + it as ``metadata.build.bundleSha256``; ``bundle_changed`` compares against it. + """ + root = _local_bundle_root(app_id) + if not os.path.isdir(root): + return None + digest = hashlib.sha256() + for dirpath, dirs, files in os.walk(root): + dirs.sort() + for filename in sorted(files): + abs_path = os.path.join(dirpath, filename) + rel = os.path.relpath(abs_path, root).replace(os.sep, '/') + with open(abs_path, 'rb') as handle: + content = hashlib.sha256(handle.read()).digest() + digest.update(rel.encode('utf-8') + b'\0' + content) + return digest.hexdigest() + + # ============================================================================= # THE PRIMITIVE — mint one seed version + copy its bundle # ============================================================================= @@ -164,7 +198,7 @@ async def copy_bundle_to_store(app_id: str, artifact_path: str) -> int: from ai.account.deployment_backend import artifact_content_dir from ai.account.store import Store - local_root = os.path.join(os.path.dirname(sys.executable), 'static', 'apps', app_id) + local_root = _local_bundle_root(app_id) if not os.path.isdir(local_root): debug(f'[seed_apps] no local bundle at {local_root} — store copy skipped for {app_id} (rebuild the app)') return 0 @@ -217,6 +251,12 @@ async def seed_app(account: Any, org_id: str, entry: Dict[str, Any], actor: Dict # from version numbers everywhere, so recording apps.json's build-time # static path would only seed a dead field into every new row. manifest = {k: v for k, v in entry.items() if k != 'entry'} + # The digest of the bundle this version is copied from, so a later + # ``bundle_changed`` can tell whether the pod's build moved on since. + build: Dict[str, Any] = {'status': 'ok', 'seeded': True, 'endedAt': time.time()} + digest = bundle_digest(app_id) + if digest: + build['bundleSha256'] = digest registered = await account.deployments_publish( org_id, app_id, @@ -226,7 +266,7 @@ async def seed_app(account: Any, org_id: str, entry: Dict[str, Any], actor: Dict # build.status 'ok': the seed's dist/ is populated by the copy below # from an already-built static tree, so seeded versions pass the SAME # built gate server builds do (no special-casing anywhere downstream). - metadata={'manifest': manifest, 'build': {'status': 'ok', 'seeded': True, 'endedAt': time.time()}}, + metadata={'manifest': manifest, 'build': build}, state='ready', ) try: @@ -278,6 +318,39 @@ def _build_ok(entry: Dict[str, Any]) -> bool: return str(build.get('status') or '') == 'ok' +# ============================================================================= +# CHANGED-BUILD POLICY — for orchestrators that re-seed only what moved +# ============================================================================= + + +async def bundle_changed(account: Any, org_id: str, entry: Dict[str, Any]) -> bool: + """Whether this pod's built bundle differs from the one the app was last seeded with. + + The policy behind an orchestrator's changed-only re-seed: force an app + only when its build changed, so an unchanged app does not gain a version + on every deploy. Compares the local bundle digest with ``bundleSha256`` + on the newest SEED row; user deploys of the same id are not seeds and + are ignored. A seed row without a digest predates the field, so it + counts as changed once, and that re-seed records one. + + Returns False when there is no local bundle (nothing to seed from), no + rail rows (the plain seed handles a fresh app), or no seed rows (a user + deployed the id first, and it is left alone). + """ + app_id = str(entry['id']) + local = bundle_digest(app_id) + if local is None: + return False + rows = await account.deployments_versions(org_id, app_id) + # Rows are newest-first, so the first seed row is the latest seed. + seeds = [row for row in rows or [] if row.get('comment') == SEED_COMMENT] + if not seeds: + return False + metadata = seeds[0].get('metadata') if isinstance(seeds[0].get('metadata'), dict) else {} + build = metadata.get('build') if isinstance(metadata.get('build'), dict) else {} + return build.get('bundleSha256') != local + + # ============================================================================= # ONE ENTRY — presence check, self-heal, mint, bind # ============================================================================= @@ -357,6 +430,9 @@ async def seed_manifest_app( try: if await copy_bundle_to_store(app_id, str(row.get('artifactPath') or '')) > 0: stamp = {'status': 'ok', 'seeded': True, 'endedAt': time.time()} + digest = bundle_digest(app_id) + if digest: + stamp['bundleSha256'] = digest await account.deployments_set_build(org_id, app_id, int(row.get('version', 0)), stamp) row.setdefault('metadata', {})['build'] = stamp target = row diff --git a/packages/ai/tests/ai/account/test_seed_apps.py b/packages/ai/tests/ai/account/test_seed_apps.py new file mode 100644 index 0000000000..27da6ba97c --- /dev/null +++ b/packages/ai/tests/ai/account/test_seed_apps.py @@ -0,0 +1,204 @@ +# MIT License +# +# Copyright (c) 2026 Aparavi Software AG +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +"""The seeder's bundle digest and the changed-build policy built on it. + +A seeded version records the digest of the bundle it was copied from; +``bundle_changed`` compares the pod's bundle with the newest seed row's, so an +orchestrator can re-seed only the apps whose build moved. The local static +tree is a temp directory and the registry is a fake. +""" + +import pytest + +from ai.account import seed_apps +from ai.account.seed_apps import SEED_COMMENT, bundle_changed, bundle_digest, seed_app + +APP_ID = 'rocketride.home' +ENTRY = {'id': APP_ID, 'name': 'Home', 'version': '1.0.0', 'entry': '/apps/rocketride.home/remoteEntry.js'} + + +@pytest.fixture +def static_apps(tmp_path, monkeypatch): + """Point the seeder's local bundle root at a temp static/apps tree.""" + monkeypatch.setattr(seed_apps, '_local_bundle_root', lambda app_id: str(tmp_path / app_id)) + return tmp_path + + +def _write(root, files): + for rel, data in files.items(): + path = root / rel + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(data) + + +class _Registry: + """Just enough of the account for the seeder: rows newest-first, publish captured.""" + + def __init__(self, rows=None): + self.rows = list(rows or []) + self.published = [] + + async def deployments_versions(self, org_id, app_id): + return list(self.rows) + + async def deployments_publish(self, org_id, app_id, artifact, actor, *, comment, metadata, state): + self.published.append(metadata) + return { + 'version': len(self.rows) + 1, + 'artifactPath': f'.deployments/{app_id}/v1-abcdef12.json', + 'metadata': metadata, + } + + async def deployments_set_build(self, org_id, app_id, version, build): + return {} + + +def _seed_row(digest=None, comment=SEED_COMMENT): + build = {'status': 'ok', 'seeded': True} + if digest is not None: + build['bundleSha256'] = digest + return {'version': 1, 'comment': comment, 'state': 'ready', 'metadata': {'build': build}} + + +# ============================================================================= +# bundle_digest +# ============================================================================= + + +def test_no_local_bundle_has_no_digest(static_apps): + assert bundle_digest(APP_ID) is None + + +def test_the_same_files_give_the_same_digest_whatever_the_write_order(static_apps, tmp_path_factory, monkeypatch): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a', 'static/js/index.js': b'b'}) + first = bundle_digest(APP_ID) + + other = tmp_path_factory.mktemp('other') + _write(other / APP_ID, {'static/js/index.js': b'b', 'remoteEntry.js': b'a'}) + monkeypatch.setattr(seed_apps, '_local_bundle_root', lambda app_id: str(other / app_id)) + + assert bundle_digest(APP_ID) == first + + +@pytest.mark.parametrize( + 'files', + [ + {'remoteEntry.js': b'a', 'static/js/index.js': b'changed'}, + {'remoteEntry.js': b'a', 'static/js/index.js': b'b', 'static/js/new.js': b'c'}, + {'remoteEntry.js': b'a'}, + {'remoteEntry.js': b'a', 'static/js/renamed.js': b'b'}, + ], + ids=['content', 'added', 'removed', 'renamed'], +) +def test_any_file_change_changes_the_digest(static_apps, tmp_path_factory, monkeypatch, files): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a', 'static/js/index.js': b'b'}) + before = bundle_digest(APP_ID) + + other = tmp_path_factory.mktemp('other') + _write(other / APP_ID, files) + monkeypatch.setattr(seed_apps, '_local_bundle_root', lambda app_id: str(other / app_id)) + + assert bundle_digest(APP_ID) != before + + +# ============================================================================= +# seed_app records the digest +# ============================================================================= + + +@pytest.mark.asyncio +async def test_a_seeded_version_records_its_bundle_digest(static_apps, monkeypatch): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + + async def copied(app_id, artifact_path): + return 1 + + monkeypatch.setattr(seed_apps, 'copy_bundle_to_store', copied) + registry = _Registry() + + await seed_app(registry, 'org', ENTRY, seed_apps.SYSTEM_ACTOR) + + assert registry.published[0]['build']['bundleSha256'] == bundle_digest(APP_ID) + + +# ============================================================================= +# bundle_changed +# ============================================================================= + + +@pytest.mark.asyncio +async def test_an_unchanged_bundle_is_not_reseeded(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + registry = _Registry([_seed_row(bundle_digest(APP_ID))]) + + assert await bundle_changed(registry, 'org', ENTRY) is False + + +@pytest.mark.asyncio +async def test_a_changed_bundle_is_reseeded(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'new build'}) + registry = _Registry([_seed_row('0' * 64)]) + + assert await bundle_changed(registry, 'org', ENTRY) is True + + +@pytest.mark.asyncio +async def test_a_seed_row_from_before_the_digest_counts_as_changed(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + registry = _Registry([_seed_row()]) + + assert await bundle_changed(registry, 'org', ENTRY) is True + + +@pytest.mark.asyncio +async def test_only_the_newest_seed_row_counts_and_user_deploys_are_ignored(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + current = bundle_digest(APP_ID) + registry = _Registry( + [ + _seed_row(comment='deployed from the App Builder'), + _seed_row(current), + _seed_row('0' * 64), + ] + ) + + assert await bundle_changed(registry, 'org', ENTRY) is False + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + 'rows', + [[], [_seed_row(comment='deployed from the App Builder')]], + ids=['no rows', 'no seed rows'], +) +async def test_apps_without_a_seed_row_are_left_to_the_plain_seed(static_apps, rows): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + + assert await bundle_changed(_Registry(rows), 'org', ENTRY) is False + + +@pytest.mark.asyncio +async def test_without_a_local_bundle_there_is_nothing_to_reseed_from(static_apps): + registry = _Registry([_seed_row('0' * 64)]) + + assert await bundle_changed(registry, 'org', ENTRY) is False From 369155115a8b1a1a5a44f1ffd6bd23f8a854911b Mon Sep 17 00:00:00 2001 From: Dmitrii Karataev Date: Fri, 30 Oct 2026 13:13:49 -0700 Subject: [PATCH 2/4] fix(server): no seed digest for an empty or unreadable bundle; test the self-heal stamp From review: an empty static/apps// hashed to the empty-stream digest, so a changed-only seed saw it as changed and minted a failed version on every deploy. bundle_digest now returns None when the walk finds no file, and when a file can't be read, so the seed and the self-heal carry on without a digest instead of failing. Tests: the self-heal stamp records the digest, a failed newest seed counts as changed (so the next deploy retries it), and the empty and unreadable cases give None. The bundle_changed docstring names the failed-seed case. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015nTVr6jfSFYm1GppxbjghP --- packages/ai/src/ai/account/seed_apps.py | 33 +++++++---- .../ai/tests/ai/account/test_seed_apps.py | 59 ++++++++++++++++++- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/packages/ai/src/ai/account/seed_apps.py b/packages/ai/src/ai/account/seed_apps.py index b652e0ae9a..167034c4d0 100644 --- a/packages/ai/src/ai/account/seed_apps.py +++ b/packages/ai/src/ai/account/seed_apps.py @@ -134,20 +134,30 @@ def bundle_digest(app_id: str) -> Optional[str]: in sorted order, so the same build gives the same digest on every pod and a changed, added, removed or renamed file changes it. Seeded rows record it as ``metadata.build.bundleSha256``; ``bundle_changed`` compares against it. + + None means "no digest": no directory, an empty one (the copy would find no + files and fail the seed), or a file that can't be read. Callers then seed + without a digest rather than fail, which is how rows looked before the field. """ root = _local_bundle_root(app_id) if not os.path.isdir(root): return None digest = hashlib.sha256() - for dirpath, dirs, files in os.walk(root): - dirs.sort() - for filename in sorted(files): - abs_path = os.path.join(dirpath, filename) - rel = os.path.relpath(abs_path, root).replace(os.sep, '/') - with open(abs_path, 'rb') as handle: - content = hashlib.sha256(handle.read()).digest() - digest.update(rel.encode('utf-8') + b'\0' + content) - return digest.hexdigest() + found = False + try: + for dirpath, dirs, files in os.walk(root): + dirs.sort() + for filename in sorted(files): + abs_path = os.path.join(dirpath, filename) + rel = os.path.relpath(abs_path, root).replace(os.sep, '/') + with open(abs_path, 'rb') as handle: + content = hashlib.sha256(handle.read()).digest() + digest.update(rel.encode('utf-8') + b'\0' + content) + found = True + except OSError as exc: + debug(f'[seed_apps] {app_id}: bundle digest unavailable: {exc}') + return None + return digest.hexdigest() if found else None # ============================================================================= @@ -330,8 +340,9 @@ async def bundle_changed(account: Any, org_id: str, entry: Dict[str, Any]) -> bo only when its build changed, so an unchanged app does not gain a version on every deploy. Compares the local bundle digest with ``bundleSha256`` on the newest SEED row; user deploys of the same id are not seeds and - are ignored. A seed row without a digest predates the field, so it - counts as changed once, and that re-seed records one. + are ignored. A seed row without a digest counts as changed: either it + predates the field (one re-seed records a digest), or its build failed + and was stamped without one, so the next deploy retries the seed. Returns False when there is no local bundle (nothing to seed from), no rail rows (the plain seed handles a fresh app), or no seed rows (a user diff --git a/packages/ai/tests/ai/account/test_seed_apps.py b/packages/ai/tests/ai/account/test_seed_apps.py index 27da6ba97c..94f5e40b0c 100644 --- a/packages/ai/tests/ai/account/test_seed_apps.py +++ b/packages/ai/tests/ai/account/test_seed_apps.py @@ -31,7 +31,7 @@ import pytest from ai.account import seed_apps -from ai.account.seed_apps import SEED_COMMENT, bundle_changed, bundle_digest, seed_app +from ai.account.seed_apps import SEED_COMMENT, bundle_changed, bundle_digest, seed_app, seed_manifest_app APP_ID = 'rocketride.home' ENTRY = {'id': APP_ID, 'name': 'Home', 'version': '1.0.0', 'entry': '/apps/rocketride.home/remoteEntry.js'} @@ -57,6 +57,8 @@ class _Registry: def __init__(self, rows=None): self.rows = list(rows or []) self.published = [] + self.build_stamps = [] + self.bindings = [] async def deployments_versions(self, org_id, app_id): return list(self.rows) @@ -70,11 +72,19 @@ async def deployments_publish(self, org_id, app_id, artifact, actor, *, comment, } async def deployments_set_build(self, org_id, app_id, version, build): + self.build_stamps.append(build) return {} + async def publish_get(self, org_id, kind, app_id, audience): + return None -def _seed_row(digest=None, comment=SEED_COMMENT): - build = {'status': 'ok', 'seeded': True} + async def publish_set(self, org_id, kind, app_id, audience, version, snapshot, actor): + self.bindings.append(version) + return {} + + +def _seed_row(digest=None, comment=SEED_COMMENT, status='ok'): + build = {'status': status, 'seeded': True} if digest is not None: build['bundleSha256'] = digest return {'version': 1, 'comment': comment, 'state': 'ready', 'metadata': {'build': build}} @@ -89,6 +99,23 @@ def test_no_local_bundle_has_no_digest(static_apps): assert bundle_digest(APP_ID) is None +def test_an_empty_bundle_directory_has_no_digest(static_apps): + (static_apps / APP_ID / 'static').mkdir(parents=True) + + assert bundle_digest(APP_ID) is None + + +def test_an_unreadable_file_leaves_no_digest(static_apps, monkeypatch): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + + def unreadable(*args, **kwargs): + raise PermissionError('denied') + + monkeypatch.setattr(seed_apps, 'open', unreadable, raising=False) + + assert bundle_digest(APP_ID) is None + + def test_the_same_files_give_the_same_digest_whatever_the_write_order(static_apps, tmp_path_factory, monkeypatch): _write(static_apps / APP_ID, {'remoteEntry.js': b'a', 'static/js/index.js': b'b'}) first = bundle_digest(APP_ID) @@ -141,6 +168,24 @@ async def copied(app_id, artifact_path): assert registry.published[0]['build']['bundleSha256'] == bundle_digest(APP_ID) +@pytest.mark.asyncio +async def test_a_self_healed_seed_row_records_its_bundle_digest(static_apps, monkeypatch): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + + async def copied(app_id, artifact_path): + return 1 + + monkeypatch.setattr(seed_apps, 'copy_bundle_to_store', copied) + row = _seed_row(status='failed') + row['artifactPath'] = f'.deployments/{APP_ID}/v1-abcdef12.json' + registry = _Registry([row]) + + assert await seed_manifest_app(registry, 'org', ENTRY, seed_apps.SYSTEM_ACTOR) is True + assert registry.build_stamps[-1]['status'] == 'ok' + assert registry.build_stamps[-1]['bundleSha256'] == bundle_digest(APP_ID) + assert registry.bindings == [1] + + # ============================================================================= # bundle_changed # ============================================================================= @@ -170,6 +215,14 @@ async def test_a_seed_row_from_before_the_digest_counts_as_changed(static_apps): assert await bundle_changed(registry, 'org', ENTRY) is True +@pytest.mark.asyncio +async def test_a_failed_newest_seed_counts_as_changed_so_the_next_deploy_retries(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) + registry = _Registry([_seed_row(status='failed'), _seed_row(bundle_digest(APP_ID))]) + + assert await bundle_changed(registry, 'org', ENTRY) is True + + @pytest.mark.asyncio async def test_only_the_newest_seed_row_counts_and_user_deploys_are_ignored(static_apps): _write(static_apps / APP_ID, {'remoteEntry.js': b'a'}) From da18525a37e4259d53f2872c57352af854128547 Mon Sep 17 00:00:00 2001 From: Dmitrii Karataev Date: Fri, 30 Oct 2026 14:18:30 -0700 Subject: [PATCH 3/4] fix(seed): an unreadable bundle directory leaves no digest os.walk skips a directory it can't list unless it's given an error handler, so bundle_digest returned a digest over the readable files only. An onerror handler now raises, and the existing OSError branch returns None like it does for an unreadable file. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015nTVr6jfSFYm1GppxbjghP --- packages/ai/src/ai/account/seed_apps.py | 13 ++++++++++--- packages/ai/tests/ai/account/test_seed_apps.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/ai/src/ai/account/seed_apps.py b/packages/ai/src/ai/account/seed_apps.py index 167034c4d0..b8909e5c19 100644 --- a/packages/ai/src/ai/account/seed_apps.py +++ b/packages/ai/src/ai/account/seed_apps.py @@ -136,16 +136,23 @@ def bundle_digest(app_id: str) -> Optional[str]: it as ``metadata.build.bundleSha256``; ``bundle_changed`` compares against it. None means "no digest": no directory, an empty one (the copy would find no - files and fail the seed), or a file that can't be read. Callers then seed - without a digest rather than fail, which is how rows looked before the field. + files and fail the seed), or a file or directory that can't be read. Callers + then seed without a digest rather than fail, which is how rows looked before + the field. """ root = _local_bundle_root(app_id) if not os.path.isdir(root): return None digest = hashlib.sha256() found = False + + def unreadable_dir(exc: OSError) -> None: + # os.walk skips a directory it can't list unless told otherwise, which + # would digest only the readable part of the bundle. + raise exc + try: - for dirpath, dirs, files in os.walk(root): + for dirpath, dirs, files in os.walk(root, onerror=unreadable_dir): dirs.sort() for filename in sorted(files): abs_path = os.path.join(dirpath, filename) diff --git a/packages/ai/tests/ai/account/test_seed_apps.py b/packages/ai/tests/ai/account/test_seed_apps.py index 94f5e40b0c..2dffb3e3c4 100644 --- a/packages/ai/tests/ai/account/test_seed_apps.py +++ b/packages/ai/tests/ai/account/test_seed_apps.py @@ -28,6 +28,8 @@ tree is a temp directory and the registry is a fake. """ +import os + import pytest from ai.account import seed_apps @@ -116,6 +118,21 @@ def unreadable(*args, **kwargs): assert bundle_digest(APP_ID) is None +def test_an_unreadable_directory_leaves_no_digest(static_apps, monkeypatch): + _write(static_apps / APP_ID, {'remoteEntry.js': b'a', 'static/js/index.js': b'b'}) + locked = str(static_apps / APP_ID / 'static') + real_scandir = os.scandir + + def scandir(path='.'): + if os.fspath(path) == locked: + raise PermissionError('denied') + return real_scandir(path) + + monkeypatch.setattr(os, 'scandir', scandir) + + assert bundle_digest(APP_ID) is None + + def test_the_same_files_give_the_same_digest_whatever_the_write_order(static_apps, tmp_path_factory, monkeypatch): _write(static_apps / APP_ID, {'remoteEntry.js': b'a', 'static/js/index.js': b'b'}) first = bundle_digest(APP_ID) From c1830169c4d8d45def1ee9f4c9c61dbf7d011cbd Mon Sep 17 00:00:00 2001 From: Dmitrii Karataev Date: Fri, 30 Oct 2026 20:31:37 -0700 Subject: [PATCH 4/4] fix(seed): a release never replaces a live direct deploy bundle_changed compared the pod's bundle with the newest seed row only, so a release with a new build of an app would force a re-seed and move the public audience off a version someone deployed directly. Joe wants to ship home-ui changes that way, without a backend release. When the public audience serves a version that isn't a seed, bundle_changed now returns False and the release leaves the app alone. A direct deploy that isn't live yet doesn't block the re-seed, and a manual --reseed still overrides either way. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015nTVr6jfSFYm1GppxbjghP --- CHANGELOG.md | 2 +- packages/ai/src/ai/account/seed_apps.py | 12 +++++-- .../ai/tests/ai/account/test_seed_apps.py | 31 ++++++++++++++++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f12474da2..c27f163960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] — since 2026-10-16 ### Added -- **server**: a seeded app version records the sha256 of the bundle it was copied from (`metadata.build.bundleSha256`), and `bundle_changed()` tells an orchestrator whether the pod's build differs from the app's newest seed, so a deploy can re-seed only the apps whose build changed +- **server**: a seeded app version records the sha256 of the bundle it was copied from (`metadata.build.bundleSha256`), and `bundle_changed()` tells an orchestrator whether the pod's build differs from the app's newest seed, so a deploy can re-seed only the apps whose build changed. An app whose public version is a direct deploy, not a seed, counts as unchanged, so a release never replaces it - **typescript**: add `SignupProperties`, `PkceCredential` and `normalizeSignupProperties` for optional validated signup attribution resolved immediately before PKCE authentication; credentials without context retain their existing bytes (#2890). - **shell**: freeze additive API v8 with consent-gated `signupProperties` in `startOAuth` and `shell:loginRequest`, kept only in the PKCE credential and out of native telemetry facts; recheck privacy signals, consent and expiry after redirects and before authentication (#2890). - **nodes**: the vector-store tools gain `soft_delete` and `restore` on all nine store nodes (`rocketride_vector`, `store_astra`, `store_atlas`, `store_chroma`, `store_milvus`, `store_pinecone`, `store_postgres`, `store_qdrant`, `store_weaviate`): they move documents to the trash and back over the drivers' existing soft-delete support, are offered beside `upsert` and `delete` only while writes through tools are allowed, and report `matched_chunks` where the store counts the rows it marks (the two Postgres stores and Chroma). `rocketride_vector` and `store_postgres` also offer `list_documents` (one entry per document with its parent path and chunk count, paged and ordered by object ID, active documents or the trash) and report `document_count` in `stats`; both come from an optional driver capability (`DocumentStoreBase.listDocuments`, `countDocuments`, `supports_document_listing`) any other driver can adopt (#2587) diff --git a/packages/ai/src/ai/account/seed_apps.py b/packages/ai/src/ai/account/seed_apps.py index b8909e5c19..c9b82cef00 100644 --- a/packages/ai/src/ai/account/seed_apps.py +++ b/packages/ai/src/ai/account/seed_apps.py @@ -352,8 +352,10 @@ async def bundle_changed(account: Any, org_id: str, entry: Dict[str, Any]) -> bo and was stamped without one, so the next deploy retries the seed. Returns False when there is no local bundle (nothing to seed from), no - rail rows (the plain seed handles a fresh app), or no seed rows (a user - deployed the id first, and it is left alone). + rail rows (the plain seed handles a fresh app), no seed rows (a user + deployed the id first, and it is left alone), or when the public audience + serves a direct deploy rather than a seed: a release must not replace what + someone deployed on purpose. A manual ``--reseed`` still does. """ app_id = str(entry['id']) local = bundle_digest(app_id) @@ -364,6 +366,12 @@ async def bundle_changed(account: Any, org_id: str, entry: Dict[str, Any]) -> bo seeds = [row for row in rows or [] if row.get('comment') == SEED_COMMENT] if not seeds: return False + public = await account.publish_get(org_id, 'app', app_id, PUBLIC_AUDIENCE) + if public is not None: + bound = int(public.get('version', 0)) + live = next((row for row in rows if int(row.get('version', 0)) == bound), None) + if live is not None and live.get('comment') != SEED_COMMENT: + return False metadata = seeds[0].get('metadata') if isinstance(seeds[0].get('metadata'), dict) else {} build = metadata.get('build') if isinstance(metadata.get('build'), dict) else {} return build.get('bundleSha256') != local diff --git a/packages/ai/tests/ai/account/test_seed_apps.py b/packages/ai/tests/ai/account/test_seed_apps.py index 2dffb3e3c4..0607aaf854 100644 --- a/packages/ai/tests/ai/account/test_seed_apps.py +++ b/packages/ai/tests/ai/account/test_seed_apps.py @@ -56,8 +56,9 @@ def _write(root, files): class _Registry: """Just enough of the account for the seeder: rows newest-first, publish captured.""" - def __init__(self, rows=None): + def __init__(self, rows=None, public=None): self.rows = list(rows or []) + self.public = public self.published = [] self.build_stamps = [] self.bindings = [] @@ -78,18 +79,18 @@ async def deployments_set_build(self, org_id, app_id, version, build): return {} async def publish_get(self, org_id, kind, app_id, audience): - return None + return None if self.public is None else {'version': self.public, 'state': 'enabled'} async def publish_set(self, org_id, kind, app_id, audience, version, snapshot, actor): self.bindings.append(version) return {} -def _seed_row(digest=None, comment=SEED_COMMENT, status='ok'): +def _seed_row(digest=None, comment=SEED_COMMENT, status='ok', version=1): build = {'status': status, 'seeded': True} if digest is not None: build['bundleSha256'] = digest - return {'version': 1, 'comment': comment, 'state': 'ready', 'metadata': {'build': build}} + return {'version': version, 'comment': comment, 'state': 'ready', 'metadata': {'build': build}} # ============================================================================= @@ -255,6 +256,28 @@ async def test_only_the_newest_seed_row_counts_and_user_deploys_are_ignored(stat assert await bundle_changed(registry, 'org', ENTRY) is False +@pytest.mark.asyncio +async def test_a_live_direct_deploy_is_not_replaced_by_a_changed_bundle(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'new build'}) + registry = _Registry( + [_seed_row(comment='deployed with rocketride app deploy', version=2), _seed_row('0' * 64, version=1)], + public=2, + ) + + assert await bundle_changed(registry, 'org', ENTRY) is False + + +@pytest.mark.asyncio +async def test_a_newer_direct_deploy_that_is_not_live_does_not_block_the_reseed(static_apps): + _write(static_apps / APP_ID, {'remoteEntry.js': b'new build'}) + registry = _Registry( + [_seed_row(comment='deployed with rocketride app deploy', version=2), _seed_row('0' * 64, version=1)], + public=1, + ) + + assert await bundle_changed(registry, 'org', ENTRY) is True + + @pytest.mark.asyncio @pytest.mark.parametrize( 'rows',