Repository navigation
feat(task): per-task file observation registry (A2, #1375) #1394
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
easonLiangWorldedtech
wants to merge
23
commits into
Zoo-Code-Org:main
Choose a base branch
from
easonLiangWorldedtech:feat/observation-registry-s2
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 all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
131d18d
feat(file-safety): add version token for the guarded-write path (A1, …
easonliang28 13188d2
docs(file-safety): correct ino precision bounds in version token (A1,…
easonliang28 2c1582b
fix(file-safety): derive the version token from exact BigInt stats (A…
easonliang28 2965ad1
feat(task): per-task file observation registry (A2, #1375)
easonliang28 a00eef8
chore(ci): empty commit — re-trigger CI and the CodeRabbit current-he…
easonliang28 05c845d
Merge commit '0d937c050810ebc305b34368bf6d6ae8c1f89966' into feat/obs…
easonliang28 30f5d8c
Merge remote-tracking branch 'upstream/main' into feat/observation-re…
easonliang28 988f1e2
test(registry): restore fake timers in teardown and cover token-looku…
easonliang28 6b821b2
test(registry): assert read content in the token-failure regression t…
easonliang28 5a4e27e
Merge branch 'main' into feat/observation-registry-s2
easonliang28 770f21b
chore(ci): empty commit — trigger the CodeRabbit review at head (chat…
bcefb66
Merge upstream/main (9af61f87e) to satisfy the branch-freshness thres…
easonLiangWorldedtech 0cb754c
fix(observation): drop a stale observation when a later token lookup …
932b2f1
chore(merge): refresh onto main 4f1dee18e
easonLiangWorldedtech addf98b
style(tools): drop imports unused after the main refresh (lint gate)
easonLiangWorldedtech a4d9f01
test(core): drop a stale observation when the version token is unreso…
easonLiangWorldedtech 9dc3b15
test(core): cover observation-registry privacy across a parent and su…
easonLiangWorldedtech 9fe680c
Merge upstream/main into feat/observation-registry-s2
easonLiangWorldedtech dd060a4
fix(tools): take the read version token before the read, and pin the …
easonLiangWorldedtech 57b98c9
test(tools): pin the legacy token order and fold the stat double
easonLiangWorldedtech 323d2d8
test(tools): pin what a rejecting context tracker leaves behind
easonLiangWorldedtech afe6024
refactor(task): drop the registry accessors no production code calls
easonLiangWorldedtech 06658a8
Merge upstream/main 73931fe into feat/observation-registry-s2
easonLiangWorldedtech 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { describe, it, expect, vi } from "vitest" | ||
|
|
||
| import { ObservationRegistry } from "../observationRegistry" | ||
|
|
||
| describe("ObservationRegistry", () => { | ||
| it("observe → get returns the recorded version and the clock time it observed at", () => { | ||
| // typeof number accepts 0 and NaN, so pin the exact timestamp instead: a | ||
| // broken clock that returns some other number must not pass. | ||
| vi.useFakeTimers() | ||
| vi.setSystemTime(new Date(Date.UTC(2025, 0, 1, 0, 0, 0, 0))) | ||
| try { | ||
| const reg = new ObservationRegistry() | ||
| reg.observe("/a/b/c.ts", "1:2:300:4000000000:5000000000") | ||
| const obs = reg.get("/a/b/c.ts") | ||
| expect(obs).toBeDefined() | ||
| expect(obs!.version).toBe("1:2:300:4000000000:5000000000") | ||
| expect(obs!.observedAt).toBe(Date.UTC(2025, 0, 1, 0, 0, 0, 0)) | ||
| } finally { | ||
| vi.useRealTimers() | ||
| } | ||
| }) | ||
|
|
||
| it("re-observe replaces the entry with a fresh observedAt", () => { | ||
| vi.useFakeTimers() | ||
| try { | ||
| const reg = new ObservationRegistry() | ||
| reg.observe("/a/b/c.ts", "v1") | ||
| const first = reg.get("/a/b/c.ts")! | ||
| expect(first.version).toBe("v1") | ||
|
|
||
| vi.advanceTimersByTime(50) | ||
| reg.observe("/a/b/c.ts", "v2") | ||
| const second = reg.get("/a/b/c.ts")! | ||
| expect(second.version).toBe("v2") | ||
| expect(second.observedAt).toBeGreaterThan(first.observedAt) | ||
| } finally { | ||
| // Teardown in finally so a failing assertion cannot leak fake | ||
| // timers or the mocked Date into subsequent tests. | ||
| vi.useRealTimers() | ||
| } | ||
| }) | ||
|
|
||
| it("forget drops a warm entry so a later read cannot be guarded by a stale token", () => { | ||
| const reg = new ObservationRegistry() | ||
| reg.observe("/x.ts", "t1") | ||
|
|
||
| // The warm case: an entry from an earlier read must not survive a read that could not | ||
| // compute a token for the current on-disk version. | ||
| expect(reg.forget("/x.ts")).toBe(true) | ||
| expect(reg.get("/x.ts")).toBeUndefined() | ||
|
|
||
| // The cold case: forgetting an unobserved path is a no-op, not an error. | ||
| expect(reg.forget("/y.ts")).toBe(false) | ||
| expect(reg.get("/y.ts")).toBeUndefined() | ||
| }) | ||
|
|
||
| it("get on empty registry returns undefined", () => { | ||
| const reg = new ObservationRegistry() | ||
| expect(reg.get("/any.ts")).toBeUndefined() | ||
| }) | ||
|
|
||
| it("separate instances are independent — observing in one does not appear in the other", () => { | ||
| const regA = new ObservationRegistry() | ||
| const regB = new ObservationRegistry() | ||
| regA.observe("/shared.ts", "v1") | ||
| expect(regA.get("/shared.ts")).toBeDefined() | ||
| expect(regB.get("/shared.ts")).toBeUndefined() | ||
| regB.observe("/shared.ts", "v2") | ||
| expect(regA.get("/shared.ts")!.version).toBe("v1") | ||
| expect(regB.get("/shared.ts")!.version).toBe("v2") | ||
| }) | ||
| }) | ||
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,49 @@ | ||
| /** | ||
| * Per-task file observation registry (upstream epic #1375, phase A2). | ||
| * | ||
| * Each Task owns its own instance so parent and subtask observations are | ||
| * independent. The S4 guarded-write will compare these versions against the | ||
| * token recomputed pre-write to detect stale reads or file replacement. | ||
| * | ||
| * Pure in-memory — zero I/O, no dependencies. Nothing in this PR reads an | ||
| * observation back out; the guard that will compare these tokens is a later phase. | ||
| * | ||
| * Only observe, forget and get are exposed: the S4 guard is the only named consumer. A | ||
| * per-task instance needs no reset - the next task constructs a new registry - so has, size | ||
| * and clear land with whoever needs them (a registry shared across tasks would need the | ||
| * reset, and that is not decided yet). | ||
| */ | ||
|
|
||
| export interface FileObservation { | ||
| /** Version token derived from on-disk fs.stat (bigint mode). */ | ||
| version: string | ||
| /** Millisecond timestamp when the observation was recorded. */ | ||
| observedAt: number | ||
| } | ||
|
|
||
| export class ObservationRegistry { | ||
| private readonly entries = new Map<string, FileObservation>() | ||
|
|
||
| /** | ||
| * Record an observation for a file at its absolute path. | ||
| * | ||
| * Re-observing replaces the entry with a fresh observedAt timestamp and | ||
| * the new version token. | ||
| */ | ||
| observe(absolutePath: string, version: string): void { | ||
| this.entries.set(absolutePath, { version, observedAt: Date.now() }) | ||
| } | ||
|
|
||
| /** | ||
| * Drop the observation for a file. A read that cannot compute a version token must not | ||
| * leave an earlier entry behind, because the write guard would then compare against a | ||
| * token that no longer describes the last read. | ||
| */ | ||
| forget(absolutePath: string): boolean { | ||
| return this.entries.delete(absolutePath) | ||
| } | ||
|
|
||
| get(absolutePath: string): FileObservation | undefined { | ||
| return this.entries.get(absolutePath) | ||
| } | ||
| } |
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.
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.