| 1 | # Slice 5b: bounded per-file diffs |
| 2 | |
| 3 | Status: approved by the controller, 2026-11-26. ProtocolChangeDiffs = 35 (reallocated by the controller after main shipped 32, then Assistant files 33 and Places 34). |
| 4 | |
| 5 | ## Source and transport |
| 6 | |
| 7 | Use the runner's existing private Git object store, alongside Engineering's |
| 8 | `changeFiles` measurement in `internal/runner/thin/engineer.go`. The thin instance |
| 9 | relays candidate packs between runners; it does not maintain a forge clone |
| 10 | (`internal/equipo/chat/transfers.go`). Do not introduce instance forge credentials |
| 11 | or a new clone solely to display a diff. |
| 12 | |
| 13 | Prepare a bounded collection of display patches for the accepted Engineering |
| 14 | candidate, then upload it separately from the ordinary step/task view. This |
| 15 | makes a viewed diff available when the runner is offline and keeps device GETs |
| 16 | read-only. Bind every upload to instance, assigned runner, task, step, attempt, |
| 17 | base and candidate, with a digest and declared byte count. Validate all bindings |
| 18 | at acceptance; publish the collection only with its matching accepted report. |
| 19 | An interrupted collection remains unavailable and is pruned. Duplicate uploads |
| 20 | must match their digest and content; conflicting replacements are refused. |
| 21 | |
| 22 | This needs a new runner protocol capability and bounded chunk frames, following |
| 23 | the research-image transfer pattern, plus a small final-report reference. The |
| 24 | number must be allocated with the controller before code, considering other |
| 25 | open branches. Old runners and old steps keep the reviewed Amadan link. No |
| 26 | patches go into task lists, snapshots, events, the Coordinator tool or prompts. |
| 27 | The existing Review measurements and merge authority remain unchanged. |
| 28 | |
| 29 | ## Device endpoint and binding |
| 30 | |
| 31 | `GET /api/v1/tasks/{id}/changes/diff?candidate_sha=<sha>&path=<encoded-path>` |
| 32 | |
| 33 | Use exactly the task-read authority, including current membership. Resolve the |
| 34 | current candidate's latest Engineering step on the server. The requested path |
| 35 | must exactly match a validated change_files entry; derive base and rename source |
| 36 | from that entry, never from caller-supplied Git arguments. A candidate mismatch |
| 37 | returns a reviewed conflict; unknown or invisible tasks are indistinguishable. |
| 38 | The candidate and task visibility are checked again before returning bytes. |
| 39 | |
| 40 | Return task/step/attempt/base/candidate/path identity, status, old path if renamed, |
| 41 | and either bounded unified patch text or an explicit unavailable reason. |
| 42 | Flags distinguish truncation, binary content and secret withholding. Native |
| 43 | renders plain text, never HTML, and discards responses for a candidate or file |
| 44 | that is no longer selected. Responses use no-store and never offer a raw-file |
| 45 | or unredacted-download mode. New user-facing reasons require reviewed copy. |
| 46 | |
| 47 | ## Computation and bounds |
| 48 | |
| 49 | Only entries already included in the at-most-200-file facts listing are eligible. |
| 50 | Use the exact candidate against its recorded base, including the existing |
| 51 | verified initial-commit/empty-tree behavior. Read Git objects, not checkout paths; |
| 52 | never follow symlinks or submodules. Treat paths literally, with the shared path |
| 53 | validator (including U+061C), NUL-safe listing and no shell interpolation. |
| 54 | Disable hooks, external diff, textconv, filters, config discovery and network |
| 55 | access, following the existing trusted Git environment. Rename identity comes |
| 56 | from the measured entries, not a second heuristic applied to one path. |
| 57 | |
| 58 | Approved hard limits: 1 MiB per input blob, 8 MiB of input across a collection, |
| 59 | 200 files, 64 KiB and 2,000 lines of patch text per file, 2 MiB retained patch text |
| 60 | per candidate, and 128 KiB encoded JSON per device response. Process files in |
| 61 | stable path order. Apply a 10-second total collection deadline and one collector |
| 62 | per runner; cap unaccepted uploads per attempt and prune them after 15 minutes. |
| 63 | No unbounded subprocess buffering; kill and wait on timeout/overflow. Collection |
| 64 | failure must not fail Engineering or affect merging. |
| 65 | |
| 66 | Binary/non-UTF-8 files have metadata only. Large blobs, symlinks and submodules |
| 67 | link out without content. Oversized scanned text patches may end at a complete |
| 68 | line with truncated=true; omitted files get an explicit unavailable result, not |
| 69 | an empty diff. Native retains the file counts and the Amadan action throughout. |
| 70 | Accepted collections are replaced when the candidate changes and expire after |
| 71 | seven days; the task then falls back to Amadan. These display limits are separate |
| 72 | from the Review gate's evidence limits. |
| 73 | |
| 74 | ## Secret handling |
| 75 | |
| 76 | Scan complete bounded before/after blobs before generating or clipping patches. |
| 77 | Use the runner's pinned Gitleaks rules and trusted scanner setup already used by |
| 78 | Preview (`preview_security.go`); repository configs, ignores and inline allow |
| 79 | comments cannot weaken it. Also apply known credential-value and existing token |
| 80 | redaction checks. If a secret is detected, withhold that file's whole diff for |
| 81 | this slice. If scanning fails, times out or encounters an over-limit input, |
| 82 | withhold it as unavailable. Never ship a partially scanned prefix. |
| 83 | |
| 84 | The instance independently rechecks the bounded incoming patch with the same |
| 85 | trusted detection rules before persistence; a runner's clean flag is not proof. |
| 86 | Do not store rejected patch bytes, secret matches or raw scanner reports. Audit |
| 87 | identity, digest, outcome and sizes only. This reduces accidental disclosure; |
| 88 | pattern scanning cannot prove arbitrary source text contains no secret. |
| 89 | |
| 90 | ## Tests and approval points |
| 91 | |
| 92 | Test task visibility/revocation, stale candidate races, wrong runner/attempt and |
| 93 | upload replay, literal paths and renames, initial commits, binary/large files, |
| 94 | every byte/line/time cap, interrupted uploads, expiry, and old-runner fallback. |
| 95 | Secrets tests cover added/deleted/context lines, multiline keys, encoded values, |
| 96 | cut boundaries, scanner failure and hostile repository scanner configuration. |
| 97 | Mutate each guard. Add OpenAPI/contract coverage and a perf budget record; native |
| 98 | fake-server tests prove the selected file and candidate reach the endpoint. |
| 99 | |
| 100 | Controller decisions before implementation: approve precomputed runner patches |
| 101 | and their storage/retention bounds, allocate the protocol capability, and confirm |
| 102 | whole-file withholding for detected secrets. This note proposes no new copy. |
| 103 | |
| 104 | |
| 105 | ## Implementation refinements |
| 106 | |
| 107 | A complete 64 KiB file patch fits a single base64 durable frame under the |
| 108 | 256 KiB stream bound. There are no partial unscanned chunks in storage. The |
| 109 | collection hash binds every path, refusal, truncation flag and patch byte; its |
| 110 | matching accepted report publishes the collection transactionally. |
| 111 | |
| 112 | Both ends scan in memory with the pinned Gitleaks 8.30.1 embedded default rules, |
| 113 | using a fresh detector, a trusted configuration and no path-based exemptions. |
| 114 | No candidate files configure it. The library logger is disabled. Known-token |
| 115 | checks run on decoded layers too. Full before/after inputs are scanned on the |
| 116 | runner; the instance independently scans each complete patch before storage. |
| 117 | |
| 118 | Expired bytes are pruned by the existing sweep and during uploads. An internal |
| 119 | attempt-bound deadline remains on the step to distinguish expiry from an old |
| 120 | runner that never supplied a patch. It is never projected to the Coordinator. |
| 121 | |