fix(agent/agentscripts): create script log directories - #25545
Closed
puneetdixit200 wants to merge 1 commit into
Closed
fix(agent/agentscripts): create script log directories#25545puneetdixit200 wants to merge 1 commit into
puneetdixit200 wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
puneetdixit200
force-pushed
the
fix/script-log-path-parent
branch
2 times, most recently
from
May 23, 2026 16:35
00efdea to
382dbe8
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
cdrci2
added a commit
to coder/cla
that referenced
this pull request
May 24, 2026
Author
|
recheck |
puneetdixit200
force-pushed
the
fix/script-log-path-parent
branch
from
May 26, 2026 02:22
382dbe8 to
b91e6f1
Compare
35C4n0r
added a commit
that referenced
this pull request
Aug 14, 2026
…8166) Previously, a `coder_script` whose `log_path` pointed under a directory that did not yet exist failed before the script ran, with no per-script log output. `OpenFile(logPath, O_CREATE|O_RDWR, 0o600)` creates the log file but not its parent directories, so the open returned `ENOENT`. The failure only surfaced in the agent log (`startup script(s) failed` / `shutdown script(s) failed`) and never reached the script's own UI logs, which made it look like a silent failure. This creates the resolved parent directory with `MkdirAll(filepath.Dir(logPath), 0o700)` before opening the log file, so the script runs and its log is written. `0o700` matches the existing script data-dir and secret-file directory conventions in this package. Resolution of `~`, environment variables, and paths relative to `LogDir` is unchanged; only the parent directory is now created. Fixes #21986 <details><summary>Implementation notes and validation</summary> **Change** * `agent/agentscripts/agentscripts.go`: in `(*Runner).run`, after the full `logPath` resolution and before `OpenFile`, create the parent directory: ```go logDir := filepath.Dir(logPath) if err = r.Filesystem.MkdirAll(logDir, 0o700); err != nil { return xerrors.Errorf("create script log file directory %q: %w", logDir, err) } ``` **Regression test** * `agent/agentscripts/agentscripts_test.go`: `TestExecuteCreatesMissingLogDir` runs a script with a nested, nonexistent `LogPath` and asserts the streamed output and that the log file is created. * The test uses `afero.NewOsFs()` on purpose: `afero.NewMemMapFs()` auto-creates parent directories on `OpenFile`, so it cannot reproduce the reported failure. * Verified red without the fix (`open .../does/not/exist/install.log: no such file or directory`) and green with it. **Local validation** * `gofmt` clean, `go vet`, `go build`, `golangci-lint run` on the package, and `go test -race ./agent/agentscripts/` all pass. **End-to-end** * Validated on a dev instance with a template whose `coder_script.log_path` targets a nested directory that does not exist. The agent created the parents with mode `0700` and wrote the log file; the workspace agent reported healthy. **Prior attempts** * [#22796](<#22796>) and [#25545](<#25545>) proposed the same directory-creation approach. Both were closed for non-technical reasons (a low-effort AI PR and a stale community PR), not rejected on the merits. This supersedes them, authored by the issue owner, using `0o700` and adding a regression test. </details> --- *Raised on behalf of* @35C4n0r *by Coder Agents.*
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.
Fixes #21986
Summary
LogPath, matching the reported failure mode.Test plan
go test ./agent/agentscripts -run TestExecuteCreatesLogPathParents -count=1go test ./agent/agentscripts -count=1make fmt/go FILE=agent/agentscripts/agentscripts.gomake fmt/go FILE=agent/agentscripts/agentscripts_test.gogit diff --check --cachedI also attempted the normal pre-commit hook after installing local Make and pnpm tooling. On this Windows host, the hook did not reach project validation because GNU Make invoked Bash incorrectly and tried to execute generated Go files as shell scripts, for example
coderd/database/querier.go: line 1: //: Is a directory. The focused Go checks above passed after that attempt.Disclosure
I used AI assistance while preparing this change. I reviewed the diff and verification results myself.