-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor(coding-agent): move the semantic-edge ledger onto the event-log substrate #2028
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
Open
snimu
wants to merge
8
commits into
main
Choose a base branch
from
refactor/semantic-edges-ledger-on-event-log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d661a30
refactor(coding-agent): move the semantic-edge ledger onto the event-…
snimu 02f1cdd
fix(coding-agent): make the explicit ledger reader's ENOENT contract …
snimu 9e6f959
docs(coding-agent): state the event-log tail rule once
snimu 4904fa0
Merge remote-tracking branch 'origin/main' into refactor/semantic-edg…
snimu ebc1a94
fix(coding-agent): write event-log appends fully and gate appends on …
snimu e88fc98
fix(coding-agent): reclaim short event-log writes instead of completi…
snimu d760284
fix(coding-agent): leave the torn tail on a short write instead of re…
snimu d749cf9
refactor(coding-agent): compress event-log comments
snimu 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
1 change: 1 addition & 0 deletions
1
packages/coding-agent/.changes/res-1260-semantic-edges-on-event-log.md
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 @@ | ||
| - Moved the semantic-edge ledger's append and replay IO onto the shared event-log substrate. One behavior unified across both ledgers: an unterminated final line is an uncommitted append — skipped on read and truncated before the next append, never newline-completed. |
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,64 @@ | ||
| import { appendFileSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { EventLog } from "../src/core/event-log.js"; | ||
|
|
||
| /** Armable fs faults; everything passes through to the real fs by default. */ | ||
| const faults: { shortWriteOnce?: boolean; truncateError?: Error } = {}; | ||
|
|
||
| vi.mock("node:fs", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("node:fs")>(); | ||
| return { | ||
| ...actual, | ||
| writeSync: ((fd: number, data: Uint8Array) => { | ||
| if (faults.shortWriteOnce && data.length > 1) { | ||
| faults.shortWriteOnce = false; | ||
| return actual.writeSync(fd, data.subarray(0, Math.floor(data.length / 2))); | ||
| } | ||
| return actual.writeSync(fd, data); | ||
| }) as typeof actual.writeSync, | ||
| ftruncateSync: ((fd: number, len?: number) => { | ||
| if (faults.truncateError) throw faults.truncateError; | ||
| return actual.ftruncateSync(fd, len); | ||
| }) as typeof actual.ftruncateSync, | ||
| }; | ||
| }); | ||
|
|
||
| describe("event log fault injection", () => { | ||
| let dir: string; | ||
|
|
||
| beforeEach(() => { | ||
| dir = mkdtempSync(join(tmpdir(), "prime-event-log-faults-")); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| faults.shortWriteOnce = undefined; | ||
| faults.truncateError = undefined; | ||
| rmSync(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it("persists the full payload even when the kernel writes short", () => { | ||
| const path = join(dir, "log.jsonl"); | ||
| const log = new EventLog(path); | ||
| faults.shortWriteOnce = true; | ||
| log.appendSync([{ v: 1, id: "short-write-survivor" }]); | ||
|
|
||
| expect(new EventLog(path).replaySync((line) => JSON.parse(line) as { id?: string })).toEqual([ | ||
| { v: 1, id: "short-write-survivor" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("refuses to append through a tail it could not repair", () => { | ||
| const path = join(dir, "log.jsonl"); | ||
| const log = new EventLog(path); | ||
| log.appendSync([{ v: 1, id: "committed" }]); | ||
| appendFileSync(path, '{"torn'); | ||
| const before = readFileSync(path, "utf8"); | ||
|
|
||
| faults.truncateError = new Error("EPERM: append-only file"); | ||
| // Writing through would weld the torn tail to the new record forever. | ||
| expect(() => log.appendSync([{ v: 1, id: "next" }])).toThrow(/EPERM/); | ||
| expect(readFileSync(path, "utf8")).toBe(before); | ||
| }); | ||
| }); |
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
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.