Repository navigation
[heft] Add shard result contracts and output ownership - #6205
Yashwanth Reddy Verupaka (yashwanth195) wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Active issues prevent publishing valid long output filenames and cause unbounded recursion when resolving an absent filesystem root.
2 open issues
What changed in this PR
Adds workload-neutral contracts for safely publishing isolated shard results in Heft. This is a standalone foundation; it does not enable managed sharding or change existing task execution.
Changes:
- Adds strict shard identities, count-aware temporary paths, and schema-validated result manifests.
- Introduces canonical output validation, exclusive ownership claims, and cancellation-aware atomic publication.
- Adds regression tests, public manifest types, contract documentation, and a minor changefile.
| File | Description |
|---|---|
docs/heft/shard-contracts.md |
Documents guarantees, lifecycle, and caller obligations. |
common/reviews/api/heft.api.md |
Records public manifest and status types. |
common/changes/@rushstack/heft/heft-shard-contracts_2026-11-13.json |
Declares the minor feature release. |
apps/heft/src/sharding/test/ShardResultManifest.test.ts |
Tests manifest validation, publication, and cancellation. |
apps/heft/src/sharding/test/ShardOutputOwnership.test.ts |
Tests path aliases, ownership contention, and cleanup. |
apps/heft/src/sharding/test/ShardIdentity.test.ts |
Tests strict parsing and isolated temporary paths. |
apps/heft/src/sharding/test/ShardFileSystem.test.ts |
Tests atomic writes and path validation. |
apps/heft/src/sharding/ShardResultManifest.ts |
Implements manifest validation, reads, and publication. |
apps/heft/src/sharding/ShardOutputOwnership.ts |
Implements canonical paths and exclusive output claims. |
apps/heft/src/sharding/ShardIdentity.ts |
Adds shard parsing, formatting, and folder helpers. |
apps/heft/src/sharding/ShardFileSystem.ts |
Adds path validation and guarded atomic writes. |
apps/heft/src/sharding/IShardResultManifest.ts |
Defines workload-neutral result contracts. |
apps/heft/src/schemas/shard-result-manifest.schema.json |
Defines the versioned manifest schema. |
apps/heft/src/index.ts |
Exports manifest and status types. |
Review effort: Balanced
| const folder: string = path.dirname(filename); | ||
| await fs.mkdir(folder, { recursive: true }); | ||
| abortSignal?.throwIfAborted(); | ||
| const temporaryPath: string = path.join(folder, `.${path.basename(filename)}.${randomUUID()}.tmp`); |
There was a problem hiding this comment.
All output files must be deterministically named. Generating random files will completely wreck build cache file tracing.
There was a problem hiding this comment.
Removed generated staging names in ab06af8. Publication now takes a fixed, caller-declared staging path independent of the destination basename; manifests use shard-manifest.partial.json. Long leaf and ancestor cases are covered.
| return await fs.realpath(filename); | ||
| } catch (error) { | ||
| if (!FileSystem.isNotExistError(error as Error)) throw error; | ||
| return path.join(await resolveShardPathAsync(path.dirname(filename)), path.basename(filename)); |
There was a problem hiding this comment.
Removed the canonicalization and ownership layer, including this recursion, in ab06af8. Path checks are lexical; actual filesystem failures propagate from the write.
| targetPath: string, | ||
| abortSignal?: AbortSignal | ||
| ): Promise<void> { | ||
| const relative: string = path.relative(buildFolderPath, targetPath); |
There was a problem hiding this comment.
Way too expensive. Enforce literally that targetPath.startsWith(${buildFolderPath}${path.sep})
There was a problem hiding this comment.
Replaced the filesystem walk with a lexical prefix check on normalized paths in ab06af8. Configuration validation performs no filesystem I/O.
|
|
||
| "generation": { | ||
| "title": "Shard Generation", | ||
| "description": "An opaque token identifying the sharded run that produced this manifest. The collator requires it to be uniform across every manifest, which is what prevents results from two different runs being merged together.", |
There was a problem hiding this comment.
With build cache and incremental runs, merging results from two different runs is an explicit goal.
There was a problem hiding this comment.
Removed generation and attempt tokens in ab06af8. The manifest no longer requires results from the same run. Rush owns cache compatibility; consumer collation and mixed-cache acceptance are being updated separately.
|
|
||
| "workload": { | ||
| "title": "Workload Name", | ||
| "description": "The kind of work this shard performed, for example \"jest\" or \"lint\". The neutral core treats this as opaque; only an adapter interprets it.", |
There was a problem hiding this comment.
This should just be the heft action or phase name
There was a problem hiding this comment.
Replaced workload with the configured producer phaseName in ab06af8. The folder helper uses the existing phase/task temp suffix; separate collation work will explicitly name that producer phase/task rather than compare action aliases.
|
|
||
| ## Paths and exclusive ownership | ||
|
|
||
| Resolve build-root-relative configuration paths against the build root before calling the path helpers. |
There was a problem hiding this comment.
Don't resolve build-root-relative configuration paths at all. Simply ensure that they don't walk up out of the build root.
There was a problem hiding this comment.
Configuration stays project-relative in ab06af8. Validation is lexical, including escape and reserved-device checks, with no realpath calls or directory creation. Callers join to the build root only at the I/O boundary.
| ancestors without creating missing inputs; `resolveShardOutputPathAsync()` validates and materializes output | ||
| directories, but never creates a result file. It resolves physical aliases, including Windows short paths. | ||
|
|
||
| Pass canonical destinations to `acquireShardOutputLocksAsync()`. Claims exclude overlapping ancestors and |
There was a problem hiding this comment.
Why are there locks involved in this process at all?
There was a problem hiding this comment.
Removed the locks and claim registry in ab06af8. Single-writer scheduling and waiting for producer cleanup are orchestrator responsibilities, not a new filesystem protocol in this foundation.
| Output contention fails immediately; registration contention has a two-second retry budget, not an I/O timeout. | ||
| Partial acquisition failures release acquired claims and surface cleanup failures. | ||
|
|
||
| Claims live in the reserved `<buildRoot>/.heft-jest-shard-locks` protocol namespace, outside shard outputs. |
There was a problem hiding this comment.
No, they don't, because they are completely unnecessary.
There was a problem hiding this comment.
Removed this namespace and its recovery protocol in ab06af8, along with the ownership implementation and tests.

Summary
Add reusable Heft contracts for workloads that need to publish isolated shard results safely. This standalone
foundation provides identities, versioned manifests, atomic publication and exclusive output claims; it does
not enable managed sharding or change existing task execution.
Details
missing results from corrupt ones and leave workload payloads opaque.
publication preserve exclusive ownership through cancellation and cleanup. Abandoned claims require verified
manual recovery, never PID/age-based stealing.
Ported only the generic foundation from
6af2a03e5461da3e2ac8bd91ce2d0f5fd91310c9onto upstreammain, withadditional standalone regressions and a trailing-newline parser correction. No unmerged PR is a prerequisite.
Collation/coherence validation, adapter registration, CLI mode wiring, Jest execution/coverage/JUnit and Rush
identity/cache integration remain separate. Callers must keep outputs disjoint from source and payload inputs;
these cooperative filesystem helpers are not a sandbox. Existing unsharded behavior is unchanged.
How it was tested
Validated this standalone port on Windows with Node 24.22.1 and the repository's Rush 5.182.0/Heft/Jest setup.
The integrated source's earlier validation is not used as evidence for this PR.
node common\scripts\install-run-rush.js install --to @rushstack/heftnode common\scripts\install-run-rush.js build --to @rushstack/heftnode common\scripts\install-run-rush.js build --only @rushstack/heft --productionapps\heft:node ..\..\common\scripts\install-run-rushx.js _phase:test --test-path-pattern sharding --disable-code-coveragenode common\scripts\install-run-rush.js prettiernode common\scripts\install-run-rush.js change --verify --target-branch upstream/maingit diff --cached --checkCoverage includes identity/schema domains, invalid/corrupt manifests, cancellation boundaries, atomic failure
cleanup, symlinked roots versus nested junctions, filesystem name equivalence, overlapping/concurrent claims,
partial acquisition cleanup, replaced/hardlinked claims and abandoned-gate diagnostics. No POSIX run or broad
Jest adapter/coverage/collator/acceptance sweep was performed.
Impacted documentation
Added
docs/heft/shard-contracts.mdfor implemented guarantees and caller obligations. No existing websitebehavior changes. The new schema describes generated result files, so no init template applies.