Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/scripts/slow_test_durations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Use a green ``main`` run: it has a ``junit-*`` artifact for every shard of the slow tier, the gateway tests, the unit
tier and the installer tier, which ``gh run download`` puts in a folder each. Each test's time counts toward its file,
or toward the test itself for a file the table names in ``split_by_test``; that list is kept as it is. A file the
or toward the test itself for a file the table names in ``split_by_test`` or ``split_in``, which are kept as they are. A file the
reports have no test of, such as one of a tier the run skipped, keeps the times the table had for it while it exists.
"""

Expand All @@ -30,7 +30,7 @@ def main() -> int:
args = parser.parse_args()

table = json.loads(args.table.read_text())
split = set(table.get("split_by_test", []))
split = set(table.get("split_by_test", [])) | set(table.get("split_in", {}))
seconds: dict[str, float] = defaultdict(float)
for report in args.reports:
for case in ET.parse(report).getroot().iter("testcase"):
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ and deserialized through a registry.
| `explorer/` | Optional local web UI: `agent-env up`, binds loopback `:8234`. |
| `cli/` | Click CLI with the groups `a2a-agent`, `artifact`, `bundle`, `config`, `env`, `eval`, `plugin`, `run`, `task`, `up`. `task run`, `task run-batch` and `eval run` hand their runs to the configured `[runner]` and follow them. |
| `agents/` | The `agents` bundle: the agents agent-env ships, one folder each under `agents/agents/`, with a smoke task each under `agents/tasks/`. Its Claude Code, `@local/agentenv-framework/agents/claude-code`, is the default agent. An agent's Python packages are its folder's `requirements.txt`, installed in its image, never in agent-env's own environment. A run that pulls one of its agents reads the whole bundle, so `tst/unit/bundle/shipped_bundles_test.py` parses and checks every shipped bundle. |
| `computers/` | The `computers` bundle: the base computers agent-env ships as `computer` artifacts, `ubuntu-24.04` (XFCE on Xvfb, settings as `AGENTENV_SETTING_<NAME>`; it starts as root, its container form's `start_as`, whose supervisord, `root.conf`, runs the clock follower as `agentenv-clock`, the egress proxy as `agentenv-egress` (`utils/egress_proxy/`, a Go program its Dockerfile builds and tests, on real time, through which every session program goes out, so a live site loads at any universe date: it passes a site's TLS through when the universe is inside the site's certificate, else re-signs it with the computer's own CA, minted at boot and valid from 1950 to 9999, handshaking with the site as the client did, and refuses any destination that isn't global) and the session's supervisord as the session user, which runs every session program; `root/` installs them at the build, `install.sh`, and starts them at boot, `init`; `ubuntu-24.04-browser`, the base of agent-env's website browsers, which takes the same clock and egress proxy, and ubuntu-24.04's `root/` and `root.conf`, through its `shared_sources.toml`), and `omarchy-4.5`, a disk alone built on the composing machine from Omarchy's own VM image (its `[forms.disk]` `source`) by `disk/omarchy/`'s recipe, its services systemd user units of the graphical session that start through `with-seed`, booted by the launcher as a `linux-desktop` guest (`env/envs/computer/utils/omarchy_disk.py`, on `thin_disk.py`, which Windows' disks use too), aliased through `[artifacts]`. It has no tasks either. `disk/linux/` is the Linux disk form's recipe: `boot/`, whose Dockerfile makes a disk form (a GPT disk of an EFI system partition holding one UKI, Ubuntu's kernel with a busybox initramfs whose init reads a NoCloud seed and `switch_root`s into the image's entrypoint, and an ext4 root filesystem that is a container image's, plus `/etc/agentenv/vm/image.env` from its OCI config), `tools/`, the disk tools that make it unprivileged on the builder's own platform (`mkfs.ext4 -d`), and `launcher/`, the QEMU launcher that boots one under KVM. A base's `[forms.disk]` with no image is made from its container form; the composer makes each arch's disk from its composed container, keeping the base disk's EFI system partition, keyed by the container's key, the base disk and the recipe; gate 3 probes it where a provider boots disks natively (`disk_image_platforms()`), and a deploy's first boot with KVM probes one left `unverified`; a deploy naming `form = "disk"` boots it through `create_vm(image=..., env=...)`, its settings in the seed. `utils/faketime_clock/` is the computer's clock, which each base takes through its `shared_sources.toml`: agent-env's build of libfaketime 0.9.12 (`libfaketime.patch` and the two `agentenv_clock_*.c` files it includes, GPL-2.0-only as libfaketime is, built by `build.sh` from upstream's sha256-pinned tarball, in a stage of the base's Dockerfile of its own) and the TLS shim, which `/etc/ld.so.preload` loads into every process and which fake only the session user's: clock reads and waits for a set clock time follow the page the follower (`clock-follower`) writes (`clockpage.py`), monotonic and relative waits staying real, with its default settings (`clock.conf`); `tst/clock` gates it. The follower long-polls the gateway's `/clock/watch` under the config core writes through the root channel when a multi env deploys the computer and after a reset (`env/envs/computer/utils/clock.py`), each time waiting on the computer's `sync_time` until it follows, a warning naming why when it doesn't (arming the clock refuses such a computer), and the driver serves `clock/v1` `sync_time` where the follower is (`agentenv_protocol.computer.clock`), not on a disk guest, whose follower core can't reach. |
| `computers/` | The `computers` bundle: the base computers agent-env ships as `computer` artifacts, `ubuntu-24.04` (XFCE on Xvfb, settings as `AGENTENV_SETTING_<NAME>`; it starts as root, its container form's `start_as`, whose supervisord, `root.conf`, runs the clock follower as `agentenv-clock`, the egress proxy as `agentenv-egress` (`utils/egress_proxy/`, a Go program its Dockerfile builds and tests, on real time, through which every session program goes out, so a live site loads at any universe date: it passes a site's TLS through when the universe is inside the site's certificate, else re-signs it with the computer's own CA, minted at boot and valid from 1950 to 9999, handshaking with the site as the client did, and refuses any destination that isn't global) and the session's supervisord as the session user, which runs every session program, among them `clock-panel`, which has the panel's clock redraw when the universe clock is armed or jumps rather than up to a minute later; `root/` installs them at the build, `install.sh`, and starts them at boot, `init`; `ubuntu-24.04-browser`, the base of agent-env's website browsers, which takes the same clock and egress proxy, and ubuntu-24.04's `root/` and `root.conf`, through its `shared_sources.toml`), and `omarchy-4.5`, a disk alone built on the composing machine from Omarchy's own VM image (its `[forms.disk]` `source`) by `disk/omarchy/`'s recipe, its services systemd user units of the graphical session that start through `with-seed`, booted by the launcher as a `linux-desktop` guest (`env/envs/computer/utils/omarchy_disk.py`, on `thin_disk.py`, which Windows' disks use too), aliased through `[artifacts]`. It has no tasks either. `disk/linux/` is the Linux disk form's recipe: `boot/`, whose Dockerfile makes a disk form (a GPT disk of an EFI system partition holding one UKI, Ubuntu's kernel with a busybox initramfs whose init reads a NoCloud seed and `switch_root`s into the image's entrypoint, and an ext4 root filesystem that is a container image's, plus `/etc/agentenv/vm/image.env` from its OCI config), `tools/`, the disk tools that make it unprivileged on the builder's own platform (`mkfs.ext4 -d`), and `launcher/`, the QEMU launcher that boots one under KVM. A base's `[forms.disk]` with no image is made from its container form; the composer makes each arch's disk from its composed container, keeping the EFI system partition of the base's disk where it has one (its disk form's image, or the one published for it), else taking the recipe's own at the base's size, with no base disk made, keyed by the container's key, the base disk and the recipe; gate 3 probes it where a provider boots disks natively (`disk_image_platforms()`), and a deploy's first boot with KVM probes one left `unverified`; a deploy naming `form = "disk"` boots it through `create_vm(image=..., env=...)`, its settings in the seed. `utils/faketime_clock/` is the computer's clock, which each base takes through its `shared_sources.toml`: agent-env's build of libfaketime 0.9.12 (`libfaketime.patch` and the two `agentenv_clock_*.c` files it includes, GPL-2.0-only as libfaketime is, built by `build.sh` from upstream's sha256-pinned tarball, in a stage of the base's Dockerfile of its own) and the TLS shim, which `/etc/ld.so.preload` loads into every process and which fake only the session user's: clock reads and waits for a set clock time follow the page the follower (`clock-follower`) writes (`clockpage.py`), monotonic and relative waits staying real, with its default settings (`clock.conf`); `tst/clock` gates it. The follower long-polls the gateway's `/clock/watch` under the config core writes through the root channel when a multi env deploys the computer and after a reset (`env/envs/computer/utils/clock.py`), each time waiting on the computer's `sync_time` until it follows, a warning naming why when it doesn't (arming the clock refuses such a computer), and the driver serves `clock/v1` `sync_time` where the follower is (`agentenv_protocol.computer.clock`), not on a disk guest, whose follower core can't reach. |
| `utils/faketime_clock/`, `utils/egress_proxy/` | Sources several shipped images share, each built into the image from its own context: `faketime_clock/` (agent-env's libfaketime, the TLS shim, the clock page and the clock follower) and `egress_proxy/` (the egress proxy). An image's folder names what it takes in its `shared_sources.toml` (`clock = "utils/faketime_clock"`, paths under `src/agent_env`, at the name its Dockerfile copies from), and its build context (`utils/docker/context.py`, and release CI's `infra_build.py`) holds each at that name, so the image still builds from one self-contained context and its source hash covers what it takes. A fix lands once, in every image that takes it. |
| `browsers/` | The `browsers` bundle: the website browsers agent-env ships, today `chromium`, a `computer_app` env (Chrome for Testing at the build Playwright pins, for amd64 and arm64, set up for unattended use by managed policies in `/etc/opt/chrome_for_testing/policies/managed`, opened at boot on its `start_urls`, its profile its data). All of it, its pin, install step, policies and command, is in `envs/chromium/chromium.py`; `tst/integration/computer/chromium_app_test.py` runs it. Like `drivers`, it has no tasks. |
| `drivers/` | The `drivers` bundle: the computer drivers agent-env ships as `computer_driver` envs, the reference driver (X11 on Linux, recording through `x11grab`) aliased `reference`, the page driver aliased `page`, a browser computer's, whose screen is the browser's active tab and which serves Playwright MCP's `browser_*` tools beside `computer_*` from a Playwright MCP it runs attached to the browser over a CDP address the relay issues it (`browser_evaluate` and `browser_run_code_unsafe` hidden by default; each call an entry in the browser's log, begun and ended with `browser/v1` `calls/begin` and `calls/end`, that its CDP commands name as `for`; `scripts/upgrade_playwright_mcp.py` pins its version), and trycua's cua-driver aliased `cua-driver` (its daemon from the pinned PyPI wheel, its own instructions, tools and skill resources served to agents through `@server_instructions`, `forwarded_tools` and `@resource`, its tools beside `computer_*`, `computer/v1` on its desktop-scope calls, its skill pack leading the computer skill; `tst/integration/computer/cua_driver_test.py` runs it). It has no tasks: a bundle with neither tasks nor evals is refused unless its `aliases.toml` names something for other bundles to use. The shipped `desktop` example composes it with the `ubuntu-24.04` base into a computer env, which `tst/integration/computer/` deploys, probes, records and has an agent use. |
Expand Down
4 changes: 3 additions & 1 deletion src/agent_env/computers/artifacts/ubuntu-24.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#
# The universe clock (clock/): agent-env's libfaketime and its TLS shim, built in a stage of their own so no compiler is
# left in the image, are preloaded into every process and fake only the session user's, from the clock page the
# follower writes, which the session user can read but neither write nor replace.
# follower writes, which the session user can read but neither write nor replace. The session's clock-panel has the
# panel's clock redraw whenever that clock is armed or jumps.
#
# The egress proxy (egress/), on real time, which every session program goes out through, so a live site loads at any
# universe date: built and tested in a stage of its own, so no Go toolchain is left in the image.
Expand Down Expand Up @@ -44,6 +45,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
COPY --from=clock /out/libfaketimeMT.so.1 /out/libtls_realtime.so /usr/local/lib/agentenv-clock/
COPY clock/clockpage.py clock/clock-follower /usr/local/lib/agentenv-clock/
COPY clock/clock.conf /etc/agentenv/clock.conf
COPY clock-panel /usr/local/lib/agentenv-clock/clock-panel
COPY --from=egress /out/egress /usr/local/lib/agentenv-egress/egress
COPY root/ /usr/local/lib/agentenv-root/
RUN sh /usr/local/lib/agentenv-root/install.sh user
Expand Down
127 changes: 127 additions & 0 deletions src/agent_env/computers/artifacts/ubuntu-24.04/clock-panel
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/python3 -I
"""The desktop panel's clock on the universe's clock. XFCE's clock plugin redraws on a timer of its own, a minute of
real time, so when the universe clock is armed or jumps it shows the old time until that timer fires, up to a minute
later, and the timer keeps its old phase, so the universe's next minute shows late too. This session program reads the
clock page the follower writes (``clockpage.py``) and, when the universe moves by a second or more or its rate changes,
has each clock on the panel redraw at once and again at the universe's next minute; while the clock runs at a rate
other than 1, at every universe minute, at most once a second. A clock whose time zone is unset or the local zone's name
shows local time either way, so a redraw moves it to the other and back: two changes the plugin redraws on, which leave
the panel's config as it was, and a redraw cut short between them leaves it in one of the two, which the next redraws.
A clock given another zone is left alone. It runs on real time (the clock's real-time marker), against which the page
anchors the universe."""
import json
import os
import re
import subprocess
import sys
import time

sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import clockpage # noqa: E402

ZONE = os.environ.get("AGENTENV_CLOCK_ZONE", "/etc/timezone")
POLL_S = 0.25
#: A write that moves the universe by less (the follower re-anchoring on a new offset) isn't a jump.
MOVED_NS = 1_000_000_000
#: The least time between two redraws.
GAP_NS = 1_000_000_000
MINUTE_NS = 60_000_000_000
PLUGIN = re.compile(r"/plugins/plugin-\d+")


def log(event: str, **fields) -> None:
sys.stdout.write(json.dumps({"event": event, "real": time.time(), **fields}) + "\n")
sys.stdout.flush()


def read(fd: int) -> tuple | None:
"""The page's (armed, universe_ns, anchor_ns, rate), None while it's being written or isn't a page."""
raw = os.pread(fd, clockpage.LAYOUT.size, 0)
if len(raw) < clockpage.LAYOUT.size:
return None
magic, version, seq, universe, anchor, rate, armed, _, generation, check, mono_universe, mono_anchor = (
clockpage.LAYOUT.unpack(raw))
if (magic, version) != (clockpage.MAGIC, clockpage.VERSION) or seq & 1 or check != clockpage.check(
seq, universe, anchor, rate, armed, generation, mono_universe, mono_anchor):
return None
return armed, universe, anchor, rate


def universe_at(state: tuple, now_ns: int) -> int:
armed, universe, anchor, rate = state
if not armed:
return now_ns
if rate == 0 or now_ns <= anchor:
return universe
return universe + int((now_ns - anchor) * rate)


def moved(old: tuple | None, new: tuple, now_ns: int) -> bool:
"""Whether the panel shows the wrong time after ``new`` replaced ``old``: at first sight, when it's armed."""
if old is None:
return bool(new[0])
return ((old[0], old[3]) != (new[0], new[3])
or abs(universe_at(new, now_ns) - universe_at(old, now_ns)) >= MOVED_NS)


def next_minute(state: tuple, now_ns: int) -> int | None:
"""The real time of the universe's next minute, None while it's frozen."""
rate = state[3] if state[0] else 1.0
if rate <= 0:
return None
return now_ns + int((MINUTE_NS - universe_at(state, now_ns) % MINUTE_NS) / rate)


def xfconf(*args: str) -> str:
ran = subprocess.run(["xfconf-query", "-c", "xfce4-panel", *args], capture_output=True, text=True, timeout=10)
if ran.returncode:
raise RuntimeError(f"xfconf-query {' '.join(args)}: {ran.stderr.strip()[:200]}")
Comment on lines +76 to +78

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Clock limits lack names. xfconf hardcodes a 10-second timeout and a 200-character error limit; redraw adds a separate 300-character limit. The repository requires magic numbers to have descriptive names. Extract named limits so readers can tell what each controls and change them safely.

Rule Used: Store magic numbers as class or instance variables with descriptive names rather than using them inline in the code. (source)

Learned From
scaleapi/scaleapi#126388

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/computers/artifacts/ubuntu-24.04/clock-panel
Line: 76-78

Comment:
**Clock limits lack names.** `xfconf` hardcodes a 10-second timeout and a 200-character error limit; `redraw` adds a separate 300-character limit. The repository requires magic numbers to have descriptive names. Extract named limits so readers can tell what each controls and change them safely.

**Rule Used:** Store magic numbers as class or instance variables with descriptive names rather than using them inline in the code. ([source](https://app.greptile.com/-/switch-tenant?tenant=scale-ai&next=%2Fcustom-context%3Fmemory%3D002e0051-41ad-46c1-9098-47433c580150))

**Learned From**
[scaleapi/scaleapi#126388](https://github.com/scaleapi/scaleapi/pull/126388)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Cursor Fix in Claude Code Fix in Codex

return ran.stdout


def redraw(why: str) -> None:
try:
listed = dict((path, value.strip()) for path, _, value in
(line.partition(" ") for line in xfconf("-p", "/plugins", "-l", "-v").splitlines()))
with open(ZONE) as f:
zone = f.read().strip()
clocks = [path for path, value in listed.items() if PLUGIN.fullmatch(path) and value == "clock"
and listed.get(f"{path}/timezone", zone) == zone]
for path in clocks:
if f"{path}/timezone" in listed:
xfconf("-p", f"{path}/timezone", "-r")
xfconf("-p", f"{path}/timezone", "-n", "-t", "string", "-s", zone)
else:
xfconf("-p", f"{path}/timezone", "-n", "-t", "string", "-s", zone)
xfconf("-p", f"{path}/timezone", "-r")
log("redrawn", why=why, clocks=clocks)
except (OSError, RuntimeError, subprocess.SubprocessError) as e: # no panel or bus yet: the next change tries again
log("error", why=why, error=f"{type(e).__name__}: {e}"[:300])


def main() -> None:
log("start", pid=os.getpid())
fd, state, due, redrawn = None, None, None, 0
while True:
if fd is None:
try:
fd = os.open(clockpage.PAGE, os.O_RDONLY)
except OSError:
time.sleep(POLL_S)
continue
page, now = read(fd), time.time_ns()
if page is not None and page != state:
jumped, state = moved(state, page, now), page
if jumped:
redraw("jump")
redrawn, due = now, next_minute(state, now)
if due is not None and now >= max(due, redrawn + GAP_NS):
redraw("minute")
redrawn = now
due = next_minute(state, now) if state[0] and state[3] != 1 else None
wake = POLL_S if due is None else min(POLL_S, max(0.0, (max(due, redrawn + GAP_NS) - now) / 1e9))
time.sleep(wake)


if __name__ == "__main__":
main()
Loading
Loading