refactor(agent): detect devcontainer via workspace marker, drop DEVSY_AGENT_IN_CONTAINER#622
Merged
Merged
Conversation
✅ Deploy Preview for devsydev canceled.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for images-devsy-sh canceled.
|
IsHostAgentInvocation decides per-workspace state layout: host (WorkspaceDir/agent, delete-stable) vs container (FindAgentHomeFolder glob). The layout must follow where the agent physically runs, which the orchestrator cannot know — a machine provider's exec command is an opaque template that may docker-exec into a container or ssh into bare metal. Only the running agent can tell, via container filesystem markers. The old predicate combined that runtime probe (isLikelyContainer) with an inline DEVSY_AGENT_IN_CONTAINER=1 env prefix set by every remote agent command builder. The env var was redundant: it was only ever set on commands that also run in a container (probe already true), and on a bare SSH machine it resolved to host via the probe regardless. So host = NOT(envPrefix AND isLikelyContainer) is equivalent, for every real caller, to host = NOT(isLikelyContainer) Drop the env var, the ContainerAgentEnvPrefix / AgentCommandEnvPrefix helpers, and their inline prefixes across all builders; keep the runtime probe and the explicit --agent-dir override. This also removes the misleading "env set but no container indicator" debug line, which was a legitimate, expected state on a bare SSH machine. Verified on the ws3-ssh provider: up and re-up behave identically to main (host layout preserved). Note: workspace logs on a bare SSH machine remains broken the same way it is on main (the agent runs on the host, which the logs guard rejects) — a pre-existing issue, unchanged by this refactor.
skevetter
force-pushed
the
fix/agent-in-container-detection
branch
from
July 8, 2026 13:08
381c33c to
98ad5b1
Compare
…tainer `devsy workspace logs` failed on the ws3-ssh (bare SSH machine) provider with "only valid inside the workspace container or machine". The command fetches the devcontainer's logs via the docker daemon (docker logs) and reads the per-workspace state — both available on the machine/host that hosts the container, not only inside it. The IsHostAgentInvocation guard was therefore too strict: on a bare SSH machine the agent runs on the host, which the guard rejected. Drop the guard for logs; it already reads workspace state via ReadAgentWorkspaceInfo (host or container layout) and errors clearly when the workspace is absent (the user's own CLI case). logs-daemon and the daemon command keep their guards — they read agent-daemon.log, which only exists where the daemon runs. Verified on ws3-ssh: logs now returns the container logs; and the docker machine-provider logs e2e still passes.
Signed-off-by: Samuel K <skevetter@pm.me>
Signed-off-by: Samuel K <skevetter@pm.me>
skevetter
marked this pull request as ready for review
July 8, 2026 14:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the misleading
DEVSY_AGENT_IN_CONTAINER=1 is set but no container indicator file found; treating as host invocationdebug line that appeared on every machine-provider (e.g.ws3-ssh)up, and replaces the fragile detection behind it.IsHostAgentInvocationselects the per-workspace state layout — host (WorkspaceDir/agent+ delete-stablecontents/<id>) vs. devcontainer (FindAgentHomeFolderglob). The old signal,DEVSY_AGENT_IN_CONTAINER=1, was an inline prefix set on every remote agent command — including on a bare SSH machine host, which is not a container. A filesystem probe (isLikelyContainer:/.dockerenv,/run/.containerenv,/proc/1/cgroup) was added to tell the machine host apart from the real devcontainer. That probe:up(the machine genuinely has no container markers), andChange
Detect the devcontainer via the authoritative marker
DEVSY_WORKSPACE_ID, which is injected into the container through each driver's run environment (docker-e/ kubernetes env) and is never set host-side. It distinguishes the devcontainer from both the user CLI and the SSH machine host directly, across all drivers — no filesystem probe.Removes the now-unnecessary
DEVSY_AGENT_IN_CONTAINERenv var, theContainerAgentEnvPrefix/AgentCommandEnvPrefixhelpers and all their inline command prefixes, andcontainer_detect.go. Net −334 lines. The explicit--agent-diroverride is preserved.Verification (end-to-end)
contents/<id>), misleading log gone, first + secondupsucceed, workspace usable over SSH.DEVSY_WORKSPACE_IDpresent inside the container, UID remap intact.upsucceeds; marker reaches the pod.cmd/...+pkg/agent+pkg/tunnelsuites, and diff-scoped lint all pass.