Fix broken context symlink in container workspaces

For chroot workspaces, the context symlink was pointing to the host path
(e.g., /root/.openagent/workspaces/xxx/context/mission-id) which doesn't
exist inside the container. Now it points to the container path
(/root/context/mission-id) where the directory is bind-mounted.

Also ensures the mission context directory is created on the host before
the container starts, so the bind mount isn't empty.
This commit is contained in:
Thomas Marchand
2026-01-17 13:58:32 +00:00
parent 407d2f8c16
commit c17a9f3891

View File

@@ -1431,12 +1431,25 @@ pub async fn write_runtime_workspace_state(
tokio::fs::create_dir_all(&runtime_dir).await?;
let context_root = working_dir_root.join(context_dir_name);
let mission_context = mission_id.map(|id| context_root.join(id.to_string()));
// Create the mission context directory on the host so it exists when bind-mounted
if let Some(target) = mission_context.as_ref() {
tokio::fs::create_dir_all(target).await?;
}
let context_link = working_dir.join(context_dir_name);
if let Some(target) = mission_context.as_ref() {
if !context_link.exists() {
#[cfg(unix)]
{
if let Err(e) = std::os::unix::fs::symlink(target, &context_link) {
// For chroot workspaces, the symlink must point to the container path
// since /root/context is bind-mounted, not the host path
let symlink_target = if workspace.workspace_type == WorkspaceType::Chroot {
PathBuf::from("/root")
.join(context_dir_name)
.join(mission_id.unwrap().to_string())
} else {
target.clone()
};
if let Err(e) = std::os::unix::fs::symlink(&symlink_target, &context_link) {
tracing::warn!(
workspace = %workspace.name,
mission = ?mission_id,