Skip to content

[OSS→OHE parity] Resolve cwd and plan artifact consistently for grouped/provider workspaces #849

Open

Description

@neubig

In plain words

OSS: The file list and Plan → Build always find the project folder and the plan file.
OHE: For some workspaces, such as GitLab, Azure or grouped launches, the file list and Plan → Build look in the wrong folder.

Outcome and scope

Inventory: G05, G13. Feature IDs: F05.slash-plan-code, F05.plan-preview, F05.build-plan-shortcut, F08.files-workspace-path, F08.files-tree.

Make launch-resolved cwd/project root and planner artifact authoritative for tenant metadata, file listing/reads and Preview→Build. Grouped launches can use conversation-id directories; GitLab/Azure use agents-tmp-config/PLAN.md while Canvas assumes .agents_tmp/PLAN.md. Do not reconstruct locations from sandbox base plus repo name.

Pinned source evidence

  • # Setup working dir based on grouping
    sandbox_grouping_strategy = await self._get_sandbox_grouping_strategy()
    working_dir = grouped_workspace_dir(
    sandbox_spec.working_dir,
    sandbox_grouping_strategy,
    conversation_id.hex,
    )
    # Run setup scripts
    remote_workspace = AsyncRemoteWorkspace(
    host=agent_server_url,
    api_key=sandbox.session_api_key,
    working_dir=working_dir,
    )
    async for updated_task in self.run_setup_scripts(
    task, sandbox, remote_workspace, agent_server_url, conversation_id
    ):
    yield updated_task
    # Resolve the provider before the agent-server starts the
    # conversation, so the save below is not delayed while the
    # "started" webhook may already be writing the row. The agent
    # gets the same provider, so its PLAN.md path matches the one
  • def _compute_plan_path(
    self,
    working_dir: str,
    git_provider: ProviderType | None,
    ) -> str:
    """Compute the PLAN.md path based on provider type.
    Args:
    working_dir: The workspace working directory
    git_provider: The git provider type (GitHub, GitLab, Azure DevOps, etc.)
    Returns:
    Absolute path to PLAN.md file in the appropriate config directory
    """
    # GitLab and Azure DevOps use agents-tmp-config (since .agents_tmp is invalid)
    if git_provider in (ProviderType.GITLAB, ProviderType.AZURE_DEVOPS):
    config_dir = 'agents-tmp-config'
    else:
    config_dir = '.agents_tmp'
    return f'{working_dir}/{config_dir}/PLAN.md'
  • def _resolve_workspace_dir(path: str | None, ctx: AgentServerContext) -> str:
    """Resolve the directory to list files in.
    The caller may pass ``path`` (e.g. the value the frontend computed from its
    working-dir convention), but that convention does not always match the
    runtime's actual working directory — different deployments clone the repo
    at ``{working_dir}/{repo_name}``, ``{working_dir}/{conversation_id}``, or
    plain ``working_dir``. The authoritative project root is derived from the
    sandbox spec's ``working_dir`` and the conversation's
    ``selected_repository`` (the same resolution the skills/hooks endpoints
    use), so prefer it. ``path`` is only honored when it points at a real
    subdirectory the runtime exposes — i.e. it is the resolved project dir or a
    descendant of it — which keeps "list a subdirectory of the workspace"
    working without ever listing outside the workspace.
    """
    project_dir = get_project_dir(
    ctx.sandbox_spec.working_dir, ctx.conversation.selected_repository
    )
    if not path:
    return project_dir
    # Accept the caller's path only when it is the resolved project dir or a
    # descendant of it, so "list a subdirectory of the workspace" still works
    # without ever listing outside the conversation's project. The bare
    # ``working_dir`` is deliberately NOT a candidate when a repository is
    # selected: it is a *parent* of the clone, so treating it as an anchor
    # would accept any sibling path (e.g. ``/workspace/project`` under
    # ``/workspace``) and list the wrong — often nonexistent — directory.
    base = project_dir.rstrip('/')
    normalized = path.rstrip('/')
    if normalized == base or normalized.startswith(base.rstrip('/') + '/'):
    return path
    return project_dir
    def _resolve_file_path(file_path: str, ctx: AgentServerContext) -> str:
    """Resolve a file path to an absolute path inside the conversation's project.
    The runtime's ``/api/file/download`` requires an **absolute** path and does
    not join it with the workspace's ``working_dir``, so the path we hand it
    must already point at the right place. The frontend builds its request path
    as ``{workspaceRoot}/{relativePath}``, where ``relativePath`` is correct
    (it comes from the ``/files`` tree, which is relative to the real project
    dir) but ``workspaceRoot`` is the frontend's working-dir convention. When
    the cloud conversation response does not expose ``workspace.working_dir``
    that convention falls back to ``{DEFAULT_WORKING_DIR}[/{repoName}]`` (e.g.
    ``/workspace/project/enterprise``), which does not match the runtime's
    actual clone location (``{working_dir}/{repo_name}``, e.g.
    ``/workspace/enterprise``). The download then 404s and the endpoint
    silently returns ``""``.
    This remaps the path onto the authoritative project dir derived from the
    sandbox spec (the same ``get_project_dir`` resolution used by
    ``_resolve_workspace_dir`` and the skills/hooks endpoints):
    * an absolute path already inside the project dir is used as-is;
    * an absolute path rooted at a stale frontend default is re-anchored by
    stripping the stale root prefix (longest match first, so
    ``/workspace/project/enterprise`` is preferred over ``/workspace``) and
    re-joining under the project dir;
    * a relative path is joined under the project dir (the runtime rejects
    relative paths, so this also fixes that case).
    """
    working_dir = ctx.sandbox_spec.working_dir
    repo_name = (
    ctx.conversation.selected_repository.split('/')[-1]
    if ctx.conversation.selected_repository
    else None
    )
    project_dir = get_project_dir(working_dir, ctx.conversation.selected_repository)
    if not file_path:
    return project_dir
    normalized = file_path.rstrip('/')
    if not normalized.startswith('/'):
    # Relative path: anchor under the project dir.
    return f'{project_dir}/{normalized}'
    project_base = project_dir.rstrip('/')
    if normalized == project_base or normalized.startswith(project_base + '/'):
    # Already inside the real project dir.
    return file_path
    # The path is absolute but not under the project dir. It is likely rooted
    # at one of the frontend's stale defaults; strip the longest matching
    # stale root and re-anchor under the project dir. Ordered longest-first so
    # a more specific root (``/workspace/project/enterprise``) wins over its
    # parent (``/workspace/project``), and the bare ``working_dir`` (which is
    # a parent of the clone) is only a last resort.
    stale_roots: list[str] = []
    if repo_name:
    stale_roots.append(f'{working_dir}/project/{repo_name}')
    stale_roots.append(f'{working_dir}/project')
    stale_roots.append(working_dir)
    for root in sorted({r.rstrip('/') for r in stale_roots}, key=len, reverse=True):
    if normalized == root or normalized.startswith(root + '/'):
    remainder = normalized[len(root) :].lstrip('/')
    return f'{project_dir}/{remainder}' if remainder else project_dir
    # No recognizable root; let the runtime reject it (returns "").
    return file_path
  • https://github.com/OpenHands/OpenHands/blob/852132d38dbc15e03d6825bbacbeb971c72575be/src/utils/plan-file.ts#L1-L80

Source audit only, not a deployed-OHE test result. Canvas pins Agent Server 1.55.1 (minimum 1.51.0); Enterprise Python dependencies pin 1.50.1. Record actual app/runtime images and client versions before interpreting capability failures; Python dependencies do not establish deployed sandbox version.

Dependencies and delivery order

OpenHands/software-agent-sdk#6079; reconcile no-repo OpenHands/OpenHands#18108 and producer PR enterprise#684 first. Enterprise → SDK → Canvas.

Acceptance

  • Expose actual resolved cwd/root and plan artifact via authorized typed contract; preserve correct planner inheritance and resume/reload.
  • Repo/no-repo launches under NO_GROUPING and all supported grouping strategies list/read the same files and honor subdirectories without sibling access.
  • GitHub/GitLab/Azure Preview and Build consume exactly the file planner wrote; cover existing/missing plan, default/profile launch and reload.
  • Containment tests cover .., canonical/symlink escape and user/org isolation; never loosen root fences to accommodate guesses.
  • Use shared SDK contract, minimal Canvas path migration and disposable provider/grouping OHE validation after compatible rollout.

Duplicate reconciliation and non-goals

#18108 and enterprise#684 explicitly exclude grouping. Existing planner/profile work does not supply provider/grouped plan-file contract.

No profile/configuration/Apps/automation expansion. Do not duplicate SDK primitives or put backend/version compatibility into Canvas. Live validation needs authorized disposable OHE user/org/repository/runtime fixtures and redacted evidence, never credentials/customer data. Filing does not authorize deployment or production testing.

Created by OpenHands (AI agent) on behalf of Graham Neubig.

Activity

  1. added
    oss-ohe-parity
    on Oct 18, 2026
  2. juanmichelini commented on Nov 4, 2026

    @juanmichelini
    Contributor

    @OpenHands please fix this. once you are done please label the PR with verify-this label

  3. openhands-ai commented on Nov 4, 2026

    @openhands-ai

    I'm on it! juanmichelini can track my progress at all-hands.dev

  4. openhands-ai commented on Nov 4, 2026

    @openhands-ai

    I fixed issue #849 ([OSS→OHE parity] Resolve cwd and plan artifact consistently for grouped/provider workspaces) and opened PR #1168 with the verify-this label applied as requested.

    What changed

    The core problem: the Files tab, file reads, skills hooks, and Preview→Build reconstructed workspace locations from the sandbox-spec base plus a repo name. That is wrong under any grouping strategy that nests the workspace under the conversation id, and the provider-aware PLAN.md path wasn't exposed through a typed contract.

    Backend (openhands/app_server/app_conversation/):

    • Added shared compute_plan_path() + PLAN_* constants (.agents_tmp/PLAN.md for GitHub/default, agents-tmp-config/PLAN.md for GitLab/Azure DevOps). The launch service's _compute_plan_path now delegates to it, so the router and the planner agree on exactly one path.
    • Added _conversation_working_dir() that reads the launch-pinned archiveworkspacepath tag (falling back to the sandbox-spec base for legacy rows), and routed /files, /file, and the skills-hooks endpoints through it + _select_root. Now list/read honor subdirectories without sibling access under both NO_GROUPING and grouped strategies.
    • Added a typed GET /{conversation_id}/plan contract (ConversationPlanArtifact: path/exists/content) so Preview→Build consume exactly the file the planner wrote. With no file_path, /file defaults to that same resolved plan artifact.
    • Canonicalized the /files path so .. traversal and sibling directories cannot escape the selected repository's root — root fences are never loosened to accommodate guesses.

    Tests

    Added tests/unit/app_server/test_app_conversation_plan_and_grouped_roots.py (26 tests) covering: grouped vs NO_GROUPING cwd resolution, containment (.. traversal, sibling denial, unknown-folder 404, cross-conversation isolation, escape passthrough), compute_plan_path per provider, the /plan contract (success/missing/paused-409/unreachable-404/read-error), and /file default → resolved plan. Also fixed existing TestReadConversationFile mocks to carry a real tags dict.

    All 480 related tests pass and pre-commit (ruff, ruff-format, mypy) is clean.

    Verification notes

    Per the issue's non-goals, live disposable-OHE validation is explicitly out of scope (filing does not authorize deployment testing); behavior is covered by unit tests.

    PR: #1168 (labeled verify-this).

  5. juanmichelini commented on Nov 17, 2026

    @juanmichelini
    Contributor

    In plain words

    OSS: The file list and Plan → Build always find the project folder and the plan file.
    OHE: For some workspaces, such as GitLab, Azure or grouped launches, the file list and Plan → Build look in the wrong folder.

    This comment was posted by an AI agent (OpenHands) on behalf of juanmichelini, for the dev-coordinator status table on enterprise#1333.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    oss-ohe-parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions