Software factory change

Merged
AG
2mo ago
+325-2

flows check now warns that declared agent permissions are not enforced

Problem

AgentStepSpec.permissions (fileGlobs, networkAllowlist, accessPreset) is
carried end-to-end as data and never acted on. Gate 1 validates it
(packages/sdk/src/validate.ts:541), the compiler lowers it to file_globs /
network_allowlist / access_preset (packages/sdk/src/compile.ts:532), the
kernel struct holds it and round-trips it (kernel/relayflowd-core/src/spec.rs:510),
and it appears in the journal. Nothing reads it to gate a file or network access —
the kernel comment at spec.rs:506 says so, and RFC-0001 states enforcement as
gate 8 work (#442).

The gap is known. What was missing is that nothing told the author. A spec that
declares permissions on every agent step passes flows check clean, so the
flows look sandboxed and are not. That is exactly how a set of verification flows
migrated off the older @relayflows/core engine — where the equivalent block
was compiled and enforced — lost their read/write split and their deny list
without a single diagnostic.

Change

Preflight emits a new permissions_unenforced warning for every agent step
that declares a permissions block.

$ flows check sandboxed.flow.yaml
WARNING [permissions_unenforced] Step "review" declares permissions (fileGlobs, accessPreset). \
This declaration is validated and recorded with the step spec; it is not currently enforced \
(gate 8 / #442). These permissions do not restrict file or network access. \
accessPreset: 'readonly' does not prevent writes.
CHECK PASSED sandboxed.flow.yaml

Design points, each deliberate:

  • Warning, never a refusal. ok is unaffected and exit stays 0. Declaring
    permissions is legal and the kernel accepts it; refusing would break every
    migrated spec to fix a documentation problem. The reporter's optional third
    suggestion — refuse accessPreset: 'readonly' outright — was not taken for the
    same reason, but readonly gets a dedicated extra sentence, since that value's
    whole meaning is a guarantee that currently does not hold.
  • Every defined declaration warns, including {} and empty arrays.
    SURFACE.md accepts partial and empty declarations without inferring defaults,
    and an empty block reads to an author as "a default sandbox applies" just as
    readily as a full one. Omitting permissions stays silent; there is no belief
    to correct.
  • Field names, never values. The message names which of fileGlobs,
    networkAllowlist, accessPreset were declared, in a fixed order, and echoes
    no globs or hosts.
  • Collected before anything that can return early. An unresolved CLI, an
    unknown model or a bad scope all refuse before any environment probe runs; the
    author should still be told about the permissions declared in the same file.
    The warning is a pure function of the compiled snapshot and touches no probe.

The wording reuses the sentence the repo already uses for the same gap in
packages/sdk/src/authored-worker-step.ts:102 and
packages/surface/src/context.ts:19, so the three sites read alike.

Second half of the fix: the SDK PermissionsSpec doc comment
(packages/sdk/src/spec.ts:128) previously read "Permission model for an agent
step (gate 8). readonly provably cannot write."
— a claim that is false today.
It now states that the block is validated and recorded but not currently
enforced
, and that accessPreset: 'readonly' does not prevent writes. The
kernel comment was already honest; a TypeScript author never sees it.

Enforcement itself is unchanged and remains gate 8 work.

Files

FileChange
packages/sdk/src/failure-kinds.tspermissions_unenforced added to PREFLIGHT_WARNING_KINDS, with the rationale for warn-not-refuse
packages/sdk/src/permissions-preflight.tsnew; pure permissionsDiagnostics(CompiledFlowSpec), mirroring budget-preflight.ts
packages/sdk/src/preflight.tscalls it on the compiled snapshot before the first early return
packages/sdk/src/spec.tsPermissionsSpec doc comment corrected

No schema, kernel, CLI-rendering or compiler change. The warning flows through
the existing emitDiagnostics path (stderr WARNING [kind] line, and a
diagnostics entry under --json), the checkFlow / checkAuthoredFlow /
checkBuildableFlow reports, and preflight.json inside a built bundle, with no
new plumbing. Authoring YAML/JSON and kernel snake_case input both reach it,
because kernelToAuthoring normalizes the declaration before preflight runs.

Tests

packages/sdk/tests/preflight-permissions-unenforced.test.ts (new, 16 cases):

  • table over {}, each field alone, empty arrays, and all three together —
    exactly one warning per declaring step, correct stepId, the declared field
    names in stable order, no values echoed, and the readonly sentence present
    only for readonly;
  • one warning per declaring step in a multi-step flow, silence for an agent step
    that declares nothing and for deterministic/llm steps;
  • a malformed declaration still refuses invalid_spec and warns about nothing;
  • the warning accompanies a cli_unresolved refusal with no probe invoked;
  • the kernel snake_case round trip (toKernelSpec → kernelToAuthoring) keeps
    the declaration, including {};
  • end-to-end runCli(['check', …]): exit 0, WARNING [permissions_unenforced]
    on stderr, and under --json the diagnostic in the report with stdout still a
    single parseable JSON object;
  • checkAuthoredFlow data-API coverage, labelled in the test as data API only —
    an arbitrary f.agent(..., { permissions }) call inside a TypeScript body is
    not inspected at authoring time and is outside this warning's reach.

packages/sdk/tests/preflight.test.ts — the existing covenant-2 reachability
test ("reaches every declared warning kind") gains a scenario for the new kind;
it asserts set equality with PREFLIGHT_WARNING_KINDS, so it fails closed on any
kind added without a producing path.

Results

  • npm --prefix packages/sdk test — 2077 passed, 18 failed. The 18 failures
    are identical, test-for-test, to the pre-change baseline on this branch
    (live-kernel, mcp, provider-trigger-executor, webhook-live,
    authored-node-runtime): they spawn kernel/target/{debug,release}/relayflowd,
    a path that does not exist in this sandbox because ops/cargo.sh points
    CARGO_TARGET_DIR outside the repo. Baseline: 2061 passed / 18 failed; with the
    change: 2077 passed / 18 failed — the delta is the 16 new tests, all passing.
  • sh ../ops/cargo.sh test -p relayflowd-core — 79 passed, 0 failed, including
    spec_parity and the canonical corpus. No kernel behaviour changed.
  • Mutation-verified: deleting the permissionsDiagnostics(compiled) call in
    preflight.ts turns 15 of the 73 tests in the two files red (including the
    reachability test); restoring the file byte-for-byte
    (sha256 09777cf300aec48b5c4284be4106534f385630969f83bb11a9efe7549d22d6d1)
    returns all 73 to green.

What this does not do

It does not enforce anything. A flow that declares permissions has exactly the
same runtime behaviour as before; the only change is that flows check now says
so out loud. Real enforcement — read/write split, deny list, .agentignore
merge, relayfile fs:read/fs:write scopes — is gate 8 (#442) and is
unaffected by this PR.


[!NOTE]
Low Risk
Preflight-only additive warnings and documentation fixes; no change to runtime permission enforcement or kernel behavior.

Overview
flows check now warns when declarative agent steps declare permissions that are not enforced at runtime.

Preflight adds a permissions_unenforced warning (warning-only; check still passes) for each agent step with a permissions block—including {} and empty arrays—via new permissionsDiagnostics in permissions-preflight.ts, wired early in preflight so it runs even when other checks refuse. Messages name declared field keys (not glob/host values) and call out that accessPreset: 'readonly' does not prevent writes.

Docs are corrected in PermissionsSpec (spec.ts and flows.schema.json): permissions are validated and recorded but not enforced (gate 8 / #442). The same docs note that .flow.ts body permissions are not inspected at check time, so a clean TypeScript check can still hide declarations.

Runtime sandboxing is unchanged; tests cover preflight, CLI/--json, and the TypeScript check blind spot.

Reviewed by Cursor Bugbot for commit 0889aacd71b6a3a31f2df8c755fefd353e07b596. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

flows check now warns when a declarative agent step declares permissions, because those declarations are validated and recorded but never enforced. Previously a permissions block passed silently and made the flow look sandboxed when it was not; now each declaring step emits a permissions_unenforced warning and the check still passes.

Behavior

  • Warns once per agent step that declares permissions in YAML/JSON or a FlowSpec passed to the check API, including empty {} and empty arrays, and names the declared fields without echoing their values.
  • Calls out that accessPreset: 'readonly' does not prevent writes.
  • Leaves runtime behavior unchanged; enforcement remains gate 8 (#442).
  • Updates the PermissionsSpec doc comment and the regenerated flows.schema.json to state the block is not enforced and is not inspected inside authored .flow.ts bodies, so a clean check on TypeScript can still hide an unenforced declaration.

Agent Relay sessions

  • claude session aaea4db5 · contributor · pushed commits · last active 2026-09-19