Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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)
Expand Down
106 changes: 104 additions & 2 deletions packages/ai/src/ai/account/seed_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

"""Edition-neutral seeding of the fixed platform apps from apps.json."""

import hashlib
import json
import os
import sys
Expand Down Expand Up @@ -116,6 +117,56 @@ 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: ``<engine_dir>/static/apps/<app_id>/``."""
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.

None means "no digest": no directory, an empty one (the copy would find no
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, onerror=unreadable_dir):
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)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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


# =============================================================================
# THE PRIMITIVE — mint one seed version + copy its bundle
# =============================================================================
Expand Down Expand Up @@ -164,7 +215,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
Expand Down Expand Up @@ -217,6 +268,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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
registered = await account.deployments_publish(
org_id,
app_id,
Expand All @@ -226,7 +283,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:
Expand Down Expand Up @@ -278,6 +335,48 @@ 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 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), 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)
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
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:
Comment thread
dk-rocketride marked this conversation as resolved.
Resolved
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
# =============================================================================
Expand Down Expand Up @@ -357,6 +456,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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
await account.deployments_set_build(org_id, app_id, int(row.get('version', 0)), stamp)
row.setdefault('metadata', {})['build'] = stamp
target = row
Expand Down
Loading