Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
- run: build/workspace-training/bin/python -m unittest discover -s tests -p test_pointclouds.py
- run: build/workspace-training/bin/python -m unittest discover -s tests -p test_volume_assets.py
- run: python -m unittest discover -s tests
- run: node --check static/auth.js
- run: node tests/test_auth_helpers.cjs
- run: node tests/test_auth_controller.cjs
- run: node tests/browser_access.cjs
env:
BROWSER: /usr/bin/google-chrome
- run: node --check static/scientific-fields.js
- run: build/workspace-training/bin/python tests/qualify_scientific_fields.py --output build/qa/scientific-neutral.zip --report build/qa/scientific-neutral.json
- run: node tests/browser_scientific_fields.cjs
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ installer, with its `bin` directory on `PATH`. Initialize a private service once
eval "$(.venv/bin/python scripts/local_postgres.py env)"
.venv/bin/python app.py

In another terminal with the same database environment, create a private one-time
login file: `.venv/bin/python access.py login --data ./data --out /private/new-login-code`.
Use an existing private directory and a new filename, then enter its code in the
browser's Session dialog. Codes expire after ten minutes; sessions last eight
hours. Localhost is not an authenticated identity. Existing catalogs require the
explicit schema-7 upgrade before starting this version. See [actor access](docs/contracts/actors.md)
for scoped agent credentials and [storage upgrades](docs/contracts/workspace-storage.md).
Existing execution remains owner-only; agent execution approval is a later stage.

The setup script uses a Unix socket under `~/.local/share/tuldok/postgres`,
generates private credentials, and creates a database role without superuser,
role-creation or database-creation permissions. It opens no TCP listener. Stop the
Expand Down Expand Up @@ -68,7 +77,7 @@ current record; saving/reviewing and freezing a new release leaves old results
unchanged. Viewing test results records durable exposure; reused records or
pixels cannot be presented as fresh holdout evidence.

Fresh catalogs use schema 6. Existing PostgreSQL schema-1 through schema-5 catalogs require an
Fresh catalogs use schema 7. Existing PostgreSQL schema-1 through schema-6 catalogs require an
explicit stopped-writer backup and upgrade, never an automatic startup change:

```sh
Expand Down
402 changes: 402 additions & 0 deletions access.py

Large diffs are not rendered by default.

203 changes: 173 additions & 30 deletions app.py

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions audio_assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bounded original PCM WAV assets; Workbench owns records, revisions and review."""
from access import authorized
import base64
import hashlib
import io
Expand Down Expand Up @@ -93,9 +94,11 @@ def validate_annotation(value, record):

class AudioAssets:
def __init__(self, workbench):
self.access = workbench.access
self.workbench = workbench
self.path = workbench.dataset.path / 'audio'

@authorized('edit', 'audio_assets.admit')
def admit(self, body):
from immutable_assets import publish_file
if type(body) is not dict or set(body) - {'wav', 'name', 'rights', 'groups', 'parents'}:
Expand Down Expand Up @@ -134,14 +137,17 @@ def admit(self, body):
encode(origin), TASK, None, 'draft', 1, created, created))
record = w._get(record_id)
w._history(record)
self.access.audit('audio_assets.admit', record_id, {'revision': record['revision'], 'source_sha256': digest})
return record

@authorized('inspect', 'audio_assets.metadata')
def metadata(self, record_id, provenance):
meta = provenance.get('audio')
if not isinstance(meta, dict) or meta.get('schema_version') != 1:
invalid('stored source metadata is unavailable.', 'unavailable', 409)
return dict(meta), (self.path / record_id / 'source.wav').is_file()

@authorized('inspect', 'audio_assets.asset', target=lambda record: record.get('id') if isinstance(record, dict) else None)
def asset(self, record):
path = self.path / record['id'] / 'source.wav'
try:
Expand All @@ -157,6 +163,7 @@ def asset(self, record):
invalid('retained source metadata does not match the original WAV.', 'conflict', 409)
return raw, 'audio/wav'

@authorized('inspect', 'audio_assets.inspect')
def inspect(self, record_id):
w = self.workbench
with w.lock:
Expand Down
2 changes: 2 additions & 0 deletions bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def result(record):


def find_result(workbench, request_id):
workbench.access.require('inspect', 'bulk_import.find_result', request_id)
if not isinstance(request_id, str) or not REQUEST_ID.fullmatch(request_id):
raise WorkbenchError('Invalid import request marker.')
with workbench.lock:
Expand All @@ -85,6 +86,7 @@ def find_result(workbench, request_id):


def import_row(workbench, body):
workbench.access.require('edit', 'bulk_import.import_row')
if set(body) - {'source_name', 'row_number', 'line', 'request_id', 'image_name', 'image'}:
raise WorkbenchError('Unsupported row admission fields.')
source_name = leaf_name(body.get('source_name'), 'Manifest name')
Expand Down
4 changes: 4 additions & 0 deletions caption_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""One native image_caption_v1 decoder; asset/target owners remain canonical."""
from access import authorized
import base64
import hashlib
import hmac
Expand Down Expand Up @@ -117,6 +118,7 @@ def origin_groups(family):

class CaptionImports:
def __init__(self, workbench):
self.access = workbench.access
self.workbench = workbench
# Process-local integrity only. Restart invalidates preparation; no corpus
# registry, persistent job, external credential or authenticity claim.
Expand All @@ -140,6 +142,7 @@ def _open(self, token):
except (ValueError, UnicodeError):
invalid('Invalid or expired caption preparation envelope.')

@authorized('edit', 'caption_import.prepare')
def prepare(self, body):
if set(body) != {'manifest', 'metadata'} or not isinstance(body['metadata'], dict) or set(body['metadata']) != set(CAPTION_SPLITS.values()):
invalid('Supply native manifest and exactly train/val/test metadata.')
Expand Down Expand Up @@ -255,6 +258,7 @@ def prepare(self, body):
invalid('Manifest and metadata do not contain the same exact asset set.')
return {'format': CAPTION_FORMAT, 'rows': rows}

@authorized('edit', 'caption_import.admit')
def admit(self, body):
if set(body) != {'token', 'asset', 'image', 'request_id'}:
invalid('Unsupported caption admission fields.')
Expand Down
34 changes: 32 additions & 2 deletions caption_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from workbench import encode_retained
import base64
import hashlib
from access import AccessError, authorized
import io
import json
import threading
Expand Down Expand Up @@ -116,11 +117,12 @@ def decode(data, source, request_id=None):
class CaptionProposals:
def __init__(self, workbench):
self.workbench = workbench
self.access = workbench.dataset.access
self.db, self.lock = workbench.db, workbench.lock
self.worker, self.active_id = None, None
self.stop = threading.Event()
self.closed = False
with self.lock, self.db.transaction():
with self.access._reconcile(), self.lock, self.db.transaction():
self.runtime_owner = self.db.claim_runtime('caption_proposals')
if not self.runtime_owner:
return
Expand All @@ -131,6 +133,7 @@ def __init__(self, workbench):
job['provider_outcome'] = 'not_admitted' if job['status'] == 'preparing' else 'unknown'
job.update(status='interrupted', error='Server stopped; inspect this attempt. No automatic inference retry.')
self._save(job)
self.access.audit('caption.reconcile', job['id'], {'status': job['status']})

def _save(self, job):
previous = self.db.execute('SELECT data FROM caption_proposals WHERE id=%s', (job['id'],)).fetchone()
Expand All @@ -146,10 +149,12 @@ def _get(self, job_id):
raise WorkbenchError('Caption request not found.', 'unavailable', 404)
return json.loads(row[0])

@authorized('inspect', 'caption.get')
def get(self, job_id):
with self.lock:
return self._get(job_id)

@authorized('inspect', 'caption.snapshot')
def snapshot(self):
with self.lock:
# Project only the poll response; stored JSON remains byte-for-byte intact.
Expand Down Expand Up @@ -195,6 +200,7 @@ def _source(self, body, *, capture_image=False):
raise WorkbenchError('Source image bytes are missing.', 'unavailable', 409) from None
return record, image_bytes

@authorized('execute', 'caption.start', owner_only=True)
def start(self, body):
fields = {'request_id', 'source_id', 'revision', 'source_revision', 'server_url', 'model', 'instruction', 'seed'}
if not isinstance(body, dict) or not fields <= body.keys() or body.keys() - fields - {'protocol', 'profile'}:
Expand Down Expand Up @@ -250,6 +256,10 @@ def start(self, body):
job['canonical_request_sha256'] = hashlib.sha256(encode(payload(job)).encode()).hexdigest()
if pumas.typed(config):
job['provider_outcome'] = 'not_admitted'
job['request_digest'] = hashlib.sha256(encode({'config': job['config'], 'source': job['source'], 'payload': payload(job)}).encode()).hexdigest()
job['admission_id'] = self.access.admit_job('caption', job['id'], job['request_digest'],
{'caption.finish': [job['id']]})
self.access.audit('caption.start', job['id'], {'request_digest': job['request_digest']})
self._save(job)
# Persistence has committed; this lock serializes startup and shutdown.
self.stop.clear()
Expand All @@ -265,7 +275,21 @@ def start(self, body):
return job

def _run(self, job_id):
job = self.get(job_id)
with self.lock:
job = self._get(job_id)
request_digest = hashlib.sha256(encode({'config': job['config'], 'source': job['source'], 'payload': payload(job)}).encode()).hexdigest()
try:
with self.access._job('caption', job_id, job.get('admission_id'), request_digest):
self._run_admitted(job)
except AccessError:
with self.access._reconcile(), self.lock, self.db.transaction():
job.update(status='interrupted', error='Job admission is missing or differs from the retained request; no inference started.')
self._save(job)
self.access.audit('caption.interrupt', job_id)
self.active_id = None

def _run_admitted(self, job):
job_id = job['id']
try:
if pumas.typed(job['config']):
pumas_vision.prepare(job, payload(job), self.stop)
Expand Down Expand Up @@ -297,15 +321,18 @@ def _run(self, job_id):
self._source(dict(source_id=job['source']['id'], revision=job['source']['revision'], source_revision=job['source']['source_revision']))
job.update(status='completed', annotation=annotation, reported_model=reported)
self._save(job)
self.access.audit('caption.finish', job_id, {'status': job['status'], 'response_sha256': job.get('response_sha256')})
except Exception as error:
with self.lock, self.db.transaction():
pumas.failure_evidence(job, error)
job.update(status='cancelled' if self.stop.is_set() else 'failed', error=str(error)[:800])
self._save(job)
self.access.audit('caption.finish', job_id, {'status': job['status']})
finally:
with self.lock:
self.active_id = None

@authorized('cancel', 'caption.cancel', target=lambda body: body.get('job_id') if isinstance(body, dict) else None)
def cancel(self, body):
if not isinstance(body, dict) or set(body) != {'job_id'}:
raise WorkbenchError('Supply only the caption request ID.')
Expand All @@ -316,8 +343,10 @@ def cancel(self, body):
self.stop.set()
job.update(status='stopping', error='Cancellation requested; late output cannot be applied.')
self._save(job)
self.access.audit('caption.cancel', job['id'])
return {'cancelled': True, 'job': job}

@authorized('edit', 'caption.decide')
def decide(self, job_id, body):
if not isinstance(body, dict) or set(body) != {'revision', 'decision'} or body['decision'] not in ('reject', 'apply_draft'):
raise WorkbenchError('Choose reject or apply_draft with the current proposal revision.')
Expand Down Expand Up @@ -347,6 +376,7 @@ def decide(self, job_id, body):
else:
job['status'] = 'rejected'
self._save(job)
self.access.audit('caption.decide', job['id'], {'revision': job['revision'], 'decision': body['decision']})
return {'job': job, 'record': record, 'changed': True}

def close(self):
Expand Down
1 change: 1 addition & 0 deletions dataset_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def candidates(recipe, seed, count):


def generate(workbench, body):
workbench.access.require('execute', 'dataset_recipes.generate', owner_only=True)
recipe, seed, count = body.get('recipe'), body.get('seed'), body.get('count')
# Validate the recipe and materialize only the bounded candidate metadata/bytes.
batch = list(candidates(recipe, seed, count))
Expand Down
12 changes: 12 additions & 0 deletions dataset_releases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Frozen, self-contained releases with connected-source split allocation."""
from access import authorized
import audio_export
import hashlib
import json
Expand Down Expand Up @@ -154,10 +155,12 @@ def archive_asset(archive, asset, filename, expected_hash):

class Releases:
def __init__(self, workbench):
self.access = workbench.access
self.workbench = workbench
self.path = workbench.dataset.path / 'releases'
self.path.mkdir(exist_ok=True)

@authorized('inspect', 'dataset_releases.locate')
def locate(self, release_id):
if not isinstance(release_id, str) or not RELEASE_ID.fullmatch(release_id):
raise WorkbenchError('Invalid release ID.')
Expand All @@ -166,6 +169,7 @@ def locate(self, release_id):
raise WorkbenchError('Release not found.', 'unavailable', 404)
return path

@authorized('inspect', 'dataset_releases.preview')
def preview(self, body):
"""Inspect the exact selection without persisting even lazy image enrollment."""
workbench = self.workbench
Expand Down Expand Up @@ -441,6 +445,7 @@ def _create_corpus(self, body):
if os.path.exists(temporary):
os.unlink(temporary)
preview = prepared['preview']
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': corpus_export.FORMAT, 'records': len(prepared['rows']),
'split_report': preview['split_report'], 'corpus_counts': preview['corpus_counts'],
Expand Down Expand Up @@ -656,11 +661,13 @@ def _create_responses(self, body):
if os.path.exists(temporary):
os.unlink(temporary)
preview = prepared['preview']
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': body['format'], 'records': preview['example_count'],
'example_count': preview['example_count'], 'unique_prompt_count': preview['unique_prompt_count'],
'split_report': preview['split_report']}

@authorized('freeze', 'dataset_releases.create')
def create(self, body):
with self.workbench.lock:
if self.workbench.db.in_transaction:
Expand Down Expand Up @@ -747,6 +754,7 @@ def _create(self, body):
finally:
if os.path.exists(temporary):
os.unlink(temporary)
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip', 'records': len(rows), 'split_report': report}

def _create_captions(self, body):
Expand Down Expand Up @@ -796,6 +804,7 @@ def _create_captions(self, body):
finally:
if os.path.exists(temporary):
os.unlink(temporary)
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': CAPTION_FORMAT, 'records': len(rows), 'split_report': report, 'warnings': manifest['warnings']}

Expand Down Expand Up @@ -849,6 +858,7 @@ def _create_classification(self, body):
finally:
if os.path.exists(temporary):
os.unlink(temporary)
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': classification_export.FORMAT, 'records': len(rows),
'split_report': preview['split_report'], 'class_vocabulary': vocabulary,
Expand All @@ -871,6 +881,7 @@ def _create_text_classification(self, body):
finally:
if os.path.exists(temporary):
os.unlink(temporary)
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': text_class_export.FORMAT, 'records': len(prepared['rows']),
'split_report': prepared['preview']['split_report'],
Expand Down Expand Up @@ -902,6 +913,7 @@ def _create_audio_classification(self, body):
finally:
if os.path.exists(temporary):
os.unlink(temporary)
self.access.audit('dataset_releases.create', release_id, {'release_sha256': release_id, 'format': body.get('format', 'canonical_v1')})
return {'id': release_id, 'url': '/api/workbench/releases/' + release_id + '.zip',
'format': audio_class_export.FORMAT, 'records': len(prepared['rows']),
'split_report': prepared['preview']['split_report'],
Expand Down
Loading
Loading