Repository navigation
Description
What happens
src/science/kernel/environment-manager.ts parses a hashed requirements file into pins:
function requirementArtifacts(requirements: string) {
if (!requirements.trim()) return []
return requirements.split("\n").map((line) => {
const pin = line.trim().split(/\s+/u)[0]!
const offset = pin.indexOf("==")
return {
pin,
name: pin.slice(0, offset),
version: pin.slice(offset + 2),
hashes: [...line.matchAll(/--hash=sha256:([a-f0-9]{64})/gu)].map((m) => m[1]!),
}
})
}No line is skipped. A comment line yields pin: "#", offset: -1, so name: "" and version: "h"; a blank line yields pin: "" and version: "n".
That result then fails its own coverage check in verifiedWheels (line ~500):
const expected = requirementArtifacts(requirements)
if (expected.length !== pins.length || expected.some((item) => !pins.includes(item.pin) || item.hashes.length === 0))
return undefinedso ensureWheelArchives treats the cache as unverified, re-downloads on every call, and finally throws:
"Downloaded wheels do not exactly cover the hashed task requirements"
Why it is wrong
TaskSpec.pip_requirements is agent- or author-supplied and validated only as z.string().trim().min(1).max(100_000) (environment-manager.ts:131) — unlike capability/schema.ts:154, which does require every non-blank line to carry --hash=sha256:.
So a completely ordinary requirements.txt — one # pinned by release 2.0 header, or a blank line between sections — can never produce a managed task environment. The pinned-wheel cache is written but never accepted, and the failure message points at "do not exactly cover" rather than at the comment line.
This fails loudly rather than silently, so it is a parser defect rather than a research-corruption bug, but it blocks a legitimate input.
Repro
requirementArtifacts([
"# pinned by release 2.0",
"numpy==1.26.4 --hash=sha256:" + "a".repeat(64),
"",
"scipy==1.11.4 --hash=sha256:" + "b".repeat(64),
].join("\n"))returns 4 entries instead of 2, so expected.length !== pins.length is true for any real pin list.
Suggested fix
Skip lines that are blank or start with # after trimming:
return requirements
.split("\n")
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("#"))
.map((line) => { /* unchanged */ })requirementArtifacts is currently module-private, so this exports it to make the parser testable directly. The tests in test/science/kernel/environment-manager.test.ts that reach this path are all test.skipIf(!capabilityPlatform()) and do not run on Windows, so the new test file exercises the parser on its own.
Activity