Skip to content

fix(execd): auto-recreate temp dir in stdLogDescriptor and combinedOutputDescriptor#415

Merged
Pangjiping merged 1 commit intoalibaba:mainfrom
zerone0x:fix/issue-400-auto-recreate-tmp-dir
Mar 11, 2026
Merged

fix(execd): auto-recreate temp dir in stdLogDescriptor and combinedOutputDescriptor#415
Pangjiping merged 1 commit intoalibaba:mainfrom
zerone0x:fix/issue-400-auto-recreate-tmp-dir

Conversation

@zerone0x
Copy link
Contributor

Summary

Fixes #400

When the /tmp directory is deleted inside a sandbox container, all subsequent command execution fails with failed to get stdlog descriptor or failed to get combined output descriptor. The root cause is that os.OpenFile with os.O_CREATE only creates the file, not the parent directory — so once /tmp is gone, every command fails until the container is restarted.

Changes

  • stdLogDescriptor: add os.MkdirAll(os.TempDir(), 0o755) before opening log files — auto-recreates /tmp (or whatever $TMPDIR points to) if it was removed
  • combinedOutputDescriptor: same fix
  • stdLogDescriptor fd leak: close stdout when stderr open fails (previously leaked the stdout *os.File)
  • Tests: two new regression tests (TestStdLogDescriptor_AutoCreatesTempDir, TestCombinedOutputDescriptor_AutoCreatesTempDir) that point TMPDIR at a non-existent path and assert the directory is created on the first command

The change is minimal and backward-compatible — MkdirAll on an existing directory is a no-op, so there is no overhead in the normal case.


🤖 Generated with Claude Code

…tputDescriptor

When the /tmp directory is deleted inside a sandbox container, subsequent
command execution fails with 'failed to get stdlog descriptor' because
os.OpenFile with O_CREATE only creates the file, not the parent directory.

Add os.MkdirAll(os.TempDir(), 0755) before file creation in both
stdLogDescriptor and combinedOutputDescriptor so the temp directory is
automatically recreated if it has been removed. Also fix a file descriptor
leak in stdLogDescriptor where the stdout file was not closed when the
stderr open failed.

Fixes alibaba#400

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 11, 2026 03:59
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes execd command execution failures when the temp directory (e.g. /tmp) is deleted in sandbox containers by ensuring the temp directory is recreated before opening per-command log files.

Changes:

  • Ensure stdLogDescriptor and combinedOutputDescriptor call os.MkdirAll(os.TempDir(), ...) before opening output files.
  • Fix a stdLogDescriptor file descriptor leak by closing stdout if opening stderr fails.
  • Add regression tests intended to validate auto-creation of the temp directory when TMPDIR points to a missing path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
components/execd/pkg/runtime/command_common.go Recreates temp dir before creating log/output files; closes stdout on stderr open failure.
components/execd/pkg/runtime/command_test.go Adds regression tests for temp-dir auto-creation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Pangjiping Pangjiping self-assigned this Mar 11, 2026
@Pangjiping Pangjiping added bug Something isn't working component/execd labels Mar 11, 2026
Copy link
Collaborator

@Pangjiping Pangjiping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Pangjiping
Copy link
Collaborator

It looks like an ignorable linter issue, I'll try to address these minor things all at once before the release.

@Pangjiping Pangjiping merged commit e99671a into alibaba:main Mar 11, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working component/execd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Command Execution Fails When /tmp Directory is Deleted

3 participants