fix(agent): default process working directory to agent dir or $HOME#23224
fix(agent): default process working directory to agent dir or $HOME#23224
Conversation
|
Actually, going to pipe through configured working directory from coder agent. |
cea4797 to
642aecf
Compare
7163a9e to
31cc520
Compare
| clock: quartz.NewReal(), | ||
| procs: make(map[string]*process), | ||
| updateEnv: updateEnv, | ||
| workingDir: workingDir, |
There was a problem hiding this comment.
How often is this likely to change during an agent lifecycle?
Could this just be a string?
There was a problem hiding this comment.
It needs to be a function. The processAPI is created once in agent.init() (line 388), but the manifest directory can change across reconnects since run() calls a.manifest.Swap() (line 1262) each time. A plain string would capture whatever value the manifest had at init time (empty, since the manifest has not been fetched yet).
The closure reads a.manifest.Load().Directory at process-start time, picking up the latest value. This is the same pattern SSH uses for WorkingDirectory at line 334.
The nil guard on the manifest (if m := a.manifest.Load(); m != nil) is the one difference from SSH, which dereferences without checking. The guard is there because processAPI is created in init() before run() populates the manifest. In practice the HTTP routes are unreachable until the manifest is loaded (the tailnet listener starts after manifestOK), but the guard costs nothing.
🤖 I traced the init path so you don't have to.
71cff44 to
e699e4c
Compare
e699e4c to
687bca8
Compare
Processes started via the agent process API inherited the agent's own working directory (/tmp/coder.xxx) when no WorkDir was specified. SSH sessions already use a fallback chain: configured agent directory > $HOME. This wires the same manifest directory closure into the process manager so the priority is now: explicit req.WorkDir > agent configured dir > $HOME The resolved directory is recorded on the process struct so ProcessInfo.WorkDir and pathStore notifications reflect where the process actually ran.
687bca8 to
400f726
Compare
Processes started via the agent process API inherited the agent's own working directory (
/tmp/coder.xxx) when noWorkDirwas specified. SSH sessions already use a fallback chain inagent/agentssh/agentssh.go:898-910: configured agent directory >$HOME. The process manager had no equivalent.This wires the same manifest directory closure into
agentproc.NewAPIso the resolved working directory priority is:req.WorkDirfrom the requestos.Stat)$HOMEThe resolved directory is recorded on the process struct so
ProcessInfo.WorkDirand pathStore git notifications reflect where the process actually ran, not just what was in the request.