grading

package
v1.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 21 Imported by: 0

README

Protected sandbox grading

You can install a JSON equality supervisor and a recoverable sandbox evaluation adapter from this package. The adapter uses the existing verification executor and sandbox test verifier. It does not rerun the agent, expose effect tools, or execute a host shell.

NewEqualitySupervisor accepts a bounded list of sealed manifests and reserved assessment artifact IDs. Supply the same registrations after a restart. Every manifest must pin EqualitySupervisorRevision, use restricted JSON artifacts, and have no state probes. Unsupported protocols and probes fail registration or assessment.

The protected test bundle and result schema each declare the exact ordered check names:

{"protocol":"cortex.json-equality.v1","checks":["answer"]}

The protected fixture dataset contains the expected values. The candidate export uses the same shape for actual values:

{"protocol":"cortex.json-equality.v1","values":{"answer":42}}

The separate grader export reports each check:

{"protocol":"cortex.json-equality.v1","checks":{"answer":"passed"}}

The supervisor independently compares each named value and requires the grader's status to agree. A matching value passes; a different value fails. Missing or additional checks, duplicate JSON keys, unknown envelope fields, invalid UTF-8, and nesting beyond 32 levels fail closed. Each artifact is limited to one MiB. Numbers retain their JSON spelling, so 1 and 1.0 are different values under this protocol. Candidate text and stdout cannot supply instructions or authority.

An assessment is an immutable restricted artifact bound to the exact manifest, candidate job, grader job, exported artifact references, and individual results. Reports carry the candidate export, grader export, and assessment in ObservationRefs. These references are included in the report digest without changing its original input binding. Report save, result commit, and current result reads load their bytes again. A deleted observation blocks current result access; historical report metadata remains available.

Host lifecycle

Construct EvaluationConfig with the existing SandboxTestConfig, the same manifest roster, a private journal directory, its owning UID, a polling interval, and a conservative allowance for both exact jobs. The directory must already exist, have mode 0700, and pass the host path ownership checks. The adapter creates immutable mode 0400 journal records and holds an exclusive process lock while running. One adapter process owns a journal at a time.

Call Start with your authorized service context before passing the adapter to verification.NewExecutor. Call Stop during shutdown and wait for it to finish. A timed-out stop keeps the process lock until a later stop joins the worker. This package does not automatically attach its phase service to an engine lifecycle.

The host supplies a pinned price revision and an upper bound covering both jobs' enforced resource ceilings. Money usage remains unknown because the sandbox result protocol does not contain authenticated billing. The existing evaluator ledger keeps the full allowance charged. Explicit token-only policy is supported with a zero money allowance and no price revision.

Evaluate retains the original call admission before the service starts its phases. It may return ErrCallUncertain while work is pending. The existing verification worker can later call Reconcile, which reads and validates retained output without submitting, cancelling, collecting, or running another evaluator.

Before each first job submission, the service writes an immutable intent. A retry inspects the original job ID; it never submits that identity again. After a restart, a completed candidate can allow the original grader to start if its submission intent was not consumed. A crash after consuming an intent but before the broker accepted it remains uncertain without an original broker receipt. There is no replacement ID, inferred success, or refund. Call IDs cannot move to another manifest within the journal.

Keep the journal and manifest registrations for as long as their admissions must be recoverable. Journal records contain references, contracts, and reports, not candidate or export artifact bodies. Apply your retention and access policy to this metadata. Artifact deletion still goes through the evidence repository and prevents cached results from becoming usable again.

Verification boundary

The tests exercise protected files, signed fixture broker responses, process locking, restart recovery, the existing evaluator executor, and real SQLite persistence. Shared observation conformance also runs against the Postgres and Mongo stores when their disposable containers are available. These tests do not qualify a live Linux worker. Runtime qualification, source and artifact grants, current deployment identity, and provisioned runner credentials remain host requirements.

Documentation

Overview

Package grading connects protected verification to authenticated sandbox jobs.

Index

Constants

View Source
const EqualityProtocol = "cortex.json-equality.v1"

EqualityProtocol selects bounded named JSON equality checks. It does not run arbitrary tests or interpret candidate text as supervisor instructions.

View Source
const EqualitySupervisorRevision = "865713cfa2ef0a3ec50726f34a7d748bca37e9b44d5b9bd905478e5a58fd1474"

EqualitySupervisorRevision pins the implementation of the equality protocol.

Variables

This section is empty.

Functions

func NewFileExporter

func NewFileExporter(c FileExportConfig) (*verification.ArtifactExporter, error)

NewFileExporter binds protected, non-replacing file publication to the guarded root export command. It creates no directories, files, listeners or workers.

Types

type Authenticity

type Authenticity struct {
	// contains filtered or unexported fields
}

Authenticity pins the broker name and signing key independently of responses.

func NewAuthenticity

func NewAuthenticity(name string, key ed25519.PublicKey) (*Authenticity, error)

NewAuthenticity copies a host-configured broker identity.

func (*Authenticity) VerifyReceipt

func (a *Authenticity) VerifyReceipt(ctx context.Context, r sandbox.Receipt, j sandbox.Job) error

VerifyReceipt authenticates the complete receipt against the expected job.

func (*Authenticity) VerifyResult

func (a *Authenticity) VerifyResult(ctx context.Context, r sandbox.Result, j sandbox.Job) error

VerifyResult authenticates a terminal observation without treating it as a verdict.

type EqualitySupervisor

type EqualitySupervisor struct {
	// contains filtered or unexported fields
}

EqualitySupervisor corroborates every declared grader check against protected expected JSON and authenticated candidate exports, retaining the original bytes.

func NewEqualitySupervisor

func NewEqualitySupervisor(c SupervisorConfig) (*EqualitySupervisor, error)

NewEqualitySupervisor freezes a bounded roster without accessing artifacts.

func (*EqualitySupervisor) Assess

Assess rechecks current authority and every artifact on retries. A changed, missing, revoked or expired observation cannot reuse a previous assessment.

type EvaluationAdapter

type EvaluationAdapter struct {
	// contains filtered or unexported fields
}

EvaluationAdapter retains evaluator admissions and results by stable call ID. Start and Stop belong to the installed host lifecycle. Reconcile never starts an evaluator or submits a sandbox job.

func NewEvaluationAdapter

func NewEvaluationAdapter(c EvaluationConfig) (*EvaluationAdapter, error)

NewEvaluationAdapter freezes registrations without starting work or creating files.

func (*EvaluationAdapter) Estimate

Estimate returns only the installed host price bound for the exact registered jobs.

func (*EvaluationAdapter) Evaluate

Evaluate durably admits the original call. The explicit service advances its phases independently; pending admission is uncertain and keeps its full charge.

func (*EvaluationAdapter) Failures

func (a *EvaluationAdapter) Failures() uint64

Failures counts unsuccessful phase passes without retaining sensitive errors.

func (*EvaluationAdapter) Reconcile

Reconcile observes only retained output, rechecking current authority and input/output evidence. It does not submit, cancel, collect or rerun evaluation.

func (*EvaluationAdapter) Start

func (a *EvaluationAdapter) Start(ctx context.Context) error

Start obtains the journal's exclusive process lock and starts bounded phase recovery using the host service context. It must carry current service authority.

func (*EvaluationAdapter) Stop

func (a *EvaluationAdapter) Stop(ctx context.Context) error

Stop cancels active work and joins it before releasing the process lock. A deadline error leaves the lock held until work drains and Stop is retried.

type EvaluationConfig

type EvaluationConfig struct {
	Tests            verification.SandboxTestConfig
	Manifests        []verification.EvaluationManifest
	Allowance        verification.EvaluationAllowance
	JournalDirectory string
	Owner            uint32
	Interval         time.Duration
}

EvaluationConfig installs a bounded roster and a protected local phase journal. Allowance is the host's conservative price bound for both exact jobs, whose resource ceilings are enforced by the qualified runner. Unknown money remains charged at this bound. The host must persist the roster across restarts.

type FileExportConfig

type FileExportConfig struct {
	Command          verification.ArtifactExporterConfig
	JournalDirectory string
	Destinations     []FileExportDestination
	Owner            uint32
}

FileExportConfig installs a local export command with a global operation journal. Command.Sink must be nil. Directories must be distinct, private and owned by Owner.

type FileExportDestination

type FileExportDestination struct {
	Name      string
	Revision  string
	Directory string
}

FileExportDestination maps a logical target and revision to a private directory. The host provisions and protects this directory; request data supplies no paths.

type SupervisorConfig

type SupervisorConfig struct {
	Registrations []SupervisorRegistration
	Repository    evidence.Repository
	Authorizer    verification.BindingAuthorizer
	Clock         verification.Clock
}

SupervisorConfig installs protected observations and current host authority.

type SupervisorRegistration

type SupervisorRegistration struct {
	Manifest     verification.EvaluationManifest
	AssessmentID id.ID
}

SupervisorRegistration reserves the immutable assessment identity for a manifest. The host must retain this registration across process restarts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL