Repository navigation
fix(scope): prevent parallel slice creates from reusing IDs #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mvschwarz
merged 7 commits into
mvschwarz:main
from
rudycelekli:fix/concurrent-slice-create
Oct 12, 2026
+640
−42
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fd6a4a
fix(scope): prevent overlapping creates from reusing slice IDs
rudycelekli 88a4761
fix(scope): preserve creation outcome when guard cleanup fails
rudycelekli d266cb2
fix(cli): reconcile completed slice scaffolds after concurrent creates
rudycelekli 751265e
fix(scope): repair only unfinished slice registrations
rudycelekli 465e94f
fix(scope): preserve shared parent state on scaffold failure
rudycelekli cee2934
test(cli): match slice concurrency checks to admitted guarantees
rudycelekli 25c9bd5
test(cli): observe isolated parent persistence writes
rudycelekli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { randomUUID } from "node:crypto"; | ||
|
|
||
| const SCHEMA = "openrig.slice-claim/v1"; | ||
| interface SliceClaim { schema: typeof SCHEMA; ref: string; state: "pending" | "verified" } | ||
|
|
||
| /** One persistent claim reserves the ordinal and records unfinished registration. */ | ||
| export function tryClaimSliceNN(missionPath: string, nn: number, ref: string): boolean { | ||
| const slices = path.join(missionPath, "slices"); | ||
| fs.mkdirSync(slices, { recursive: true }); | ||
| let fd: number; | ||
| try { | ||
| fd = fs.openSync(path.join(slices, `.nn-${String(nn).padStart(2, "0")}`), "wx"); | ||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code === "EEXIST") return false; | ||
| throw error; | ||
| } | ||
| try { | ||
| fs.writeFileSync(fd, JSON.stringify({ schema: SCHEMA, ref, state: "pending" } satisfies SliceClaim) + "\n"); | ||
| } finally { | ||
| fs.closeSync(fd); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| function readClaim(missionPath: string, marker: string): SliceClaim | null { | ||
| const ordinal = /^\.nn-(\d+)$/.exec(marker); | ||
| if (!ordinal) return null; | ||
| const file = path.join(missionPath, "slices", marker); | ||
| if (!fs.lstatSync(file).isFile()) return null; | ||
| let claim: unknown; | ||
| try { claim = JSON.parse(fs.readFileSync(file, "utf8")); } | ||
| catch (error) { | ||
| if (error instanceof SyntaxError) return null; // Legacy/partial marker reserves only a number. | ||
| throw error; | ||
| } | ||
| if (!claim || typeof claim !== "object") return null; | ||
| const value = claim as Partial<SliceClaim>; | ||
| if (value.schema !== SCHEMA || (value.state !== "pending" && value.state !== "verified") || typeof value.ref !== "string") return null; | ||
| const folder = /^slices\/(\d+)-[^/\\]+\/slice\.yaml$/.exec(value.ref); | ||
| if (!folder || Number(folder[1]) !== Number(ordinal[1])) return null; | ||
| return value as SliceClaim; | ||
| } | ||
|
|
||
| /** Older unlisted folders and verified registrations are never adopted. */ | ||
| export function pendingCompletedSliceRefs(missionPath: string): string[] { | ||
| const slices = path.join(missionPath, "slices"); | ||
| if (!fs.existsSync(slices)) return []; | ||
| const refs: string[] = []; | ||
| for (const marker of fs.readdirSync(slices)) { | ||
| const claim = readClaim(missionPath, marker); | ||
| if (claim?.state !== "pending") continue; | ||
| const slice = path.dirname(path.join(missionPath, claim.ref)); | ||
| if (fs.existsSync(path.join(slice, "PROOF.md")) && fs.existsSync(path.join(slice, "slice.yaml"))) refs.push(claim.ref); | ||
| } | ||
| return refs.sort(); | ||
| } | ||
|
|
||
| /** Retire pending evidence after observing registration, including a repaired peer. | ||
| * A stale manifest rename after this observation is not automatically repaired. */ | ||
| export function markSliceRegistrationsVerified(missionPath: string, refs: string[]): void { | ||
| const registered = new Set(refs.map((ref) => path.normalize(ref))); | ||
| const slices = path.join(missionPath, "slices"); | ||
| for (const marker of fs.readdirSync(slices)) { | ||
| const claim = readClaim(missionPath, marker); | ||
| if (claim?.state !== "pending" || !registered.has(path.normalize(claim.ref))) continue; | ||
| const file = path.join(slices, marker); | ||
| const temporary = `${file}.${process.pid}-${randomUUID()}.tmp`; | ||
| try { | ||
| fs.writeFileSync(temporary, JSON.stringify({ ...claim, state: "verified" }) + "\n", { flag: "wx" }); | ||
| fs.renameSync(temporary, file); | ||
| } finally { | ||
| fs.rmSync(temporary, { force: true }); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.