Skip to content

CONTRACT: fix(ui-server): leave workspaces/ out of the files_changed scope count - #4025

Merged
schlessera merged 3 commits into
mainfrom
fix/3793-workspaces-files-changed
Nov 15, 2026
Merged

schlessera merged 3 commits into
mainfrom
fix/3793-workspaces-files-changed

Conversation

@schlessera

Copy link
Copy Markdown
Owner

Closes #3793

What changed

A governed turn's files_changed scope cap no longer counts changed paths under workspaces/, so fetching or checking out a reference clone there no longer pauses a turn that changed nothing in the brain. The journal's observation facts gain workspacePaths: the changed paths contained in workspaces/ by isWithin (a SQL GLOB only narrows the candidates). The scope monitor caps changedPaths - workspacePaths. turn_bytes, the free-space floor and the scope summary's changedPaths (the turn disclosure) still count every workspace write. workspaces-old/x.md still counts.

Why this shape

This follows the maintainer's decision on #3793 (option 1). The summary's changedPaths keeps reporting every path, so the disclosure stays honest and the wire field keeps its documented meaning. Only the cap's count, carried in a private filesChanged on the live turn, leaves workspaces out. The containment is isWithin(BRAIN_WORKSPACES_DIR, path, { includeRoot: false }), the rule journal-steering.ts:73 uses for scoped entries, not a string prefix.

Contract (additive). onObservation is tagged @internal, but api-report records it because the journal's return type is inferred, and the tag only applies to class and interface members. Its facts gain one field, workspacePaths. That one-line api-report/ui-server.txt addition is documented in docs/integration-contract/package-api.md, with a minor changeset. No wire, HTTP or policy shape changes.

The native journal test fixture now streams its synthetic delta in bounded 64 KiB chunks, as the manager does. Before, it sent the whole delta as one chunk, and the parser refused a 1,500-file delta.

Docs: the G4 scope list and the scope-limit paragraph in docs/decisions/governed-writable-workers.md, and the scope row of the policy reference in docs/supported-inputs.md.

Proof

bun run check:pr --base origin/main   # passed, receipt below
bun run typecheck                     # clean
bun run build                         # clean
bun run test tests/api-surface.test.ts packages/ui-server/tests/turn-scope.test.ts packages/ui-server/tests/turn-scope-headroom.test.ts packages/ui-server/tests/reference-worktree-journal.test.ts

Failing first (on this tree, with only turn-journal.ts and turn-scope.ts reverted to origin/main):

  • files_changed leaves out a reference clone under workspaces/ … failed at WORKSPACE_CLONE_DOES_NOT_PAUSE_FILES_CHANGED: 1,500 workspace files raised a files_changed receipt.
  • workspace writes still count toward turn_bytes … failed at WORKSPACE_BYTES_PAUSE_TURN_BYTES_ONLY: the receipt was files_changed, not turn_bytes.
  • The updated shared snapshots … case failed: workspaces/shroud still counted as a changed path.

Mutations (each restored afterwards):

  1. Drop the exclusion (filesChanged = facts.changedPaths): the first test fails at WORKSPACE_CLONE_DOES_NOT_PAUSE_FILES_CHANGED.
  2. Swap isWithin for path.startsWith(BRAIN_WORKSPACES_DIR): the first test fails at BRAIN_PATHS_PAST_THE_CAP_STILL_PAUSE (expected count: 1001, received 1000), because workspaces-old/x.md stopped counting.

Acceptance criteria:

  • 1,500 workspace files, no brain file: no pause (WORKSPACE_CLONE_DOES_NOT_PAUSE_FILES_CHANGED). The summary still discloses ≥1,500 paths.
  • 999 brain files plus workspaces-old/x.md plus one more brain file: paused at files_changed, count: 1001, cap: 1000.
  • 2,048 bytes under workspaces/ with max_bytes_written: 1024 and max_files_changed: 1: paused on turn_bytes only.

Environment-only failures: turn-scope.test.ts has four failures in this sandbox: repeated ignored 100 MB …, both small tmpfs brain … cases and real host restart …. The same four fail on an unmodified origin/main worktree.

{"version":1,"kind":"brain-check-pr-receipt","head":"aa2bbd42435ff099d4dddcb6a1bed7423a9ddbb6","base":"origin/main","mode":"focused","startedAt":"2026-11-15T16:47:20.022Z","finishedAt":"2026-11-15T16:48:27.055Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12639.729349000001},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":108.33306199999788},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":67.43173200000092},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":19.301531000000978},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":54182.02304999999}]}

Proportionate containment

The files_changed scope cap is narrowed, not added.

  • Trigger and coverage: the cap now fires on changed paths outside workspaces/. Scratch growth under workspaces/ stays bounded by turn_bytes and the free-space floor, both unchanged.
  • What it restricts: the turn alone, as before.
  • How it clears: unchanged. The user chooses Continue (one finite grant) or Stop.
  • Where the cause is recorded: unchanged. The scope_cap governance event and the scope receipts record it.
  • Scope isolation: the per-turn tests are unchanged.

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Collisions

bun scripts/collisions.ts --json --paths <diff> at head aa2bbd424 reports path collisions with these open draft PRs:

Each overlap is a separate paragraph or line.

Anything left open

Nothing.

🤖 Generated with Claude Code

…scope count

A reference clone fetched or checked out under workspaces/ counted every
touched file against the turn's files_changed limit and paused interactive
turns that changed nothing in the brain (#3793).

The journal's observation facts now carry workspacePaths, the changed paths
contained in workspaces/ by isWithin (a GLOB only narrows the candidates, so
workspaces-old/ still counts). The scope monitor caps changedPaths minus
that count; turn_bytes, the free-space floor and the summary's changedPaths
still include workspace writes.

Contract: additive. The @internal onObservation observer is recorded in
api-report because the journal's type is inferred; its facts gain
workspacePaths. Documented in the package API component. No wire, HTTP or
policy shape changes.

The native journal test fixture now streams its synthetic delta in the same
bounded 64 KiB chunks as the manager, so a test can observe a 1,500-file
clone in one observation.

Closes #3793

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 15, 2026
@schlessera
schlessera marked this pull request as ready for review November 15, 2026 18:37
@schlessera
schlessera merged commit eb3c53a into main Nov 15, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: a reference clone under workspaces/ counts toward files_changed and pauses the turn

1 participant