vxcontrol/pentagi · error

failed to inspect exec process: %w

Error message

failed to inspect exec process: %w

What it means

After streaming output, getExecResult calls ContainerExecInspect to wait for the exec process to finish and learn its state. This error wraps a failure of that inspect call, meaning the library could not confirm the exec's completion status.

Source

Thrown at backend/pkg/tools/terminal.go:311

		// Wait for the copy goroutine to finish
		<-errChan

		suggestedTimeout := max(int(timeout.Seconds())-10, 10)
		return "", fmt.Errorf(
			"command execution timeout (%v). Partial output: %s. "+
				"HINT: If this is an interactive command (shell/REPL/listener), use detach=true. "+
				"For long batch commands, wrap with shell timeout utility: 'timeout %d <command>' to ensure clean completion",
			ctx.Err(),
			truncateString(dst.String(), 500),
			suggestedTimeout,
		)
	}

	// wait for the exec process to finish
	_, err = t.dockerClient.ContainerExecInspect(ctx, id)
	if err != nil {
		return "", fmt.Errorf("failed to inspect exec process: %w", err)
	}

	results := dst.String()
	// Style system output with color coding
	styledOutput := fmt.Sprintf("%s%s%s%s", ansiColorSystemMsg, results, ansiColorReset, ansiLineTerminator)
	_, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdout, styledOutput, t.containerID, t.taskID, t.subtaskID)
	if err != nil {
		return "", fmt.Errorf("failed to put terminal log (stdout): %w", err)
	}

	if results == "" {
		results = "Command completed successfully with exit code 0. No output produced (silent success)"
	}

	return results, nil
}

func (t *terminal) ReadFile(ctx context.Context, flowID int64, path string) (string, error) {

View on GitHub (pinned to ea665308ba)

Solutions

  1. Verify the container is still running (IsContainerRunning) before/after execution
  2. Check daemon connectivity (docker info) and retry the command
  3. Inspect container events/logs to see if it was killed during execution (docker events, docker logs)
  4. Ensure Docker client library API version matches the daemon (DOCKER_API_VERSION)

Example fix

// before
out, err := term.ExecCommand(ctx, flowID, cmd, false) // daemon unreachable at inspect
// after
if err := dockerPing(ctx); err != nil {
    return fmt.Errorf("docker daemon unavailable: %w", err)
}
out, err := term.ExecCommand(ctx, flowID, cmd, false)
Defensive patterns

Strategy: retry

Validate before calling

if ok, err := docker.IsContainerRunning(ctx, containerLID); err != nil || !ok {
    return fmt.Errorf("container unavailable before exec: %v", err)
}

Try / catch

out, err := term.ExecCommand(ctx, flowID, cmd, false)
if err != nil && strings.Contains(err.Error(), "failed to inspect exec process") {
    // daemon hiccup or exec reaped; verify daemon then retry
    if err := dockerPing(ctx); err == nil {
        out, err = term.ExecCommand(ctx, flowID, cmd, false)
    }
}

Prevention

When it happens

Trigger: ContainerExecInspect(ctx, id) returns an error: the exec instance no longer exists (already removed/reaped), the container stopped and was removed, or the Docker daemon became unreachable between attach and inspect.

Common situations: Docker daemon restart or connection drop mid-exec; container OOM-killed or stopped while the command ran; very short-lived execs that finish and get reaped before inspect; Docker API version incompatibilities.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/6a29f55bab20510d. Report an issue: GitHub.