Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_customers.py +5 -1
- api/routes_odoo_tables.py +152 -4
- api/worker_provenance.py +113 -5
- platform/harness/datastore.py +63 -0
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "5eef1d5336f",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
5eef1d5336f
|
api/routes_customers.py
CHANGED
|
@@ -29,7 +29,7 @@ import os
|
|
| 29 |
import threading
|
| 30 |
import time
|
| 31 |
|
| 32 |
-
from fastapi import APIRouter, Body, Depends, Response
|
| 33 |
|
| 34 |
import scope_cache
|
| 35 |
from deps import Session, err, module_gate, require_session
|
|
@@ -524,6 +524,8 @@ class _AssemblyStore:
|
|
| 524 |
self.cacheable = False
|
| 525 |
if os.environ.get("AIOS_HEAVY_PROFILE") == "1":
|
| 526 |
print(f"[assembly-miss] revision unreadable for {name}: {exc}", flush=True)
|
|
|
|
|
|
|
| 527 |
except Exception as exc:
|
| 528 |
if self.schema_only:
|
| 529 |
from core.request_timing import raise_if_resource_error
|
|
@@ -535,6 +537,8 @@ class _AssemblyStore:
|
|
| 535 |
if fresh or (not self.cacheable and not self.schema_only) or key not in self.docs:
|
| 536 |
try:
|
| 537 |
self.docs[key] = read()
|
|
|
|
|
|
|
| 538 |
except Exception as exc:
|
| 539 |
if self.schema_only:
|
| 540 |
from core.request_timing import raise_if_resource_error
|
|
|
|
| 29 |
import threading
|
| 30 |
import time
|
| 31 |
|
| 32 |
+
from fastapi import APIRouter, Body, Depends, HTTPException, Response
|
| 33 |
|
| 34 |
import scope_cache
|
| 35 |
from deps import Session, err, module_gate, require_session
|
|
|
|
| 524 |
self.cacheable = False
|
| 525 |
if os.environ.get("AIOS_HEAVY_PROFILE") == "1":
|
| 526 |
print(f"[assembly-miss] revision unreadable for {name}: {exc}", flush=True)
|
| 527 |
+
except HTTPException:
|
| 528 |
+
raise
|
| 529 |
except Exception as exc:
|
| 530 |
if self.schema_only:
|
| 531 |
from core.request_timing import raise_if_resource_error
|
|
|
|
| 537 |
if fresh or (not self.cacheable and not self.schema_only) or key not in self.docs:
|
| 538 |
try:
|
| 539 |
self.docs[key] = read()
|
| 540 |
+
except HTTPException:
|
| 541 |
+
raise
|
| 542 |
except Exception as exc:
|
| 543 |
if self.schema_only:
|
| 544 |
from core.request_timing import raise_if_resource_error
|
api/routes_odoo_tables.py
CHANGED
|
@@ -4416,6 +4416,7 @@ def _materialised_read(table_key, session, query, related, ids=None, *, payload=
|
|
| 4416 |
with connection as cur:
|
| 4417 |
if compiled and sql_page and not related:
|
| 4418 |
mirror_revision = _mirror_page_revision(cur, source_generation)
|
|
|
|
| 4419 |
with registry_source.canonical_selection(session, cur, table_key, metadata, needed, ids=ids) as spec:
|
| 4420 |
if spec is not None:
|
| 4421 |
cols = _filter_columns(dict(spec, cols={k: v for k, v in spec['cols'].items()
|
|
@@ -4441,7 +4442,11 @@ def _materialised_read(table_key, session, query, related, ids=None, *, payload=
|
|
| 4441 |
'source_count': cur.execute(f'SELECT count(*) FROM "{spec["table"]}"').fetchone()[0],
|
| 4442 |
'streamed': True, 'selection': True}
|
| 4443 |
registry_source.require_generation(session, table_key, source_generation)
|
| 4444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4445 |
raise err(409, 'window_population_changed', 'These records changed while loading. Reload this database.')
|
| 4446 |
return
|
| 4447 |
cur.execute("CREATE TEMP TABLE pinned_rows (_row_index BIGINT, payload JSON)")
|
|
@@ -4639,6 +4644,137 @@ def _mirror_page_revision(cur, page_rev):
|
|
| 4639 |
datastore.mirror_writes(cur), page_rev]
|
| 4640 |
|
| 4641 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4642 |
def _window_principal(session):
|
| 4643 |
"""Bind pagination to identity and permissions without volatile activity stamps."""
|
| 4644 |
import registry_source
|
|
@@ -4822,9 +4958,16 @@ def _materialised_window_read(table_key, session, offset, limit, filters, filter
|
|
| 4822 |
by_index = {int(index): int(value) for index, value in values}
|
| 4823 |
page_ids = [by_index[index] for index in indexes]
|
| 4824 |
if table_key in {'customer_data', 'product_data'}:
|
|
|
|
|
|
|
| 4825 |
payload = registry_source.canonical_page(session, read['cur'], table_key, page_ids, related=related)
|
| 4826 |
-
if read.get('selection')
|
| 4827 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4828 |
else:
|
| 4829 |
payload = registry_source.stored_page(session, table_key, page_ids, related=related)
|
| 4830 |
rows = payload['rows']
|
|
@@ -4975,13 +5118,18 @@ def odoo_table_rows(table_key: str,
|
|
| 4975 |
|
| 4976 |
select = ", ".join(f'{expr} AS "{key}"' for key, (expr, _c) in spec["cols"].items())
|
| 4977 |
revision = _mirror_page_revision(cur, page_rev)
|
|
|
|
| 4978 |
question = _window_query(table_key, filters, filterConj, sorts, search, related,
|
| 4979 |
groupBy, groupKey, ids, revision=revision)
|
| 4980 |
win = _window_page(session, question, cursor, select=f'{spec["id"]} AS "_pid", {select}',
|
| 4981 |
where=where, params=tuple(params), order_by=order,
|
| 4982 |
offset=offset, limit=(limit or None), cur=cur, page_first=True,
|
| 4983 |
page_key=spec.get("page_key") or spec['id'], **frm)
|
| 4984 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4985 |
raise err(409, 'window_population_changed', 'These records changed while loading. Reload this database.')
|
| 4986 |
if win["clamped"]:
|
| 4987 |
limits.append({
|
|
|
|
| 4416 |
with connection as cur:
|
| 4417 |
if compiled and sql_page and not related:
|
| 4418 |
mirror_revision = _mirror_page_revision(cur, source_generation)
|
| 4419 |
+
mirror_version = _mirror_diagnostic_version(cur, mirror_revision)
|
| 4420 |
with registry_source.canonical_selection(session, cur, table_key, metadata, needed, ids=ids) as spec:
|
| 4421 |
if spec is not None:
|
| 4422 |
cols = _filter_columns(dict(spec, cols={k: v for k, v in spec['cols'].items()
|
|
|
|
| 4442 |
'source_count': cur.execute(f'SELECT count(*) FROM "{spec["table"]}"').fetchone()[0],
|
| 4443 |
'streamed': True, 'selection': True}
|
| 4444 |
registry_source.require_generation(session, table_key, source_generation)
|
| 4445 |
+
mirror_after = _mirror_page_revision(cur, source_generation)
|
| 4446 |
+
mirror_version_after = _mirror_diagnostic_version(cur, mirror_after)
|
| 4447 |
+
if mirror_revision != mirror_after:
|
| 4448 |
+
_window_population_diagnostic('materialised_selection', table_key, cur,
|
| 4449 |
+
mirror_revision, mirror_after, mirror_version, mirror_version_after)
|
| 4450 |
raise err(409, 'window_population_changed', 'These records changed while loading. Reload this database.')
|
| 4451 |
return
|
| 4452 |
cur.execute("CREATE TEMP TABLE pinned_rows (_row_index BIGINT, payload JSON)")
|
|
|
|
| 4644 |
datastore.mirror_writes(cur), page_rev]
|
| 4645 |
|
| 4646 |
|
| 4647 |
+
def _mirror_diagnostic_version(cur, revision=None):
|
| 4648 |
+
"""Observe captured marks or this cursor's physical file without following a serving pointer."""
|
| 4649 |
+
try:
|
| 4650 |
+
import re
|
| 4651 |
+
from pathlib import Path
|
| 4652 |
+
from harness import datastore
|
| 4653 |
+
if revision is None:
|
| 4654 |
+
if not isinstance(cur, datastore._TimedCursor):
|
| 4655 |
+
return None
|
| 4656 |
+
raw = cur._cursor
|
| 4657 |
+
if not isinstance(raw, datastore.duckdb.DuckDBPyConnection):
|
| 4658 |
+
return None
|
| 4659 |
+
observed = raw.cursor()
|
| 4660 |
+
try:
|
| 4661 |
+
row = observed.execute("SELECT path FROM duckdb_databases() "
|
| 4662 |
+
"WHERE database_name = current_database()").fetchone()
|
| 4663 |
+
finally:
|
| 4664 |
+
observed.close()
|
| 4665 |
+
if not row or not row[0] or row[0] == ':memory:':
|
| 4666 |
+
return None
|
| 4667 |
+
actual = Path(row[0]).resolve()
|
| 4668 |
+
else:
|
| 4669 |
+
if revision[0] is None:
|
| 4670 |
+
return None
|
| 4671 |
+
actual = Path(revision[0][0])
|
| 4672 |
+
handle = getattr(cur, '_mirror_handle', None)
|
| 4673 |
+
base = handle.path if handle is not None else datastore.DB_PATH.resolve()
|
| 4674 |
+
if actual == base:
|
| 4675 |
+
return 0
|
| 4676 |
+
match = re.fullmatch(re.escape(base.stem) + r'\.v(\d+)' + re.escape(base.suffix), actual.name)
|
| 4677 |
+
return int(match[1]) if actual.parent == base.parent and match else None
|
| 4678 |
+
except BaseException:
|
| 4679 |
+
return None
|
| 4680 |
+
|
| 4681 |
+
|
| 4682 |
+
def _window_diagnostic_hash(value):
|
| 4683 |
+
"""Hash bounded comparison operands without formatting their values in a log."""
|
| 4684 |
+
digest, budget = hashlib.sha256(), [4096, 65536]
|
| 4685 |
+
|
| 4686 |
+
def feed(part, depth=0):
|
| 4687 |
+
budget[0] -= 1
|
| 4688 |
+
if budget[0] < 0 or depth > 12:
|
| 4689 |
+
raise ValueError('diagnostic hash bound')
|
| 4690 |
+
if part is None:
|
| 4691 |
+
digest.update(b'n')
|
| 4692 |
+
elif type(part) in (str, int, float, bool):
|
| 4693 |
+
if type(part) is str and len(part) > 4096:
|
| 4694 |
+
raise ValueError('diagnostic hash bound')
|
| 4695 |
+
raw = str(part).encode('utf-8')
|
| 4696 |
+
if len(raw) > 4096 or len(raw) > budget[1]:
|
| 4697 |
+
raise ValueError('diagnostic hash bound')
|
| 4698 |
+
budget[1] -= len(raw)
|
| 4699 |
+
digest.update(type(part).__name__.encode() + b':' + str(len(raw)).encode() + b':' + raw)
|
| 4700 |
+
elif type(part) in (list, tuple):
|
| 4701 |
+
if len(part) > budget[0]:
|
| 4702 |
+
raise ValueError('diagnostic hash bound')
|
| 4703 |
+
digest.update(type(part).__name__.encode() + b'[')
|
| 4704 |
+
for item in part:
|
| 4705 |
+
feed(item, depth + 1)
|
| 4706 |
+
digest.update(b']')
|
| 4707 |
+
elif type(part) is dict:
|
| 4708 |
+
if len(part) > budget[0] or not all(type(key) is str for key in part):
|
| 4709 |
+
raise ValueError('diagnostic hash bound')
|
| 4710 |
+
digest.update(b'{')
|
| 4711 |
+
for key in sorted(part):
|
| 4712 |
+
feed(key, depth + 1)
|
| 4713 |
+
feed(part[key], depth + 1)
|
| 4714 |
+
digest.update(b'}')
|
| 4715 |
+
else:
|
| 4716 |
+
raise ValueError('diagnostic hash unavailable')
|
| 4717 |
+
try:
|
| 4718 |
+
feed(value)
|
| 4719 |
+
return digest.hexdigest()
|
| 4720 |
+
except Exception:
|
| 4721 |
+
return None
|
| 4722 |
+
|
| 4723 |
+
|
| 4724 |
+
_WINDOW_DIAGNOSTIC_BYTES = 65536
|
| 4725 |
+
|
| 4726 |
+
|
| 4727 |
+
def _window_population_diagnostic(site, table_key, cur, before, after,
|
| 4728 |
+
version_before, version_after, *, kind='mirror_revision'):
|
| 4729 |
+
"""Emit one bounded value-free observation without changing the original refusal."""
|
| 4730 |
+
try:
|
| 4731 |
+
import logging
|
| 4732 |
+
import os
|
| 4733 |
+
import re
|
| 4734 |
+
from harness import datastore
|
| 4735 |
+
|
| 4736 |
+
def component(left, right):
|
| 4737 |
+
return {'changed': left != right, 'before_hash': _window_diagnostic_hash(left),
|
| 4738 |
+
'after_hash': _window_diagnostic_hash(right)}
|
| 4739 |
+
|
| 4740 |
+
components = {}
|
| 4741 |
+
evidence = {'status': 'unavailable', 'complete': False, 'events': []}
|
| 4742 |
+
if kind == 'mirror_revision':
|
| 4743 |
+
for index, name in enumerate(('file_marks', 'generation', 'source_writes', 'page_revision')):
|
| 4744 |
+
components[name] = component(before[index], after[index])
|
| 4745 |
+
if type(before[2]) is int and type(after[2]) is int:
|
| 4746 |
+
components['source_writes'].update(before=before[2], after=after[2],
|
| 4747 |
+
delta=after[2] - before[2])
|
| 4748 |
+
evidence = datastore.mirror_write_evidence(cur, before[2], after[2])
|
| 4749 |
+
for index, name in enumerate(('file', 'wal')):
|
| 4750 |
+
left = before[0][1][index] if before[0] is not None else None
|
| 4751 |
+
right = after[0][1][index] if after[0] is not None else None
|
| 4752 |
+
components[name] = component(left, right)
|
| 4753 |
+
left, right = before[1][-1], after[1][-1]
|
| 4754 |
+
if type(left) is int and type(right) is int:
|
| 4755 |
+
components['generation']['install_delta'] = right - left
|
| 4756 |
+
else:
|
| 4757 |
+
components['row_identity'] = dict(component(before, after),
|
| 4758 |
+
before_count=len(before), after_count=len(after))
|
| 4759 |
+
# The timing accumulator carries no request identity. Do not invent one from object identity.
|
| 4760 |
+
record = {'event': 'window_population_changed', 'site': site, 'kind': kind,
|
| 4761 |
+
'table': table_key if type(table_key) is str and re.fullmatch(r'[a-z][a-z0-9_]{0,63}', table_key)
|
| 4762 |
+
else _window_diagnostic_hash(table_key),
|
| 4763 |
+
'pid': os.getpid(), 'thread': threading.get_ident(),
|
| 4764 |
+
'version_before': version_before, 'version_after': version_after,
|
| 4765 |
+
'before_hash': _window_diagnostic_hash(before), 'after_hash': _window_diagnostic_hash(after),
|
| 4766 |
+
'components': components, 'counter_evidence': evidence,
|
| 4767 |
+
'attribution': 'unproven', 'scope': 'process_local_accounting'}
|
| 4768 |
+
encoded = json.dumps(record, separators=(',', ':'), ensure_ascii=True)
|
| 4769 |
+
if len(encoded.encode('utf-8')) > _WINDOW_DIAGNOSTIC_BYTES:
|
| 4770 |
+
record['counter_evidence'] = {'status': 'overflow', 'complete': False, 'events': []}
|
| 4771 |
+
encoded = json.dumps(record, separators=(',', ':'), ensure_ascii=True)
|
| 4772 |
+
if len(encoded.encode('utf-8')) <= _WINDOW_DIAGNOSTIC_BYTES:
|
| 4773 |
+
logging.getLogger('aios.window_population').warning('%s', encoded)
|
| 4774 |
+
except BaseException:
|
| 4775 |
+
pass
|
| 4776 |
+
|
| 4777 |
+
|
| 4778 |
def _window_principal(session):
|
| 4779 |
"""Bind pagination to identity and permissions without volatile activity stamps."""
|
| 4780 |
import registry_source
|
|
|
|
| 4958 |
by_index = {int(index): int(value) for index, value in values}
|
| 4959 |
page_ids = [by_index[index] for index in indexes]
|
| 4960 |
if table_key in {'customer_data', 'product_data'}:
|
| 4961 |
+
page_version = (_mirror_diagnostic_version(read['cur'], revision)
|
| 4962 |
+
if read.get('selection') else None)
|
| 4963 |
payload = registry_source.canonical_page(session, read['cur'], table_key, page_ids, related=related)
|
| 4964 |
+
if read.get('selection'):
|
| 4965 |
+
actual_page_ids = [int(row['pid']) for row in payload['rows']]
|
| 4966 |
+
if actual_page_ids != page_ids:
|
| 4967 |
+
_window_population_diagnostic('canonical_page_ids', table_key, read['cur'],
|
| 4968 |
+
page_ids, actual_page_ids, page_version, _mirror_diagnostic_version(read['cur']),
|
| 4969 |
+
kind='row_identity')
|
| 4970 |
+
raise err(409, 'window_population_changed', 'These records changed while loading. Reload this database.')
|
| 4971 |
else:
|
| 4972 |
payload = registry_source.stored_page(session, table_key, page_ids, related=related)
|
| 4973 |
rows = payload['rows']
|
|
|
|
| 5118 |
|
| 5119 |
select = ", ".join(f'{expr} AS "{key}"' for key, (expr, _c) in spec["cols"].items())
|
| 5120 |
revision = _mirror_page_revision(cur, page_rev)
|
| 5121 |
+
revision_version = _mirror_diagnostic_version(cur, revision)
|
| 5122 |
question = _window_query(table_key, filters, filterConj, sorts, search, related,
|
| 5123 |
groupBy, groupKey, ids, revision=revision)
|
| 5124 |
win = _window_page(session, question, cursor, select=f'{spec["id"]} AS "_pid", {select}',
|
| 5125 |
where=where, params=tuple(params), order_by=order,
|
| 5126 |
offset=offset, limit=(limit or None), cur=cur, page_first=True,
|
| 5127 |
page_key=spec.get("page_key") or spec['id'], **frm)
|
| 5128 |
+
revision_after = _mirror_page_revision(cur, page_rev)
|
| 5129 |
+
revision_version_after = _mirror_diagnostic_version(cur, revision_after)
|
| 5130 |
+
if revision != revision_after:
|
| 5131 |
+
_window_population_diagnostic('compiled_window', table_key, cur,
|
| 5132 |
+
revision, revision_after, revision_version, revision_version_after)
|
| 5133 |
raise err(409, 'window_population_changed', 'These records changed while loading. Reload this database.')
|
| 5134 |
if win["clamped"]:
|
| 5135 |
limits.append({
|
api/worker_provenance.py
CHANGED
|
@@ -6,11 +6,13 @@ import contextlib
|
|
| 6 |
import dataclasses
|
| 7 |
import inspect
|
| 8 |
import json
|
|
|
|
| 9 |
import os
|
| 10 |
from pathlib import Path
|
| 11 |
import re
|
| 12 |
import stat
|
| 13 |
import sys
|
|
|
|
| 14 |
import time
|
| 15 |
from types import CodeType, FunctionType, ModuleType
|
| 16 |
|
|
@@ -29,6 +31,79 @@ _BOOT_SOURCE = None
|
|
| 29 |
_BOOT_FILES = {}
|
| 30 |
_BOOT_CODES = {}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def encoded(value):
|
| 34 |
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False,
|
|
@@ -267,12 +342,14 @@ def boot_source():
|
|
| 267 |
"""Pin installed bytes once before worker services start, including an unproven boot."""
|
| 268 |
global _BOOT_SOURCE, _BOOT_FILES, _BOOT_CODES
|
| 269 |
if _BOOT_SOURCE is None:
|
|
|
|
| 270 |
try:
|
| 271 |
path = Path(__file__)
|
| 272 |
if path.is_symlink() or path.parent.is_symlink():
|
| 273 |
raise ValueError("worker_source_symlink")
|
| 274 |
version, _BOOT_FILES, total = source_files()
|
| 275 |
_BOOT_CODES = {}
|
|
|
|
| 276 |
started, code_count = time.monotonic(), 0
|
| 277 |
for relative, digest in _BOOT_FILES.items():
|
| 278 |
if not relative.endswith(".py"):
|
|
@@ -289,10 +366,17 @@ def boot_source():
|
|
| 289 |
codes.add(code_identity(code))
|
| 290 |
pending.extend(value for value in code.co_consts if isinstance(value, CodeType))
|
| 291 |
_BOOT_CODES[relative] = codes
|
|
|
|
| 292 |
loaded_origins()
|
|
|
|
| 293 |
_BOOT_SOURCE = version, source_summary(_BOOT_FILES, total)
|
| 294 |
-
except Exception:
|
| 295 |
_BOOT_SOURCE = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
return _BOOT_SOURCE
|
| 297 |
|
| 298 |
|
|
@@ -339,6 +423,7 @@ def store_identity(rt):
|
|
| 339 |
|
| 340 |
def evidence(rt):
|
| 341 |
"""Return fresh bounded evidence or None without affecting worker health."""
|
|
|
|
| 342 |
try:
|
| 343 |
import process_role
|
| 344 |
from core import data_binding
|
|
@@ -352,20 +437,31 @@ def evidence(rt):
|
|
| 352 |
or (os.environ.get("RI_DIR") and Path(os.environ["RI_DIR"]).resolve() != (ROOT / "platform").resolve())
|
| 353 |
or (dataset and not re.fullmatch(r"[A-Za-z0-9_-]+/[A-Za-z0-9_.-]+", dataset))
|
| 354 |
or os.environ.get("AIOS_SYNC_JOB_MODE") != "resident"):
|
|
|
|
| 355 |
return None
|
|
|
|
| 356 |
boot = boot_source()
|
| 357 |
if not boot:
|
|
|
|
| 358 |
return None
|
|
|
|
| 359 |
current = installed_source()
|
| 360 |
if current != boot:
|
|
|
|
| 361 |
return None
|
| 362 |
version, source = current
|
|
|
|
| 363 |
loaded_origins()
|
|
|
|
| 364 |
store = store_identity(rt)
|
|
|
|
| 365 |
loaded_origins()
|
|
|
|
| 366 |
if installed_source() != boot:
|
|
|
|
| 367 |
return None
|
| 368 |
-
|
|
|
|
| 369 |
"tenant": tenant, "version": version, "source": source, "store": store,
|
| 370 |
"role": process_role.role(), "scope": process_role.worker_scope(),
|
| 371 |
"deployment": data_binding.deployment_id(), "mode": "resident",
|
|
@@ -376,7 +472,10 @@ def evidence(rt):
|
|
| 376 |
"executableOverride": any((os.environ.get("ENV"), os.environ.get("BASH_ENV"),
|
| 377 |
os.environ.get("PYTHONPATH"), os.environ.get("PYTHONHOME"),
|
| 378 |
os.environ.get("LD_PRELOAD"), os.environ.get("LD_LIBRARY_PATH")))}})
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
| 380 |
return None
|
| 381 |
|
| 382 |
|
|
@@ -405,11 +504,20 @@ def desk_companion(rt, capture, raw, before):
|
|
| 405 |
|
| 406 |
|
| 407 |
def heartbeat_attestation(rt, beat):
|
|
|
|
| 408 |
try:
|
| 409 |
value = evidence(rt)
|
|
|
|
| 410 |
bounded(beat)
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
return None
|
| 414 |
|
| 415 |
|
|
|
|
| 6 |
import dataclasses
|
| 7 |
import inspect
|
| 8 |
import json
|
| 9 |
+
import math
|
| 10 |
import os
|
| 11 |
from pathlib import Path
|
| 12 |
import re
|
| 13 |
import stat
|
| 14 |
import sys
|
| 15 |
+
import threading
|
| 16 |
import time
|
| 17 |
from types import CodeType, FunctionType, ModuleType
|
| 18 |
|
|
|
|
| 31 |
_BOOT_FILES = {}
|
| 32 |
_BOOT_CODES = {}
|
| 33 |
|
| 34 |
+
# Separate from attestations and their capacity: three fixed-size refusal bitsets.
|
| 35 |
+
DIAGNOSTIC_PREFIX = "[worker-provenance-refusal] "
|
| 36 |
+
DIAGNOSTIC_MAX_LINE_BYTES = 512
|
| 37 |
+
DIAGNOSTIC_CODES = {
|
| 38 |
+
"boot_source": ("source", "compile", "origin", "summary", "cached"),
|
| 39 |
+
"evidence": ("context", "boot", "source_before", "origin_before", "store",
|
| 40 |
+
"origin_after", "source_after", "record"),
|
| 41 |
+
"heartbeat_attestation": ("evidence", "heartbeat", "record"),
|
| 42 |
+
}
|
| 43 |
+
DIAGNOSTIC_CATEGORIES = ("unproven", "missing", "invalid", "resource", "timeout", "exception")
|
| 44 |
+
_DIAGNOSTIC_SEEN = dict.fromkeys(DIAGNOSTIC_CODES, 0)
|
| 45 |
+
_DIAGNOSTIC_LOCK = threading.Lock()
|
| 46 |
+
_BOOT_REFUSAL = ("cached", "unproven")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _diagnostic_category(exc):
|
| 50 |
+
# Exact builtins only. Never inspect exception text, args, subclasses or frames.
|
| 51 |
+
for cls, category in ((FileNotFoundError, "missing"), (ValueError, "invalid"),
|
| 52 |
+
(MemoryError, "resource"), (TimeoutError, "timeout")):
|
| 53 |
+
if type(exc) is cls:
|
| 54 |
+
return category
|
| 55 |
+
return "exception"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _diagnostic_record(stage, code, category):
|
| 59 |
+
at, pid = time.time(), os.getpid()
|
| 60 |
+
if (type(at) not in (int, float) or not math.isfinite(at)
|
| 61 |
+
or type(pid) is not int or not 0 < pid < 2**63):
|
| 62 |
+
return None
|
| 63 |
+
record = {"stage": stage, "code": code, "category": category, "pid": pid, "at": at}
|
| 64 |
+
job = os.environ.get("JOB_ID", "")
|
| 65 |
+
if type(job) is str and re.fullmatch(r"[A-Za-z0-9_-]{1,128}", job):
|
| 66 |
+
record["jobId"] = job
|
| 67 |
+
line = DIAGNOSTIC_PREFIX + json.dumps(record, sort_keys=True, separators=(",", ":"),
|
| 68 |
+
ensure_ascii=True, allow_nan=False) + "\n"
|
| 69 |
+
return line if len(line.encode("ascii")) <= DIAGNOSTIC_MAX_LINE_BYTES else None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _diagnostic_refusal(stage, code, category="unproven", *, exc=None):
|
| 73 |
+
"""Attempt each literal refusal once per boundary streak; diagnostics never escape."""
|
| 74 |
+
global _BOOT_REFUSAL
|
| 75 |
+
try:
|
| 76 |
+
if type(stage) is not str or type(code) is not str or type(category) is not str:
|
| 77 |
+
return
|
| 78 |
+
if exc is not None:
|
| 79 |
+
category = _diagnostic_category(exc)
|
| 80 |
+
with _DIAGNOSTIC_LOCK:
|
| 81 |
+
if stage == "boot_source" and code == "cached":
|
| 82 |
+
code, category = _BOOT_REFUSAL
|
| 83 |
+
codes = DIAGNOSTIC_CODES[stage]
|
| 84 |
+
bit = 1 << (codes.index(code) * len(DIAGNOSTIC_CATEGORIES)
|
| 85 |
+
+ DIAGNOSTIC_CATEGORIES.index(category))
|
| 86 |
+
if stage == "boot_source":
|
| 87 |
+
_BOOT_REFUSAL = code, category
|
| 88 |
+
if _DIAGNOSTIC_SEEN[stage] & bit:
|
| 89 |
+
return
|
| 90 |
+
# Mark before construction/write: a broken sink cannot flood a failure streak.
|
| 91 |
+
_DIAGNOSTIC_SEEN[stage] |= bit
|
| 92 |
+
# Factories and sinks may reenter either diagnostic boundary.
|
| 93 |
+
line = _diagnostic_record(stage, code, category)
|
| 94 |
+
if line is not None:
|
| 95 |
+
sys.stderr.write(line)
|
| 96 |
+
except BaseException:
|
| 97 |
+
pass
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _diagnostic_success(stage):
|
| 101 |
+
try:
|
| 102 |
+
with _DIAGNOSTIC_LOCK:
|
| 103 |
+
_DIAGNOSTIC_SEEN[stage] = 0
|
| 104 |
+
except BaseException:
|
| 105 |
+
pass
|
| 106 |
+
|
| 107 |
|
| 108 |
def encoded(value):
|
| 109 |
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False,
|
|
|
|
| 342 |
"""Pin installed bytes once before worker services start, including an unproven boot."""
|
| 343 |
global _BOOT_SOURCE, _BOOT_FILES, _BOOT_CODES
|
| 344 |
if _BOOT_SOURCE is None:
|
| 345 |
+
phase = "source"
|
| 346 |
try:
|
| 347 |
path = Path(__file__)
|
| 348 |
if path.is_symlink() or path.parent.is_symlink():
|
| 349 |
raise ValueError("worker_source_symlink")
|
| 350 |
version, _BOOT_FILES, total = source_files()
|
| 351 |
_BOOT_CODES = {}
|
| 352 |
+
phase = "compile"
|
| 353 |
started, code_count = time.monotonic(), 0
|
| 354 |
for relative, digest in _BOOT_FILES.items():
|
| 355 |
if not relative.endswith(".py"):
|
|
|
|
| 366 |
codes.add(code_identity(code))
|
| 367 |
pending.extend(value for value in code.co_consts if isinstance(value, CodeType))
|
| 368 |
_BOOT_CODES[relative] = codes
|
| 369 |
+
phase = "origin"
|
| 370 |
loaded_origins()
|
| 371 |
+
phase = "summary"
|
| 372 |
_BOOT_SOURCE = version, source_summary(_BOOT_FILES, total)
|
| 373 |
+
except Exception as exc:
|
| 374 |
_BOOT_SOURCE = False
|
| 375 |
+
_diagnostic_refusal("boot_source", phase, exc=exc)
|
| 376 |
+
if _BOOT_SOURCE is False:
|
| 377 |
+
_diagnostic_refusal("boot_source", "cached")
|
| 378 |
+
elif _BOOT_SOURCE is not None:
|
| 379 |
+
_diagnostic_success("boot_source")
|
| 380 |
return _BOOT_SOURCE
|
| 381 |
|
| 382 |
|
|
|
|
| 423 |
|
| 424 |
def evidence(rt):
|
| 425 |
"""Return fresh bounded evidence or None without affecting worker health."""
|
| 426 |
+
code = "context"
|
| 427 |
try:
|
| 428 |
import process_role
|
| 429 |
from core import data_binding
|
|
|
|
| 437 |
or (os.environ.get("RI_DIR") and Path(os.environ["RI_DIR"]).resolve() != (ROOT / "platform").resolve())
|
| 438 |
or (dataset and not re.fullmatch(r"[A-Za-z0-9_-]+/[A-Za-z0-9_.-]+", dataset))
|
| 439 |
or os.environ.get("AIOS_SYNC_JOB_MODE") != "resident"):
|
| 440 |
+
_diagnostic_refusal("evidence", "context")
|
| 441 |
return None
|
| 442 |
+
code = "boot"
|
| 443 |
boot = boot_source()
|
| 444 |
if not boot:
|
| 445 |
+
_diagnostic_refusal("evidence", "boot")
|
| 446 |
return None
|
| 447 |
+
code = "source_before"
|
| 448 |
current = installed_source()
|
| 449 |
if current != boot:
|
| 450 |
+
_diagnostic_refusal("evidence", "source_before")
|
| 451 |
return None
|
| 452 |
version, source = current
|
| 453 |
+
code = "origin_before"
|
| 454 |
loaded_origins()
|
| 455 |
+
code = "store"
|
| 456 |
store = store_identity(rt)
|
| 457 |
+
code = "origin_after"
|
| 458 |
loaded_origins()
|
| 459 |
+
code = "source_after"
|
| 460 |
if installed_source() != boot:
|
| 461 |
+
_diagnostic_refusal("evidence", "source_after")
|
| 462 |
return None
|
| 463 |
+
code = "record"
|
| 464 |
+
value = bounded({"at": time.time(), "pid": os.getpid(), "spaceId": space, "jobId": job,
|
| 465 |
"tenant": tenant, "version": version, "source": source, "store": store,
|
| 466 |
"role": process_role.role(), "scope": process_role.worker_scope(),
|
| 467 |
"deployment": data_binding.deployment_id(), "mode": "resident",
|
|
|
|
| 472 |
"executableOverride": any((os.environ.get("ENV"), os.environ.get("BASH_ENV"),
|
| 473 |
os.environ.get("PYTHONPATH"), os.environ.get("PYTHONHOME"),
|
| 474 |
os.environ.get("LD_PRELOAD"), os.environ.get("LD_LIBRARY_PATH")))}})
|
| 475 |
+
_diagnostic_success("evidence")
|
| 476 |
+
return value
|
| 477 |
+
except Exception as exc:
|
| 478 |
+
_diagnostic_refusal("evidence", code, exc=exc)
|
| 479 |
return None
|
| 480 |
|
| 481 |
|
|
|
|
| 504 |
|
| 505 |
|
| 506 |
def heartbeat_attestation(rt, beat):
|
| 507 |
+
code = "evidence"
|
| 508 |
try:
|
| 509 |
value = evidence(rt)
|
| 510 |
+
code = "heartbeat"
|
| 511 |
bounded(beat)
|
| 512 |
+
if not value:
|
| 513 |
+
_diagnostic_refusal("heartbeat_attestation", "evidence")
|
| 514 |
+
return None
|
| 515 |
+
code = "record"
|
| 516 |
+
value = bounded({**value, "schema": "sync-worker-attestation/v1", "heartbeatSha256": sha(encoded(beat))})
|
| 517 |
+
_diagnostic_success("heartbeat_attestation")
|
| 518 |
+
return value
|
| 519 |
+
except Exception as exc:
|
| 520 |
+
_diagnostic_refusal("heartbeat_attestation", code, exc=exc)
|
| 521 |
return None
|
| 522 |
|
| 523 |
|
platform/harness/datastore.py
CHANGED
|
@@ -956,6 +956,68 @@ _ACTIVE_WRITES = [0]
|
|
| 956 |
_COUNT_CACHE = OrderedDict()
|
| 957 |
_COUNT_CACHE_MAX = 256
|
| 958 |
_COUNT_CACHE_LOCK = _thr.RLock()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
|
| 960 |
|
| 961 |
def _invalidate_counts(path=None, *, source_write=True):
|
|
@@ -967,6 +1029,7 @@ def _invalidate_counts(path=None, *, source_write=True):
|
|
| 967 |
handle = _HANDLES_LIVE.get(str(Path(path or DB_PATH).resolve()))
|
| 968 |
if handle is not None:
|
| 969 |
handle.writes += 1
|
|
|
|
| 970 |
|
| 971 |
|
| 972 |
def note_mirror_install(path=None, *, cur=None):
|
|
|
|
| 956 |
_COUNT_CACHE = OrderedDict()
|
| 957 |
_COUNT_CACHE_MAX = 256
|
| 958 |
_COUNT_CACHE_LOCK = _thr.RLock()
|
| 959 |
+
_WRITE_HISTORY = OrderedDict()
|
| 960 |
+
_WRITE_HISTORY_TENANTS = 16
|
| 961 |
+
_WRITE_HISTORY_EVENTS = 32
|
| 962 |
+
_WRITE_HISTORY_STACK = 6
|
| 963 |
+
|
| 964 |
+
|
| 965 |
+
def _remember_source_write(handle):
|
| 966 |
+
"""Retain bounded accounting evidence without retaining frames, SQL or arguments."""
|
| 967 |
+
if handle is None:
|
| 968 |
+
return
|
| 969 |
+
try:
|
| 970 |
+
frames, frame = [], sys._getframe(1)
|
| 971 |
+
try:
|
| 972 |
+
for _ in range(_WRITE_HISTORY_STACK):
|
| 973 |
+
if frame is None:
|
| 974 |
+
break
|
| 975 |
+
symbol = frame.f_code.co_name
|
| 976 |
+
basename = frame.f_code.co_filename.replace("\\", "/").rsplit("/", 1)[-1]
|
| 977 |
+
frames.append({"symbol": symbol if re.fullmatch(r"[\w.<>]{1,64}", symbol, re.ASCII)
|
| 978 |
+
else "<unavailable>",
|
| 979 |
+
"file": basename if re.fullmatch(r"[\w.-]{1,64}\.py", basename, re.ASCII)
|
| 980 |
+
else "<unavailable>", "line": frame.f_lineno})
|
| 981 |
+
frame = frame.f_back
|
| 982 |
+
finally:
|
| 983 |
+
del frame
|
| 984 |
+
event = {"counter": handle.writes, "pid": os.getpid(), "thread": _thr.get_ident(),
|
| 985 |
+
"time_ns": time.time_ns(), "classification": "source_write", "stack": frames}
|
| 986 |
+
key = _weakref.ref(handle)
|
| 987 |
+
history = _WRITE_HISTORY.get(key)
|
| 988 |
+
if history is None:
|
| 989 |
+
history = {"events": deque(maxlen=_WRITE_HISTORY_EVENTS), "lost_through": handle.writes - 1}
|
| 990 |
+
_WRITE_HISTORY[key] = history
|
| 991 |
+
_WRITE_HISTORY.move_to_end(key)
|
| 992 |
+
while len(_WRITE_HISTORY) > _WRITE_HISTORY_TENANTS:
|
| 993 |
+
_WRITE_HISTORY.popitem(last=False)
|
| 994 |
+
if len(history["events"]) == _WRITE_HISTORY_EVENTS:
|
| 995 |
+
history["lost_through"] = history["events"][0]["counter"]
|
| 996 |
+
history["events"].append(event)
|
| 997 |
+
except BaseException:
|
| 998 |
+
pass
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
def mirror_write_evidence(cur, before, after):
|
| 1002 |
+
"""Report only retained events inside this handle's exact compared counter interval."""
|
| 1003 |
+
result = {"status": "unavailable", "complete": False, "events": []}
|
| 1004 |
+
if type(before) is not int or type(after) is not int or after < before:
|
| 1005 |
+
return result
|
| 1006 |
+
handle = getattr(cur, "_mirror_handle", None)
|
| 1007 |
+
if handle is None:
|
| 1008 |
+
return result # Legacy counters combine tenants and cannot attribute a tenant's writes.
|
| 1009 |
+
if before == after:
|
| 1010 |
+
return {"status": "not_moved", "complete": False, "events": []}
|
| 1011 |
+
with _COUNT_CACHE_LOCK:
|
| 1012 |
+
history = _WRITE_HISTORY.get(_weakref.ref(handle))
|
| 1013 |
+
if history is None:
|
| 1014 |
+
return result
|
| 1015 |
+
events = [dict(event, stack=[dict(frame) for frame in event["stack"]])
|
| 1016 |
+
for event in history["events"] if before < event["counter"] <= after]
|
| 1017 |
+
overflow = before < history["lost_through"]
|
| 1018 |
+
complete = not overflow and len(events) == after - before
|
| 1019 |
+
return {"status": "overflow" if overflow else "retained" if complete else "unavailable",
|
| 1020 |
+
"complete": complete, "events": events}
|
| 1021 |
|
| 1022 |
|
| 1023 |
def _invalidate_counts(path=None, *, source_write=True):
|
|
|
|
| 1029 |
handle = _HANDLES_LIVE.get(str(Path(path or DB_PATH).resolve()))
|
| 1030 |
if handle is not None:
|
| 1031 |
handle.writes += 1
|
| 1032 |
+
_remember_source_write(handle)
|
| 1033 |
|
| 1034 |
|
| 1035 |
def note_mirror_install(path=None, *, cur=None):
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
5c44e645639570cde0659c50f5c3a4760cc78124ed4be67f8b0044f629063e56
|