[PR #55] [CLOSED] fix(tools-image): guarantee localhost resolution for images with empty /etc/hosts #144

Closed
opened 2026-10-29 14:20:11 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kvcache-ai/AgentENV/pull/55
Author: @JoyboyBrian
Created: 7/29/2026
Status: ❌ Closed

Base: main ← Head: fix/guest-hosts-localhost


📝 Commits (6)

  • 644083f fix(tools-image): guarantee localhost resolution for images with empty /etc/hosts
  • 8eef2ac fix(tools-image): address localhost bootstrap review
  • 4a153b9 fix(tools-image): harden localhost bootstrap
  • cc1029c fix(tools-image): assert helper success in tests
  • 5928df5 chore(tools-image): clarify test host support
  • b163e2f fix(tools-image): simplify localhost bootstrap to inline pivot-init check

📊 Changes

2 files changed (+33 additions, -7 deletions)

View changed files

📝 scripts/tests/e2e/e2b_python_sdk_compat.py (+19 -0)
📝 tools-image/pivot-init (+14 -7)

📄 Description

Summary

Fix guest localhost resolution when an OCI image ships /etc/hosts as an empty placeholder or without canonical loopback mappings.

This PR:

  • replaces the existence-only /etc/hosts fallback in pivot-init with a small content-based check;
  • preserves existing image-provided entries and appends only missing 127.0.0.1 localhost or ::1 localhost mappings;
  • adds an E2B compatibility assertion covering the resulting guest state.

Problem

pivot-init currently initializes /etc/hosts only when the file does not exist:

if [ ! -e /etc/hosts ]; then
    ...
fi

Many OCI images—including ubuntu:22.04 and ubuntu:24.04—ship a zero-byte /etc/hosts because container runtimes normally replace it at startup. AgentENV boots the image as a VM and does not perform that container-runtime mount, so these guests can start without a usable localhost mapping.

For example:

getent -s files hosts localhost

exits with status 2 in an affected guest. A plain getent hosts localhost is not a reliable probe because an upstream DNS resolver may answer for localhost.

Change

At boot, pivot-init now:

  1. creates /etc if necessary;
  2. repairs a missing trailing newline before appending;
  3. checks independently for the canonical IPv4 and IPv6 mappings;
  4. appends only the mappings that are missing.

The check is idempotent across repeated boots and pause/resume cycles. Existing /etc/hosts content is retained.

The implementation intentionally remains a small inline bootstrap block. It does not introduce a separate helper, locking, or special symlink replacement policy; pivot-init has a single caller before user init.

Validation

  • Added an assertion to scripts/tests/e2e/e2b_python_sdk_compat.py that verifies the sandbox created from the built template contains a loopback-to-localhost mapping.
  • Manually verified on an x86_64 Firecracker host with ubuntu:24.04:
    • before: getent -s files hosts localhost exits 2;
    • after: files-source localhost resolution succeeds;
    • repeated boot and pause/resume do not add duplicate entries.

Tools-drive rollout

This PR changes tools-image source only. It does not publish a tools drive or bump [tools].version.

The published AgentENV v0.1.1 release still pins and bundles tools drive 0.1.0, so it does not contain this fix. Rolling the change out requires publishing a new immutable tools-drive version and updating config/deps_manifest.toml.

Existing snapshots remain pinned to the tools_drive_version recorded when they were created and are not modified or invalidated by that future manifest bump. Nodes that may restore historical snapshots must retain the corresponding historical tools-drive versions.

Changing snapshot-based template rebuilds to cold-boot with a newer tools drive, or automatically provisioning missing historical versions, is outside the scope of this focused fix.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kvcache-ai/AgentENV/pull/55 **Author:** [@JoyboyBrian](https://github.com/JoyboyBrian) **Created:** 7/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/guest-hosts-localhost` --- ### 📝 Commits (6) - [`644083f`](https://github.com/kvcache-ai/AgentENV/commit/644083f8b89810626d02b0048f5178c8f5572f27) fix(tools-image): guarantee localhost resolution for images with empty /etc/hosts - [`8eef2ac`](https://github.com/kvcache-ai/AgentENV/commit/8eef2ac814a2c8ee9a483e986dc19ff27633e3f3) fix(tools-image): address localhost bootstrap review - [`4a153b9`](https://github.com/kvcache-ai/AgentENV/commit/4a153b9d05d140b3625a8867bbdbd6ebf4985625) fix(tools-image): harden localhost bootstrap - [`cc1029c`](https://github.com/kvcache-ai/AgentENV/commit/cc1029c7f72a3016c31938997bd5d0a1135d1d39) fix(tools-image): assert helper success in tests - [`5928df5`](https://github.com/kvcache-ai/AgentENV/commit/5928df52aeb6515a41d901114307f54a1cd41e53) chore(tools-image): clarify test host support - [`b163e2f`](https://github.com/kvcache-ai/AgentENV/commit/b163e2ffdc8436ec273be0135eb1c794cb37e33c) fix(tools-image): simplify localhost bootstrap to inline pivot-init check ### 📊 Changes **2 files changed** (+33 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `scripts/tests/e2e/e2b_python_sdk_compat.py` (+19 -0) 📝 `tools-image/pivot-init` (+14 -7) </details> ### 📄 Description ## Summary Fix guest `localhost` resolution when an OCI image ships `/etc/hosts` as an empty placeholder or without canonical loopback mappings. This PR: - replaces the existence-only `/etc/hosts` fallback in `pivot-init` with a small content-based check; - preserves existing image-provided entries and appends only missing `127.0.0.1 localhost` or `::1 localhost` mappings; - adds an E2B compatibility assertion covering the resulting guest state. ## Problem `pivot-init` currently initializes `/etc/hosts` only when the file does not exist: ```sh if [ ! -e /etc/hosts ]; then ... fi ``` Many OCI images—including `ubuntu:22.04` and `ubuntu:24.04`—ship a zero-byte `/etc/hosts` because container runtimes normally replace it at startup. AgentENV boots the image as a VM and does not perform that container-runtime mount, so these guests can start without a usable `localhost` mapping. For example: ```sh getent -s files hosts localhost ``` exits with status 2 in an affected guest. A plain `getent hosts localhost` is not a reliable probe because an upstream DNS resolver may answer for `localhost`. ## Change At boot, `pivot-init` now: 1. creates `/etc` if necessary; 2. repairs a missing trailing newline before appending; 3. checks independently for the canonical IPv4 and IPv6 mappings; 4. appends only the mappings that are missing. The check is idempotent across repeated boots and pause/resume cycles. Existing `/etc/hosts` content is retained. The implementation intentionally remains a small inline bootstrap block. It does not introduce a separate helper, locking, or special symlink replacement policy; `pivot-init` has a single caller before user init. ## Validation - Added an assertion to `scripts/tests/e2e/e2b_python_sdk_compat.py` that verifies the sandbox created from the built template contains a loopback-to-`localhost` mapping. - Manually verified on an x86_64 Firecracker host with `ubuntu:24.04`: - before: `getent -s files hosts localhost` exits 2; - after: files-source `localhost` resolution succeeds; - repeated boot and pause/resume do not add duplicate entries. ## Tools-drive rollout This PR changes tools-image source only. It does not publish a tools drive or bump `[tools].version`. The published AgentENV `v0.1.1` release still pins and bundles tools drive `0.1.0`, so it does not contain this fix. Rolling the change out requires publishing a new immutable tools-drive version and updating `config/deps_manifest.toml`. Existing snapshots remain pinned to the `tools_drive_version` recorded when they were created and are not modified or invalidated by that future manifest bump. Nodes that may restore historical snapshots must retain the corresponding historical tools-drive versions. Changing snapshot-based template rebuilds to cold-boot with a newer tools drive, or automatically provisioning missing historical versions, is outside the scope of this focused fix. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 14:20:11 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/AgentENV#144
No description provided.