Skip to content

fix(sandbox): resolve an existing sandbox's spec with a default fallback - #965

Merged
hieptl merged 3 commits into
mainfrom
hieptl/ohe-3675-spec-helper
Oct 23, 2026
Merged

hieptl merged 3 commits into
mainfrom
hieptl/ohe-3675-spec-helper

Conversation

@hieptl

@hieptl hieptl commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

Runtime-api advertises only the current agent-server image, so after an image bump every sandbox created on the previous image has no sandbox spec. #903 fixed conversation start by falling back to the default spec. Four other places look up an existing sandbox's spec, and each handled the missing spec in its own way:

Caller On a missing spec
_get_agent_server_context default spec, generic warning without ids
read_conversation_file returned '', so PLAN.md came back blank
_restore_git_user_settings_after_resume raised, swallowed, identity never restored
_resolve_archive_path raised for conversations without a pinned workspace path

All five callers read exactly one field from the spec, working_dir, which the default spec shares for the stock images.

Summary

  • Add SandboxSpecService.resolve_existing_sandbox_spec(), next to get_default_sandbox_spec(): the sandbox's own spec when it is still advertised, otherwise the default spec plus a warning naming the image, the sandbox and the spec it picked. The docstring confines it to working_dir.
  • Use it in _start_app_conversation, _get_agent_server_context, read_conversation_file, _restore_git_user_settings_after_resume and _resolve_archive_path, replacing the five ad-hoc checks.
  • Tests for the helper and for each caller on a sandbox whose image is no longer advertised.

Issue Number

Refs #902, the second of the three PRs planned there (Linear OHE-3675). The grouping change is the third PR, opened separately.

How to Test

uv run pytest -q tests/unit/app_server/test_sandbox_spec_service.py \
  tests/unit/app_server/test_app_conversation_router.py \
  tests/unit/app_server/test_sandbox_resume_git_config.py \
  tests/unit/app_server/test_remote_sandbox_service.py \
  tests/unit/app_server/test_live_status_app_conversation_service.py

New tests, all of which fail on main:

  • test_resolve_existing_sandbox_spec_returns_the_sandbox_spec and test_resolve_existing_sandbox_spec_falls_back_to_the_default
  • TestReadConversationFile::test_reads_from_sandbox_whose_image_is_no_longer_advertised
  • test_restore_git_identity_in_sandbox_whose_image_is_no_longer_advertised
  • TestArchiveConversationWorkspace::test_resolve_archive_path_legacy_unadvertised_image

On a deployment after an agent-server bump: pick a sandbox still on the previous image and start a conversation in it with an explicit sandbox_id. GET /api/v1/app-conversations/{id}/file?file_path=/workspace/project/PLAN.md returns the file instead of an empty body, and after pausing and resuming the sandbox git config --global user.name inside it is set again. The app-server logs Sandbox spec <old image> not found for sandbox <id>; using default spec <current image> (working_dir=/workspace/project).

Video/Screenshots

None (backend only).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • working_dir is still not persisted on the sandbox row. If that is added later, this method is the one place that changes.
  • Archive trade-off: when archiving is required, a pre-pinning conversation in an old-image sandbox used to fail path resolution, which kept the sandbox for the idle reap. It now archives at the default spec's working_dir. A custom warm config with a different working_dir would make that path empty; the stock configs all use /workspace/project.
  • _get_agent_server_context logs the warning on every hooks/skills/files request for an old-image sandbox, as it already did with the generic message.

Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-181ec90

Runtime-api advertises only the current agent-server image, so after an
image bump every sandbox created on the previous image has no sandbox
spec. #903 handled that for conversation start. The other callers that
look up an existing sandbox's spec each handled the missing spec in their
own way: the conversation router fell back with a generic warning, the
file-read endpoint returned an empty string, the post-resume git identity
restore raised and was swallowed, and archive path resolution raised for
conversations without a pinned workspace path. All of them read only
working_dir from the spec, which the default spec shares.

- Add resolve_existing_sandbox_spec() next to resolve_sandbox_spec(): the
  sandbox's own spec when it is still advertised, otherwise the default
  spec plus a warning naming the image, the sandbox and the pick.
- Use it in _start_app_conversation, _get_agent_server_context,
  read_conversation_file, _restore_git_user_settings_after_resume and
  _resolve_archive_path.
- Cover the helper and each caller on a sandbox whose image is no longer
  advertised.

Refs #902
@hieptl hieptl added the type: fix A bug fix label Oct 22, 2026
@hieptl hieptl self-assigned this Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  app_conversation_router.py 1274
  live_status_app_conversation_service.py
  openhands/app_server/sandbox
  remote_sandbox_service.py
  sandbox_router.py 190
  sandbox_spec_service.py 62-63
Project Total  

This report was generated by python-coverage-comment-action

…cService

Make the existing-sandbox spec lookup a method on SandboxSpecService,
next to get_default_sandbox_spec, instead of a module-level helper that
takes the service as an argument. The warning now comes from the spec
service's own logger, so callers no longer pass one in.

Caller tests mock the new method; the tests for a sandbox whose image is
no longer advertised use a PresetSandboxSpecService, so they still run
the real fallback through each caller.
@hieptl
hieptl requested a review from tofarr October 23, 2026 03:58

@tofarr tofarr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍰

@hieptl
hieptl merged commit 5b77f70 into main Oct 23, 2026
22 checks passed
@hieptl
hieptl deleted the hieptl/ohe-3675-spec-helper branch October 23, 2026 09:57
@openhands-release-bot openhands-release-bot Bot added the released: 1.78.0 Shipped in 1.78.0 label Oct 23, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.78.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.78.0 Shipped in 1.78.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants