Skip to content

Make the current location for script blocks executing in background/thread jobs default to the caller's in all scenarios #10673

Closed

Description

Update: This proposal has been approved - the remaining work is summarized in this comment.


Ideally, we'd have a consistent experience across all background-/thread-job related features, meaning that all of the following should exhibit the same behavior with respect to the current location that the script block being passed sees (by default:

  • (a) Start-Job
  • (b) Start-ThreadJob
  • (c) postpositional & to start a job (implicit Start-Job)
  • (d) ForEach-Object -Parallel

The most sensible location to use is the caller's current location, which (c) already uses and (d) will, once #10672 is merged.

The proposal is to make (a) and (b) behave like (c) and (d) for overall consistency and use of a sensible default:

(b) (Start-ThreadJob) was meant to be modeled after Start-Job's example, but currently isn't: it uses the - virtually unpredictable from a user's perspective - process-wide working directory; given that, it shouldn't be too late to change it - see PaulHigin/PSThreadJob#46

(a) (Start-Job) regrettably has always defaulted to $HOME (the filesystem provider's home location).

The question now is:

Can we consider Start-Job's default-to-$HOME behavior a bug / something worth fixing as a Bucket 3: Unlikely Grey Area change?

I'm certainly personally in favor of that, but I haven't looked into how likely it is that existing Start-Job code relies on $HOME to be the default directory.

Ilya (@iSazonov)'s take (from his comment at #10537 (comment)):

I suggest to consider Start-Job case as bug.
If my work folder is c:\work and I run a job which switched to $home that is c:\users\isazonov - the last place is the worst place where user would like to see a resulting file. We could guess that user would use relative path to Documents folder. But most likely when faced with this inconsistency, the user will use the exact path to the working directory (c:\work), especially since the job is perceived as some kind of background process.

Activity

  1. added
    Issue-Question
    on Oct 1, 2019
  2. added
    Review - Committee
    on Oct 2, 2019
  3. iSazonov commented on Oct 2, 2019

    @iSazonov
    Collaborator

    /cc Steve Lee (@SteveL-MSFT) Need PowerShell Committee conclusion.

  4. added
    Breaking-Change
    on Oct 2, 2019
  5. SteveL-MSFT commented on Oct 9, 2019

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee discussed this, we agree that each of these should standardize on using the current working directory as the working directory. Start-Job is already inconsistent with itself in that Linux/macOS starts in user's home directory, but on Windows it starts in user's Documents folder. We agree to accept a breaking change to always start in the filesystem current working directory where the cmdlet/operator is used for all of the scenarios.

  6. added
    Committee-Reviewed
    and removed
    Review - Committee
    on Oct 9, 2019
  7. iSazonov commented on Oct 10, 2019

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) Please update the issue description with current status - what is left to fix after last commits? May be add links to PRs.

  8. added
    Issue-Meta
    and removed
    Issue-Question
    on Oct 10, 2019
  9. SteveL-MSFT commented on Oct 10, 2019

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) the background operator & already uses current working directory, foreach-object -parallel was fixed recently, start-threadjob has PaulHigin/PSThreadJob#46 opened and Paul Higinbotham (@PaulHigin) can make that fix and we can include that version in PS7. I believe just Start-Job needs a fix.

  10. iSazonov commented on Oct 10, 2019

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Yes. The issue has PowerShell Committee conclusion and I'd want to see all (problems and solutions) in the OP for clear history because it is a breaking change.

  11. mklement0 commented on Oct 10, 2019

    @mklement0
    ContributorAuthor

    I've updated the OP with a note at the top that points to the approval comment and to Steve's follow-up comment summarizing the remaining work needed.

  12. MathiasMagnus commented on Oct 23, 2019

    @MathiasMagnus
    Contributor

    I'd consider ForEach-Object -Parallel to be special in the sense that it's not a breaking change, since it's only a preview feature. This was the case I hit where my code was using old-school ForEach-Object and moving to the parallel version broke because executables were not found by the script. In this sense, not applying the caller's cwd is the breaking part.

  13. PaulHigin commented on Oct 23, 2019

    @PaulHigin
    Contributor

    Nagy-Egri Máté Ferenc (@MathiasMagnus)
    This has already been fixed for ForEach-Object -Parallel (#10672)

  14. mklement0 commented on Oct 23, 2019

    @mklement0
    ContributorAuthor

    Nagy-Egri Máté Ferenc (@MathiasMagnus): Also note that it will be fixed for Start-Job and Start-ThreadJob as well (despite being technically breaking changes).

  15. ghost closed this as completedon Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Breaking-ChangeCommittee-ReviewedIssue-MetaResolution-Fixed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions