Repository navigation
fix(skills): trust the updater's lock when a run installs content newer than the bundle - #11220
Conversation
…er than the bundle skills update installs source-repo HEAD, which routinely runs ahead of the revisions a shipped build bundles. The post-run re-scan hashed that content 'unrecognized' (the registry has never seen it) and the verdict counted it as a failure — so a clean update reported "The update didn't finish / Updated 0 of N", and Retry repeated the false failure forever because the CLI now no-ops (lock == source). The 'newer-known' escape hatch never fires: the generator always points the manifest at the registry's newest snapshot, so no observed content can hash to a revision newer than the bundle. The verdict now computes the git tree sha of the observed bytes (a port of the generator's hashing, verified byte-for-byte against git write-tree and against every shipped skill's manifest gitTreeSha) and accepts an unrecognized placement when that sha equals the lock's skillFolderHash: the lock is the CLI's own record of what it installed, so disk matching lock means the command did its job — the bundled registry simply has not seen that revision yet. Half-written bundles (sha mismatch), unreadable copies, removed skills, degraded aliases, and outdated copies at the lock hash all still fail.
📝 WalkthroughWalkthroughThe change adds Git-compatible tree hashing for observed skill packages, including executable modes, binary contents, nested directories, and Git ordering rules. Observed package and freshness installation records now carry the resulting tree SHA or 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 33c42116-f33f-4ec0-839b-fccf0bd01681
📒 Files selected for processing (8)
src/main/ipc/skills.tssrc/main/skills/skill-freshness-placement-observation.tssrc/main/skills/skill-git-tree-identity.test.tssrc/main/skills/skill-git-tree-identity.tssrc/main/skills/skill-package-identity.tssrc/main/skills/skill-update-outcome.test.tssrc/main/skills/skill-update-outcome.tssrc/shared/skill-freshness.ts
| const env = { ...process.env, GIT_CONFIG_GLOBAL: devNull, GIT_CONFIG_SYSTEM: devNull } | ||
| execFileSync('git', ['init', '--quiet', repoShell], { env }) | ||
| const gitDirArgs = ['--git-dir', join(repoShell, '.git'), '--work-tree', work] | ||
| execFileSync('git', [...gitDirArgs, '-c', 'core.autocrlf=false', 'add', '-A'], { | ||
| env, | ||
| cwd: work | ||
| }) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Windows portability of the git parity fixture.
os.devNull resolves to \\.\nul on Windows; Git's config loader does not reliably accept that as a config path, and the test also assumes a git binary on PATH. Consider NUL on win32 (or GIT_CONFIG_NOSYSTEM=1 plus GIT_CONFIG_GLOBAL pointing at a temp empty file) so the fixture behaves identically across hosts.
As per coding guidelines, "code, commands, and scripts must work on macOS, Linux, and Windows."
🔧 Suggested env hardening
- const env = { ...process.env, GIT_CONFIG_GLOBAL: devNull, GIT_CONFIG_SYSTEM: devNull }
+ const emptyConfig = join(base, 'empty.gitconfig')
+ await writeFile(emptyConfig, '')
+ const env = {
+ ...process.env,
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_CONFIG_GLOBAL: emptyConfig,
+ GIT_CONFIG_SYSTEM: emptyConfig
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const env = { ...process.env, GIT_CONFIG_GLOBAL: devNull, GIT_CONFIG_SYSTEM: devNull } | |
| execFileSync('git', ['init', '--quiet', repoShell], { env }) | |
| const gitDirArgs = ['--git-dir', join(repoShell, '.git'), '--work-tree', work] | |
| execFileSync('git', [...gitDirArgs, '-c', 'core.autocrlf=false', 'add', '-A'], { | |
| env, | |
| cwd: work | |
| }) | |
| const emptyConfig = join(base, 'empty.gitconfig') | |
| await writeFile(emptyConfig, '') | |
| const env = { | |
| ...process.env, | |
| GIT_CONFIG_NOSYSTEM: '1', | |
| GIT_CONFIG_GLOBAL: emptyConfig, | |
| GIT_CONFIG_SYSTEM: emptyConfig | |
| } | |
| execFileSync('git', ['init', '--quiet', repoShell], { env }) | |
| const gitDirArgs = ['--git-dir', join(repoShell, '.git'), '--work-tree', work] | |
| execFileSync('git', [...gitDirArgs, '-c', 'core.autocrlf=false', 'add', '-A'], { | |
| env, | |
| cwd: work | |
| }) |
🧰 Tools
🪛 ast-grep (0.45.0)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
Source: Coding guidelines
| return ( | ||
| entry.status === 'unrecognized' && | ||
| lockHash !== undefined && | ||
| entry.observedGitTreeSha === lockHash | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect how skillFolderHash is produced/consumed elsewhere in the repo.
rg -n 'skillFolderHash' -C3 --type=ts --type=js --type=md
fd -t f -e mjs -e ts . config scripts 2>/dev/null | xargs rg -n 'gitTreeSha|toString\(.hex.\)' -C2Repository: stablyai/orca
Length of output: 151
🏁 Script executed:
#!/bin/bash
set -u
echo "Files matching skill-update-outcome:"
fd -v 'skill-update-outcome' . -t f -e ts -e tsx -e js -e jsx 2>/dev/null || true
file="$(fd 'skill-update-outcome' . -t f -e ts -e tsx -e js -e jsx | head -n 1 || true)"
if [ -n "${file:-}" ]; then
echo "--- outline ---"
ast-grep outline "$file" --view compact 2>/dev/null || true
echo "--- contents ---"
cat -n "$file"
fi
echo
echo "Relevant symbols/usages:"
rg -n "skillFolderHash|observedGitTreeSha|skillPackageGitTreeSha|readGloballyUpdatableSkillLocks|updateOutcome|is.*Convergent|Convergent|lockHash" . \
-g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx' -g '*.md' || true
echo
echo "Deterministic comparison behavior probe:"
node - <<'JS'
const a = 'abc123';
const b = 'ABC123';
const c = ' abc123 ';
console.log(JSON.stringify({
a_eq_b: a === b,
a_trim_eq_c: a === c.trim(),
a_trim_toLower_eq_c_trim_toLower: a.trim().toLowerCase() === c.trim().toLowerCase(),
b_trim_toLower_eq_b_trim_toLower: a.trim().toLowerCase() === b.trim().toLowerCase(),
}));
JSRepository: stablyai/orca
Length of output: 15752
🏁 Script executed:
#!/bin/bash
set -u
for f in src/main/skills/skill-update-outcome.ts src/main/skills/skill-update-registration.ts src/main/skills/skill-git-tree-identity.ts src/main/skills/skill-package-identity.ts src/main/skills/skill-update-convergence.ts; do
if [ -f "$f" ]; then
echo "--- $f outline ---"
ast-grep outline "$f" --view compact 2>/dev/null || true
echo "--- $f relevant contents ---"
nl -ba "$f" | sed -n '1,130p'
fi
done
echo "--- case/whitespace normalization references ---"
rg -n "trim\(\$\)|trim\(\)|toLowerCase\(\$1\)|toLowerCase\(\)|toUpperCase\(\)|hex" src/main/skills src/shared -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx' || true
echo "--- git command usage in skill identity files ---"
rg -n "git object|git hash-object|git ls-tree|git rev-parse|sha1|toString\([^)]*hex[^)]*\)|Buffer|createHash" src/main/skills/skill-git-tree-identity.ts src/main/skills/skill-package-identity.ts src/main/skills/skill-update-registration.ts -C3Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -u
for f in src/main/skills/skill-update-outcome.ts src/main/skills/skill-update-registration.ts src/main/skills/skill-git-tree-identity.ts src/main/skills/skill-package-identity.ts src/main/skills/skill-update-convergence.ts; do
if [ -f "$f" ]; then
echo "--- $f lines 1-130 ---"
awk '{ printf "%3d\t%s\n", NR, $0 }' "$f" | sed -n '1,140p'
fi
done
echo "--- skill-update-outcome specific lines ---"
awk '{ printf "%3d\t%s\n", NR, $0 }' src/main/skills/skill-update-outcome.ts | sed -n '40,70p'
echo "--- read lock trimming/filtering in registration ---"
awk '{ printf "%3d\t%s\n", NR, $0 }' src/main/skills/skill-update-registration.ts | sed -n '30,85p'
echo "--- git-tree identity hashing implementation ---"
awk '{ printf "%3d\t%s\n", NR, $0 }' src/main/skills/skill-git-tree-identity.ts | sed -n '1,100p'Repository: stablyai/orca
Length of output: 24298
Normalize the lock hash before comparing it to the computed tree SHA.
skillPackageGitTreeSha emits lowercase hex, while skillFolderHash is read directly from the lock without trimming or normalization. Use the same lowercase form for the comparison so an uppercase lock value does not prevent a valid post-cut update from landing.
| /** Git tree sha of the observed bytes; lets the post-run verdict match disk against the updater's lock. */ | ||
| observedGitTreeSha?: string | null |
There was a problem hiding this comment.
Optional field relies on implicit undefined-fails-closed semantics
observedGitTreeSha is typed as ?: string | null, so an object without the field (from deserialized pre-PR data or a construction site that hasn't been updated) carries undefined. The comparison in skillPlacementLanded — entry.observedGitTreeSha === lockHash — correctly evaluates undefined === string as false, so it fails closed. However, this behavior is implicit. A brief note in the comment explaining that absence is treated identically to a non-matching SHA would help the next reader understand why the field is intentionally optional rather than required.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Greptile SummaryThis PR fixes a false-failure loop where The fix computes a git tree SHA of the observed on-disk bytes and treats an
Confidence Score: 4/5Safe to merge; the verdict change is tightly scoped to a single status×topology×hash-match condition, fails closed in every error path, and is covered by both unit tests and an integration test that reproduces the exact post-cut scenario. The logic is correct and well-tested. The only noteworthy point is that observedGitTreeSha is typed as optional in the shared SkillFreshnessInstallation type, meaning callers that omit the field silently get fail-closed behavior via undefined === string rather than a compile-time reminder — functionally safe, but the intent is not self-documenting. Files Needing Attention: The optional observedGitTreeSha field in src/shared/skill-freshness.ts is the one spot worth a second look, to confirm whether the ? is a deliberate backward-compat choice or should eventually become required once all callers are updated.
|
| Filename | Overview |
|---|---|
| src/main/skills/skill-git-tree-identity.ts | New file implementing git tree SHA computation (port of the generator's algorithm); correctly handles nested dirs, executables, binary blobs, and the z.txt vs z/ sort edge case. |
| src/main/skills/skill-update-outcome.ts | Core verdict change: adds lock-hash comparison in skillPlacementLanded; only forgives 'unrecognized' status when disk SHA exactly matches the lock entry, everything else still fails. |
| src/shared/skill-freshness.ts | Adds observedGitTreeSha as an optional field (?: string |
| src/main/skills/skill-package-identity.ts | Threads gitBlobSha and treeEntries through observeSkillPackage, computing observedGitTreeSha alongside the existing digest without altering the existing traversal logic. |
| src/main/skills/skill-freshness-placement-observation.ts | Passes observedGitTreeSha through all three return paths (inaccessible early-exit, success, and error catch), consistently setting null when bytes are unavailable. |
| src/main/ipc/skills.ts | Fetches globalSkillLocks concurrently with scanInventory and forwards them to skillUpdateFailedNames; comment explains the intentional fresh read after the run rewrites the lock. |
| src/main/skills/skill-update-outcome.test.ts | Adds eight new unit tests pinning the new lock-match logic, plus a full integration test that builds a real post-cut fixture (modified SKILL.md, temp home, real lock) and fails on main today. |
| src/main/skills/skill-git-tree-identity.test.ts | Two tests: one verifies every shipped skill's folder hashes to the bundled manifest's gitTreeSha, another validates the algorithm against real git write-tree output over nesting/executables/binary/sort-edge cases. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[skills update CLI runs] --> B[Post-run: rescanOutdatedNames]
B --> C[Promise.all: scanInventory + readGloballyUpdatableSkillLocks]
C --> D[skillUpdateFailedNames]
D --> E{For each requested name}
E --> F{Any convergent placements?}
F -- No --> G[Name FAILED - skill removed]
F -- Yes --> H{skillPlacementLanded for each entry}
H --> I{status == current or newer-known?}
I -- Yes --> J[Landed ✓]
I -- No --> K{status == unrecognized AND lockHash defined AND disk SHA == lockHash?}
K -- Yes --> L[Landed ✓ - post-cut source content]
K -- No --> M[Not landed ✗]
H --> N{any entry not landed?}
N -- Yes --> O[Name FAILED]
N -- No --> P[Name SUCCEEDED]
Reviews (1): Last reviewed commit: "fix(skills): trust the updater's lock wh..." | Re-trigger Greptile
…er than the bundle (stablyai#11220) skills update installs source-repo HEAD, which routinely runs ahead of the revisions a shipped build bundles. The post-run re-scan hashed that content 'unrecognized' (the registry has never seen it) and the verdict counted it as a failure — so a clean update reported "The update didn't finish / Updated 0 of N", and Retry repeated the false failure forever because the CLI now no-ops (lock == source). The 'newer-known' escape hatch never fires: the generator always points the manifest at the registry's newest snapshot, so no observed content can hash to a revision newer than the bundle. The verdict now computes the git tree sha of the observed bytes (a port of the generator's hashing, verified byte-for-byte against git write-tree and against every shipped skill's manifest gitTreeSha) and accepts an unrecognized placement when that sha equals the lock's skillFolderHash: the lock is the CLI's own record of what it installed, so disk matching lock means the command did its job — the bundled registry simply has not seen that revision yet. Half-written bundles (sha mismatch), unreadable copies, removed skills, degraded aliases, and outdated copies at the lock hash all still fail.
Sidecar tolerance stopped at the snapshot match, leaving three disk-vs-official comparisons still judging the whole folder. The lock-comparable hash covered every observed file, so a clean update beside agents/openai.yaml reported as failed and read 'may be modified'. It is now carried both whole and scoped to the current bundle's paths, and either may satisfy the lock: the sidecar case only ever matches scoped, while an upstream revision that ADDS a file only ever matches whole, so publishing one alone would trade this bug for stablyai#11220. Convergence re-derived the disk revision from that same whole-folder digest, which no revision matches once a sidecar lands, retiring the stuck-lock gate and arming an update the command provably cannot perform; it now honours the revision observation already resolved. Subset matching also let an older revision launder drift on a file the current bundle lists, since that revision does not list it and so read it as a neighbour. Identity now keys tolerance on what the current bundle owns.
* fix(skills): match official skill files despite local sidecars Scope known-snapshot matching to manifest-listed files so agent-written sidecars (e.g. agents/openai.yaml) no longer mark a package unrecognized and block updates when official bytes still match. Preserves fail-closed detection when a listed file's content drifts. Fixes #12694 * fix(skills): scope lock trust and convergence to official files too Sidecar tolerance stopped at the snapshot match, leaving three disk-vs-official comparisons still judging the whole folder. The lock-comparable hash covered every observed file, so a clean update beside agents/openai.yaml reported as failed and read 'may be modified'. It is now carried both whole and scoped to the current bundle's paths, and either may satisfy the lock: the sidecar case only ever matches scoped, while an upstream revision that ADDS a file only ever matches whole, so publishing one alone would trade this bug for #11220. Convergence re-derived the disk revision from that same whole-folder digest, which no revision matches once a sidecar lands, retiring the stuck-lock gate and arming an update the command provably cannot perform; it now honours the revision observation already resolved. Subset matching also let an older revision launder drift on a file the current bundle lists, since that revision does not list it and so read it as a neighbour. Identity now keys tolerance on what the current bundle owns. --------- Co-authored-by: Jinwoo-H <[email protected]>
…er than the bundle (stablyai#11220) skills update installs source-repo HEAD, which routinely runs ahead of the revisions a shipped build bundles. The post-run re-scan hashed that content 'unrecognized' (the registry has never seen it) and the verdict counted it as a failure — so a clean update reported "The update didn't finish / Updated 0 of N", and Retry repeated the false failure forever because the CLI now no-ops (lock == source). The 'newer-known' escape hatch never fires: the generator always points the manifest at the registry's newest snapshot, so no observed content can hash to a revision newer than the bundle. The verdict now computes the git tree sha of the observed bytes (a port of the generator's hashing, verified byte-for-byte against git write-tree and against every shipped skill's manifest gitTreeSha) and accepts an unrecognized placement when that sha equals the lock's skillFolderHash: the lock is the CLI's own record of what it installed, so disk matching lock means the command did its job — the bundled registry simply has not seen that revision yet. Half-written bundles (sha mismatch), unreadable copies, removed skills, degraded aliases, and outdated copies at the lock hash all still fail.
…yai#12812) * fix(skills): match official skill files despite local sidecars Scope known-snapshot matching to manifest-listed files so agent-written sidecars (e.g. agents/openai.yaml) no longer mark a package unrecognized and block updates when official bytes still match. Preserves fail-closed detection when a listed file's content drifts. Fixes stablyai#12694 * fix(skills): scope lock trust and convergence to official files too Sidecar tolerance stopped at the snapshot match, leaving three disk-vs-official comparisons still judging the whole folder. The lock-comparable hash covered every observed file, so a clean update beside agents/openai.yaml reported as failed and read 'may be modified'. It is now carried both whole and scoped to the current bundle's paths, and either may satisfy the lock: the sidecar case only ever matches scoped, while an upstream revision that ADDS a file only ever matches whole, so publishing one alone would trade this bug for stablyai#11220. Convergence re-derived the disk revision from that same whole-folder digest, which no revision matches once a sidecar lands, retiring the stuck-lock gate and arming an update the command provably cannot perform; it now honours the revision observation already resolved. Subset matching also let an older revision launder drift on a file the current bundle lists, since that revision does not list it and so read it as a neighbour. Identity now keys tolerance on what the current bundle owns. --------- Co-authored-by: Jinwoo-H <[email protected]>
The false-failure loop
npx skills updateinstalls source-repo HEAD, which routinely runs ahead of the revisions a shipped build bundles. After a clean run:unrecognized.skillUpdateFailedNamescountsunrecognizedas not-landed → run stateerror→ "Some skills could not be updated.", dialog "The update didn't finish / Updated 0 of N skills", yellow "Update failed" status segment.The
newer-knownescape hatch built for exactly this case is structurally unreachable:generate-skill-bundle-manifest.mjsalways points the current manifest at the registry's newest snapshot, somax(registry revision) == manifest revisionin every shipped build and no observed content can classify as a known newer revision. 7 of 8 bundled skills have drifted upstream since v1.4.151 alone, so on any shipped release the loop arms the moment a skill changes onmain.The disk-matches-lock rule
The verdict now computes the git tree sha of the observed bytes and treats an
unrecognizedconvergent placement as landed when that sha equals the lock'sskillFolderHash:skill-git-tree-identity.ts), and two tests keep it honest: every shipped skill's folder must hash to the exactgitTreeShathe bundled manifest records, and a synthetic fixture (nested dirs, executable, binary bytes, thez.txt-vs-z/ordering edge) must match realgit write-tree.Nothing else is forgiven — tests pin that a half-written bundle (sha mismatch), a missing lock entry, an unreadable copy, a removed skill, a degraded provider-alias beside a lock-matching canonical copy, and an
outdatedcopy sitting at the lock hash all still fail. An integration test builds the real post-cut state (temp HOME, real bundled artifacts, current bytes + an upstream edit, lock at that tree sha) and asserts an empty failed-names list; it fails onmaintoday.Only the run verdict changes. Freshness classification (
unrecognizedstatus, badges) and update eligibility are untouched.