Repository navigation
Description
Description
Description
When the same Taskfile is included multiple times with different dir values, dynamic variables may be evaluated using the directory configured for another inclusion.
Each included task works correctly when executed separately. However, when both included tasks are executed in the same Task invocation, their dynamic-variable directory context appears to be incorrectly shared.
I reproduced this on the latest main commit:
Steps to reproduce
Create the following structure:
example/
├── Taskfile.yml
├── included/
│ └── Taskfile.yml
└── workspace/
├── backend/
└── frontend/
Use the following root Taskfile.yml:
version: "3"
includes:
backend:
taskfile: ./included/Taskfile.yml
dir: ./workspace/backend
frontend:
taskfile: ./included/Taskfile.yml
dir: ./workspace/frontend
tasks:
default:
cmds:
- task: backend:show
- task: frontend:show
Use the following included Taskfile at included/Taskfile.yml:
version: "3"
tasks:
show:
vars:
CURRENT_DIR:
sh: basename "$(pwd)"
cmds:
- 'echo "{{.CURRENT_DIR}}" > result.txt'
Create the required directories:
mkdir -p workspace/backend workspace/frontend
Run both tasks in the same invocation:
task backend:show frontend:show
Inspect the generated files:
cat workspace/backend/result.txt
cat workspace/frontend/result.txt
Expected behavior
Each dynamic variable should be evaluated using its inclusion's configured directory:
workspace/backend/result.txt -> backend
workspace/frontend/result.txt -> frontend
Actual behavior
Both files contain the backend directory name:
workspace/backend/result.txt -> backend
workspace/frontend/result.txt -> backend
The frontend:show command itself executes inside workspace/frontend, but its dynamic variable contains the value evaluated for workspace/backend.
Additional observations
Both tasks work correctly when executed separately:
task backend:show
Produces: backend
task frontend:show
Produces: frontend
The problem occurs when both included tasks are executed within the same Task invocation:
task backend:show frontend:show
The following screenshot demonstrates the difference between running the tasks separately and together:
Regression test
I also created a regression test using the existing fileContentTest helper.
It currently fails with:
expected: "frontend\n"
actual: "backend\n"
I would be happy to investigate this further and work on a fix if the behavior is confirmed as unintended.
Version
3.52.0
Operating system
ProductName: macOS ProductVersion: 26.3.1 ProductVersionExtra: (a) BuildVersion: 25D771280a arm64
Experiments Enabled
No response
Example Taskfile
version: "3"
includes:
backend:
taskfile: ./included/Taskfile.yml
dir: ./workspace/backend
frontend:
taskfile: ./included/Taskfile.yml
dir: ./workspace/frontend
tasks:
default:
cmds:
- task: backend:show
- task: frontend:show
Activity
trulede commentedon Jul 25, 2026
This is probably a duplicate of #524 and there you find a mechanism to use to avoid the issue. Its possible that the solution presented in #524 is how to solve this issue, but please continue with the PR if you want, or if the solution does not work.
ikshantshukla123 commentedon Jul 25, 2026
Thanks for pointing me to #524. This does appear to have the same underlying
cause: identical dynamic-variable
sh:commands are reused across differentdirectory contexts.
In this case, the same reusable Taskfile is included twice with different
dirvalues, so making thesh:command unique for each inclusion would bedifficult without modifying or duplicating the included Taskfile.
I'll continue investigating this. I already have a minimal failing regression
test, and I'll check whether dynamic-variable evaluation can distinguish
between different task/include directory contexts without affecting the
intended caching behavior.