Skip to content

Commit 2343537

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): pass collectInputs flag through daemon IPC for task hashing (#34915)
When the daemon handles task hashing, the `NativeTaskHasherImpl` checked `hasTaskInputSubscribers()` in the daemon process where no subscribers exist, causing the native Rust hasher to skip input collection entirely. This resulted in empty input arrays in IO tracing signals. The fix passes collectInputs from the client process (where subscribers are registered) through the daemon IPC to the hasher, so the daemon uses the client's subscriber state instead of its own.
1 parent bc7d88b commit 2343537

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

packages/nx/src/daemon/client/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ export class DaemonClient {
349349
tasks: Task[],
350350
taskGraph: TaskGraph,
351351
env: NodeJS.ProcessEnv,
352-
cwd: string
352+
cwd: string,
353+
collectInputs?: boolean
353354
): Promise<Hash[]> {
354355
return this.sendToDaemonViaQueue({
355356
type: 'HASH_TASKS',
@@ -361,6 +362,7 @@ export class DaemonClient {
361362
tasks,
362363
taskGraph,
363364
cwd,
365+
collectInputs,
364366
});
365367
}
366368

packages/nx/src/daemon/server/handle-hash-tasks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function handleHashTasks(payload: {
1616
tasks: Task[];
1717
taskGraph: TaskGraph;
1818
cwd: string;
19+
collectInputs?: boolean;
1920
}) {
2021
const { error, projectGraph, allWorkspaceFiles, fileMap, rustReferences } =
2122
await getCachedSerializedProjectGraphPromise();
@@ -39,7 +40,8 @@ export async function handleHashTasks(payload: {
3940
payload.tasks,
4041
payload.taskGraph,
4142
payload.env,
42-
payload.cwd
43+
payload.cwd,
44+
payload.collectInputs
4345
);
4446
return {
4547
response,

packages/nx/src/hasher/native-task-hasher-impl.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ export class NativeTaskHasherImpl implements TaskHasherImpl {
6868
task: Task,
6969
taskGraph: TaskGraph,
7070
env: NodeJS.ProcessEnv,
71-
cwd?: string
71+
cwd?: string,
72+
collectInputs?: boolean
7273
): Promise<PartialHash> {
7374
const plans = this.planner.getPlansReference([task.id], taskGraph);
74-
const collectInputs = getTaskIOService().hasTaskInputSubscribers();
75+
const shouldCollectInputs =
76+
collectInputs ?? getTaskIOService().hasTaskInputSubscribers();
7577
const hashes = this.hasher.hashPlans(
7678
plans,
7779
env,
7880
cwd ?? process.cwd(),
79-
collectInputs
81+
shouldCollectInputs
8082
);
8183

8284
return hashes[task.id];
@@ -86,18 +88,20 @@ export class NativeTaskHasherImpl implements TaskHasherImpl {
8688
tasks: Task[],
8789
taskGraph: TaskGraph,
8890
env: NodeJS.ProcessEnv,
89-
cwd?: string
91+
cwd?: string,
92+
collectInputs?: boolean
9093
): Promise<PartialHash[]> {
9194
const plans = this.planner.getPlansReference(
9295
tasks.map((t) => t.id),
9396
taskGraph
9497
);
95-
const collectInputs = getTaskIOService().hasTaskInputSubscribers();
98+
const shouldCollectInputs =
99+
collectInputs ?? getTaskIOService().hasTaskInputSubscribers();
96100
const hashes = this.hasher.hashPlans(
97101
plans,
98102
env,
99103
cwd ?? process.cwd(),
100-
collectInputs
104+
shouldCollectInputs
101105
);
102106
return tasks.map((t) => hashes[t.id]);
103107
}

packages/nx/src/hasher/task-hasher.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { minimatch } from 'minimatch';
1212
import { NativeTaskHasherImpl } from './native-task-hasher-impl';
1313
import { workspaceRoot } from '../utils/workspace-root';
1414
import { HashInputs, NxWorkspaceFilesExternals } from '../native';
15+
import { getTaskIOService } from '../tasks-runner/task-io-service';
1516

1617
// Re-export HashInputs from native module for public API
1718
export { HashInputs };
@@ -84,14 +85,16 @@ export interface TaskHasherImpl {
8485
tasks: Task[],
8586
taskGraph: TaskGraph,
8687
env: NodeJS.ProcessEnv,
87-
cwd?: string
88+
cwd?: string,
89+
collectInputs?: boolean
8890
): Promise<PartialHash[]>;
8991

9092
hashTask(
9193
task: Task,
9294
taskGraph: TaskGraph,
9395
env: NodeJS.ProcessEnv,
94-
cwd?: string
96+
cwd?: string,
97+
collectInputs?: boolean
9598
): Promise<PartialHash>;
9699
}
97100

@@ -108,12 +111,14 @@ export class DaemonBasedTaskHasher implements TaskHasher {
108111
taskGraph?: TaskGraph,
109112
env?: NodeJS.ProcessEnv
110113
): Promise<Hash[]> {
114+
const collectInputs = getTaskIOService().hasTaskInputSubscribers();
111115
return this.daemonClient.hashTasks(
112116
this.runnerOptions,
113117
tasks,
114118
taskGraph,
115119
env ?? process.env,
116-
process.cwd()
120+
process.cwd(),
121+
collectInputs
117122
);
118123
}
119124

@@ -122,13 +127,15 @@ export class DaemonBasedTaskHasher implements TaskHasher {
122127
taskGraph?: TaskGraph,
123128
env?: NodeJS.ProcessEnv
124129
): Promise<Hash> {
130+
const collectInputs = getTaskIOService().hasTaskInputSubscribers();
125131
return (
126132
await this.daemonClient.hashTasks(
127133
this.runnerOptions,
128134
[task],
129135
taskGraph,
130136
env ?? process.env,
131-
process.cwd()
137+
process.cwd(),
138+
collectInputs
132139
)
133140
)[0];
134141
}
@@ -158,13 +165,15 @@ export class InProcessTaskHasher implements TaskHasher {
158165
tasks: Task[],
159166
taskGraph?: TaskGraph,
160167
env?: NodeJS.ProcessEnv,
161-
cwd?: string
168+
cwd?: string,
169+
collectInputs?: boolean
162170
): Promise<Hash[]> {
163171
const hashes = await this.taskHasher.hashTasks(
164172
tasks,
165173
taskGraph,
166174
env ?? process.env,
167-
cwd ?? process.cwd()
175+
cwd ?? process.cwd(),
176+
collectInputs
168177
);
169178
return tasks.map((task, index) =>
170179
this.createHashDetails(task, hashes[index])
@@ -175,13 +184,15 @@ export class InProcessTaskHasher implements TaskHasher {
175184
task: Task,
176185
taskGraph?: TaskGraph,
177186
env?: NodeJS.ProcessEnv,
178-
cwd?: string
187+
cwd?: string,
188+
collectInputs?: boolean
179189
): Promise<Hash> {
180190
const res = await this.taskHasher.hashTask(
181191
task,
182192
taskGraph,
183193
env ?? process.env,
184-
cwd ?? process.cwd()
194+
cwd ?? process.cwd(),
195+
collectInputs
185196
);
186197
return this.createHashDetails(task, res);
187198
}

0 commit comments

Comments
 (0)