Skip to content

fix(ocap-kernel): sort GC krefs before hardening them - #1082

Merged
sirtimid merged 1 commit into
mainfrom
sirtimid/gc-sort-krefs-before-harden
Sep 18, 2026
Merged

sirtimid merged 1 commit into
mainfrom
sirtimid/gc-sort-krefs-before-harden

Conversation

@sirtimid

@sirtimid sirtimid commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

processGCActionSet sorted the kref list after filterActionsForProcessing had hardened it. Array.prototype.sort writes every element back even when the array is already in order, so any endpoint with two pending GC actions of one type threw a TypeError out of the run loop. One vat dropping two exports in a crank was enough, and it reproduces on main.

Re-landed from #1022 as part of the split of #1021–#1023 into single-defect PRs.

Changes

  • filterActionsForProcessing sorts krefs before the harden; the sort in processGCActionSet is gone.
  • New test: groups two actions of one type for one vat into a single item.
  • Changelog entry for @metamask/ocap-kernel.

Testing

The new test fails on main with TypeError: Cannot assign to read only property '0' and passes with the fix. The full @metamask/ocap-kernel unit suite passes locally.

🤖 Generated with Claude Code


Note

Low Risk
Small, localized GC ordering fix with a targeted regression test; avoids mutating hardened arrays without changing GC semantics beyond stable kref ordering.

Overview
Fixes a run-loop crash when one endpoint has two or more pending GC actions of the same type (e.g. a vat dropping two exports in one crank).

filterActionsForProcessing now sorts krefs before harden, because sorting a frozen array throws. The duplicate sort in processGCActionSet is removed; the returned queue item still hardens a copy of the sorted list (krefs: [...krefs]).

Adds a regression test that groups two dropExport actions for one vat into a single dropExports item, and documents the fix in the package changelog.

Reviewed by Cursor Bugbot for commit 1355e60. Bugbot is set up for automated code reviews on this repo. Configure here.

@sirtimid
sirtimid requested a review from a team as a code owner September 15, 2026 15:39
@sirtimid
sirtimid force-pushed the sirtimid/gc-sort-krefs-before-harden branch from b32de04 to 7435e1e Compare September 18, 2026 17:19
`processGCActionSet` sorted the kref list `filterActionsForProcessing` had
already hardened, so any endpoint with two pending actions of one type threw
a TypeError out of the run loop.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 73.05%
⬆️ +0.01%
9790 / 13401
🔵 Statements 72.9%
⬆️ +0.01%
9954 / 13653
🔵 Functions 73.6%
🟰 ±0%
2301 / 3126
🔵 Branches 67.29%
⬆️ +0.04%
4024 / 5980
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ocap-kernel/src/garbage-collection/garbage-collection.ts 98.27%
🟰 ±0%
96.66%
⬆️ +3.33%
100%
🟰 ±0%
98.27%
🟰 ±0%
78
Generated in workflow #4850 for commit 1355e60 by the Vitest Coverage Report Action

@sirtimid
sirtimid force-pushed the sirtimid/gc-sort-krefs-before-harden branch from 7435e1e to 1355e60 Compare September 18, 2026 17:36

@FUDCo FUDCo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small is beautiful.

@sirtimid
sirtimid added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 7da8678 Sep 18, 2026
30 checks passed
@sirtimid
sirtimid deleted the sirtimid/gc-sort-krefs-before-harden branch September 18, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants