Skip to content

Commit 9a1c5f6

Browse files
authored
Merge branch 'main' into data/541-usai-image-modalities
2 parents 8963606 + fcd94e5 commit 9a1c5f6

8 files changed

Lines changed: 706 additions & 8 deletions

File tree

‎docs/decisions/0003-repo-time-provider-catalog-refresh.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ documented command, and never produce or read harness-native configuration.
6969
(`recommendations`) and model order come from the existing catalog. If a
7070
recommended model has left the feed, the refresh fails and names each role; a
7171
person chooses the replacement.
72+
Verified `reasoning` and `inputModalities` values are curated in the same way:
73+
they are carried forward by model id (while the catalog has a valid
74+
`sources.capabilitiesVerified`), dropped only when their model leaves the
75+
feed (reported as drift), and never overwritten by the unverified
76+
`--include-capabilities` copy, which is refused while a verified value is
77+
carried. `sources.capabilitiesVerified` is carried, never advanced. Details:
78+
`integrations/providers/usai/README.md`.
7279

7380
## Scope
7481

‎integrations/isolation/acq-kits/opencode/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ OpenCode v2 platform package tarball**. Replaces acq's older unpinned MSB
66
fallback (`npm install -g opencode-ai`, resolves to the legacy 1.x line) with a
77
deterministic, version-pinned install.
88

9+
## Agent scratch directory
10+
11+
The install-time `opencode --version` checks run as root and can create
12+
`/tmp/opencode` with root ownership. On every sandbox startup, a root command
13+
creates or repairs that directory with ownership of the sandbox's `agent` user
14+
and group, resolved by name at startup (the numeric uid can differ from `1000`
15+
on some MSB images), and private permissions (`0700`). It fails closed if the
16+
`agent` user does not exist. This also handles a cleared `/tmp` after a restart.
17+
18+
The command changes only the directory itself, not existing contents, and
19+
refuses a pre-existing symlink or non-directory. It uses the same neutral
20+
startup command for both SBX and MSB. Existing sandboxes need the updated kit
21+
applied; this does not repair a sandbox merely by restarting OpenCode.
22+
923
## Provider Renderer Ownership
1024

1125
The kit stages its base policy at `/home/agent/opencode-config/base-config.jsonc`.

‎integrations/isolation/acq-kits/opencode/spec.yaml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ commands:
111111
OPENCODE_SHA256_LINUX_X64_BASELINE="c32f6fa1164ed09287519252f0c2d52ae356aec6dd5e32522e46c8fecba1bfcc" \
112112
OPENCODE_SHA256_LINUX_ARM64="96ead471c33ad1486c271d40486c438ff44eadabc25c1b65ee1437941e6ec9ce" \
113113
sh /home/agent/opencode-install.sh
114+
# Root's install-time --version probe can create OpenCode's scratch directory.
115+
# Prepare it on every start (including when /tmp was cleared), without
116+
# recursively changing existing contents or following a pre-existing symlink.
117+
- phase: startup
118+
user: "0"
119+
description: Prepare private OpenCode scratch directory for the agent user
120+
command:
121+
- sh
122+
- -c
123+
- |
124+
set -eu
125+
# Resolve ownership by name: acq may provision `agent` at a uid other
126+
# than the default (for example when that uid is already taken on an MSB image).
127+
if ! agent_uid=$(id -u agent 2>/dev/null) || ! agent_gid=$(id -g agent 2>/dev/null); then
128+
echo "opencode-kit(startup): user 'agent' not found; cannot prepare /tmp/opencode" >&2
129+
exit 1
130+
fi
131+
if [ -L /tmp/opencode ]; then
132+
echo "opencode-kit(startup): refusing symlink at /tmp/opencode" >&2
133+
exit 1
134+
fi
135+
if [ -e /tmp/opencode ] && [ ! -d /tmp/opencode ]; then
136+
echo "opencode-kit(startup): refusing non-directory at /tmp/opencode" >&2
137+
exit 1
138+
fi
139+
install -d -o "$agent_uid" -g "$agent_gid" -m 0700 /tmp/opencode
114140
# acq supplies ACQ_PROVIDER_INPUT_ROOT. It resolves to the same read-only
115141
# models/providers layout for every backend. This is the sole acq-owned writer
116142
# of OpenCode's global config after the cutover.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import test from "node:test"
2+
import assert from "node:assert/strict"
3+
import { chmod, lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises"
4+
import { spawnSync } from "node:child_process"
5+
import path from "node:path"
6+
import os from "node:os"
7+
8+
const spec = await readFile(new URL("../spec.yaml", import.meta.url), "utf8")
9+
const startup = spec.match(/ - phase: startup\n user: "0"\n description: Prepare private OpenCode scratch directory for the agent user\n command:\n - sh\n - -c\n - \|\n((?: .*\n)+)/)
10+
assert.ok(startup, "scratch directory preparation must be wired as a root startup command")
11+
const body = startup[1].replace(/^ /gm, "")
12+
13+
const idShim = `#!/bin/sh
14+
[ -n "$FAKE_UID" ] || exit 1
15+
[ "$2" = agent ] || exit 1
16+
case "$1" in -u) echo "$FAKE_UID" ;; -g) echo "$FAKE_GID" ;; *) exit 1 ;; esac
17+
`
18+
19+
// Records the requested ownership, then installs with the caller's real ids
20+
// (the test cannot chown to arbitrary ids without root).
21+
const installShim = `#!/bin/sh
22+
echo "$*" >> "$INSTALL_LOG"
23+
n=$#
24+
while [ "$n" -gt 0 ]; do
25+
a=$1; shift; n=$((n - 1))
26+
case "$a" in
27+
-o) shift; n=$((n - 1)); set -- "$@" -o "$REAL_UID" ;;
28+
-g) shift; n=$((n - 1)); set -- "$@" -g "$REAL_GID" ;;
29+
*) set -- "$@" "$a" ;;
30+
esac
31+
done
32+
exec /usr/bin/install "$@"
33+
`
34+
35+
async function fixture(t, { agent = { uid: process.getuid(), gid: process.getgid() } } = {}) {
36+
const root = await mkdtemp(path.join(os.tmpdir(), "opencode-tmp-test-"))
37+
t.after(() => rm(root, { recursive: true, force: true }))
38+
const directory = path.join(root, "opencode")
39+
const bin = path.join(root, "bin")
40+
const installLog = path.join(root, "install.log")
41+
await mkdir(bin)
42+
await writeFile(path.join(bin, "id"), idShim, { mode: 0o755 })
43+
await writeFile(path.join(bin, "install"), installShim, { mode: 0o755 })
44+
// Exercise real install/chmod without requiring root or touching /tmp/opencode.
45+
const command = body.replaceAll("/tmp/opencode", directory)
46+
const run = () => spawnSync("/bin/sh", ["-c", command], {
47+
env: {
48+
PATH: `${bin}:/usr/bin:/bin`,
49+
INSTALL_LOG: installLog,
50+
REAL_UID: String(process.getuid()),
51+
REAL_GID: String(process.getgid()),
52+
...(agent ? { FAKE_UID: String(agent.uid), FAKE_GID: String(agent.gid) } : {}),
53+
},
54+
encoding: "utf8",
55+
})
56+
const installCalls = async () => readFile(installLog, "utf8").catch(() => "")
57+
return { root, directory, run, installCalls }
58+
}
59+
60+
test("root startup resolves the agent's UID/GID by name without recursive changes", () => {
61+
assert.match(body, /id -u agent/)
62+
assert.match(body, /id -g agent/)
63+
assert.match(body, /install -d -o "\$agent_uid" -g "\$agent_gid" -m 0700 \/tmp\/opencode/)
64+
assert.doesNotMatch(body, /\b1000\b/)
65+
assert.doesNotMatch(body, /(?:chown|chmod)\s+-R/)
66+
assert.ok(spec.indexOf(startup[0]) < spec.indexOf("description: Render current provider inputs"))
67+
})
68+
69+
test("startup uses a non-1000 agent uid/gid reported by the sandbox", async (t) => {
70+
const { directory, run, installCalls } = await fixture(t, { agent: { uid: 2345, gid: 2346 } })
71+
const result = run()
72+
assert.equal(result.status, 0, result.stderr)
73+
assert.match(await installCalls(), /-d -o 2345 -g 2346 -m 0700 \S+\/opencode/)
74+
assert.ok((await stat(directory)).isDirectory())
75+
})
76+
77+
test("startup fails closed when the agent user does not exist", async (t) => {
78+
const { directory, run, installCalls } = await fixture(t, { agent: null })
79+
const result = run()
80+
assert.notEqual(result.status, 0)
81+
assert.match(result.stderr, /user 'agent' not found/)
82+
assert.equal(await installCalls(), "")
83+
await assert.rejects(stat(directory))
84+
})
85+
86+
test("startup creates a private writable directory and is idempotent", async (t) => {
87+
const { directory, run } = await fixture(t)
88+
for (let attempt = 0; attempt < 2; attempt++) {
89+
assert.equal(run().status, 0)
90+
const info = await stat(directory)
91+
assert.equal(info.uid, process.getuid())
92+
assert.equal(info.gid, process.getgid())
93+
assert.equal(info.mode & 0o777, 0o700)
94+
await writeFile(path.join(directory, "agent-output"), "synthetic output")
95+
}
96+
})
97+
98+
test("startup repairs directory permissions without changing existing contents", async (t) => {
99+
const { directory, run } = await fixture(t)
100+
await mkdir(directory)
101+
const file = path.join(directory, "existing-output")
102+
await writeFile(file, "preserved")
103+
await chmod(file, 0o640)
104+
await chmod(directory, 0o755)
105+
assert.equal(run().status, 0)
106+
assert.equal((await stat(directory)).mode & 0o777, 0o700)
107+
assert.equal(await readFile(file, "utf8"), "preserved")
108+
assert.equal((await stat(file)).mode & 0o777, 0o640)
109+
})
110+
111+
test("startup refuses symlinks without modifying their target", async (t) => {
112+
const { root, directory, run } = await fixture(t)
113+
const target = path.join(root, "unrelated")
114+
await mkdir(target)
115+
await chmod(target, 0o750)
116+
await symlink(target, directory)
117+
const result = run()
118+
assert.notEqual(result.status, 0)
119+
assert.match(result.stderr, /refusing symlink/)
120+
assert.ok((await lstat(directory)).isSymbolicLink())
121+
assert.equal((await stat(target)).mode & 0o777, 0o750)
122+
})
123+
124+
test("startup refuses a non-directory without replacing it", async (t) => {
125+
const { directory, run } = await fixture(t)
126+
await writeFile(directory, "preserved")
127+
assert.notEqual(run().status, 0)
128+
assert.equal(await readFile(directory, "utf8"), "preserved")
129+
})

‎integrations/providers/usai/README.md‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ What happens:
4242

4343
1. Both feeds are fetched **once** (https only, bounded time and size) into
4444
`tmp/usai-source/`, which is git-ignored.
45-
2. `catalog.json` is built from that pull. Role defaults and model order are
46-
carried forward from the existing catalog.
45+
2. `catalog.json` is built from that pull. Role defaults, model order and
46+
verified capability values are carried forward from the existing catalog.
4747
3. Every artifact in [`refresh-registry.json`](refresh-registry.json) is
4848
regenerated from the new catalog by its file-to-file generator.
4949
4. Only if every step succeeded are the files written. Nothing is committed.
5050
Review `git diff`, then commit as a normal change.
5151

5252
Check mode compares in a temporary directory and exits `1` on drift, naming the
53-
artifact and the models that were added, removed or changed. `sources` is not
53+
artifact and the models that were added, removed or changed (and, for capability
54+
values, the model and field that were added, changed or dropped). `sources` is not
5455
compared, because it records where a run read from, not what the catalog says.
5556

5657
### Offline and deterministic
@@ -127,6 +128,37 @@ rather than recomputing them.
127128
it fail with the message above, and `describeDrift` also names any role whose
128129
value differs between the two catalogs it compares.
129130

131+
## Verified capability values across a refresh
132+
133+
Verified `reasoning` and `inputModalities` values are curated data, like
134+
`recommendations`: the feeds never supply them, a person commits them with
135+
per-model evidence, and a regeneration carries them forward from the catalog at
136+
`--out`, keyed by model id. The neutral snapshot is regenerated from the result,
137+
so it carries them too.
138+
139+
- A model that is still in the feed keeps its values. A model that leaves the
140+
feed takes its values with it: the build names the model and fields on
141+
stderr, and `--check` reports them as drift (`capability values dropped with
142+
removed model: <id> (<fields>)`).
143+
- `sources.capabilitiesVerified` is the release reminder, not evidence. A refresh
144+
carries it unchanged while any verified value is carried, never writes or
145+
advances it, and drops it when no verified value remains.
146+
- Values are treated as verified only when the existing catalog has a valid
147+
`sources.capabilitiesVerified`. Without one they are not carried (a warning
148+
names how many) and `--check` reports them as dropped.
149+
- `--include-capabilities` is refused, before any write, whenever a verified
150+
value is carried and the upstream copy would either differ from it or add a
151+
value for a field that has no verified value. The message lists each model and
152+
field with the verified and upstream values. Mixing unverified values under a
153+
string that vouches for verified ones is the hazard; to compare upstream values,
154+
build to a scratch `--out` that has no verified values. With no verified value
155+
present the flag behaves as before and labels its output unverified.
156+
- `--check` reports capability values per model and field as `capability added`,
157+
`capability changed` or `capability dropped`, for the catalog and the snapshot.
158+
159+
To change a verified value, re-verify it and edit `catalog.json` by hand with its
160+
evidence file; the refresh never edits one.
161+
130162
## Files
131163

132164
- `catalog.schema.json` — JSON Schema (draft 2020-12), id

0 commit comments

Comments
 (0)