Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
22c6630
feat(file-safety): atomic text publish primitive + safeWriteJson refa…
easonliang28 Aug 27, 2026
81a3173
feat(task): per-task file observation registry (A2, #1375)
easonliang28 Aug 27, 2026
06dea5b
feat(tools): guarded write CAS core with per-path FIFO chain (S4a, #1…
easonliang28 Aug 27, 2026
6e5a4d8
feat(tools): wire guarded writes into the diff-view save paths (S4b, …
easonliang28 Aug 27, 2026
fe49781
fix(fws): observe the apply_patch hunk read for the guarded publish
easonliang28 Aug 28, 2026
f8dd6c3
chore(ci): empty commit — re-trigger CI and the CodeRabbit current-he…
easonliang28 Aug 30, 2026
d483304
fix(tools): run the guard check and the publish under one lock
Oct 6, 2026
dc4fd44
test(editor): mock the advisory lock the guarded write now uses
Oct 6, 2026
f29cc4e
fix(file-safety): remove the staging directory once the commit lands
Oct 6, 2026
89ba355
fix(guarded-write): refresh the observation after a publish, survive …
Oct 6, 2026
1144375
test(tools): nest the atomicity suite, tighten the legacy observation…
Oct 6, 2026
38532fc
fix(tools): lock the canonical publish target for guarded writes
Oct 7, 2026
24b12a9
test(editor): expose resolvePublishTarget on the DiffViewProvider saf…
Oct 7, 2026
4bf7625
fix(file-safety): back up by copy so a failed write never moves the t…
Oct 7, 2026
4c29f96
fix(file-safety): make the backup copy writable before fsyncing it
Oct 7, 2026
a9943b1
fix(file-safety): create the backup privately before its content exists
Oct 7, 2026
8821a2e
chore: trigger a fresh review pass at this head
Oct 7, 2026
6e06966
fix(core): authorize the focus-disruption apply_diff save with its ow…
Oct 7, 2026
e1c12f6
fix(core): type the stat doubles in the apply_diff observation test
Oct 7, 2026
5da6fe3
fix(file-safety): verify the guard at commit time and clean the stagi…
Oct 8, 2026
6cd0d06
test(editor): expect the commit verifier on the guarded saveDirectly …
Oct 8, 2026
77a9548
test(tools): pin that both stat reads happen when one fails
Oct 8, 2026
530b3a8
fix(tools): stop a queued guarded write once its task is disposed, an…
Oct 8, 2026
e1d6841
test(tools): cover the commit-time verifiers in guardedWrite
Oct 8, 2026
825af6f
fix(test): drop the duplicate Task import the merge with main left be…
Oct 10, 2026
ccc8594
style: reformat the guarded-write files to prettier output
Oct 10, 2026
ff2ab63
fix(tools): record the version each edit tool reads before a guarded …
Oct 11, 2026
08a30dc
test(tools): make the path mock cover the default import
Oct 11, 2026
5f77726
fix(file-safety): remove a partial DACL dump, and finish the verify-c…
Oct 11, 2026
27797d2
test(tools): cover the stat branches the guarded edit observation added
Oct 11, 2026
f20acbd
fix(file-safety): give this write's own dump and staging paths names …
Oct 11, 2026
53ad7d7
fix(file-safety): stop retrying a staging open that cannot recover
Oct 11, 2026
4f299c5
fix(tools): observe the self-read token only at the guarded publish
Oct 11, 2026
e976591
test(tools): cover the diff-view branch of the observation rule
Oct 11, 2026
6e0b4af
style(tools): drop imports unused after the main refresh (lint gate)
easonLiangWorldedtech Oct 16, 2026
24d36f9
style(file-safety): drop SafeWriteTextOptions type import unused afte…
easonLiangWorldedtech Oct 16, 2026
ca6c518
fix(tools): enforce the canonical working directory in guardedWrite
easonLiangWorldedtech Oct 16, 2026
3519b23
test(editor): give the saveDirectly spec the mocks the root check needs
easonLiangWorldedtech Oct 16, 2026
1f316d1
feat(s4b): guard the legacy diff-editor save path and re-check the ro…
easonLiangWorldedtech Oct 17, 2026
2eec81c
fix(s4b): roll the rejected saveChanges buffer back with an editor edit
easonLiangWorldedtech Oct 17, 2026
529c830
fix(s4b): do not save the document after the guarded publish
easonLiangWorldedtech Oct 17, 2026
0e14314
fix(s4b): record the diff-open observation the guarded saveChanges CA…
easonLiangWorldedtech Oct 17, 2026
3f4b6ac
fix(s4b): carry rolled-back user edits in the rejection remediation
easonLiangWorldedtech Oct 17, 2026
63a9856
fix(diffview): capture the version token before reading the original …
Oct 21, 2026
2952155
chore(guarded-write): mark the test-only chain reset as internal
Oct 21, 2026
c5be376
test(core): double fs/promises stat for the guarded-read wiring
easonLiangWorldedtech Nov 3, 2026
27cda88
fix(tools): fail apply_diff stale and pin the read result in stat-fai…
easonLiangWorldedtech Nov 3, 2026
5739381
test(tools): give the failure-reporting fixture the save baseline ope…
easonLiangWorldedtech Nov 3, 2026
874f7d1
test(tools): assert the file body in the stat-failure read tests
easonLiangWorldedtech Nov 3, 2026
b4da906
test(task): cover observation-registry isolation at the Task layer
easonLiangWorldedtech Nov 5, 2026
5bac54a
fix(file-safety): retry and retain a backup whose cleanup failed
easonLiangWorldedtech Nov 5, 2026
2a37d7e
fix(file-safety): retry retained backups at the start of the next write
easonLiangWorldedtech Nov 5, 2026
6cd9567
fix(file-safety): treat an already-gone backup as removed, not as wor…
easonLiangWorldedtech Nov 7, 2026
4f7cd00
fix(file-safety): hand a backup whose failure-path removal fails to t…
easonLiangWorldedtech Nov 7, 2026
6004a76
test(file-safety): assert the retained backup, and drain the pending …
easonLiangWorldedtech Nov 7, 2026
173982c
fix(file-safety): answer the guarded-write review rows on links, targ…
easonLiangWorldedtech Nov 7, 2026
176a388
fix(editor): stop saveDirectly from saving a document that may hold u…
easonLiangWorldedtech Nov 7, 2026
8592d67
fix(file-safety): propagate a failed target lstat and only remove a b…
easonLiangWorldedtech Nov 8, 2026
1a06922
fix(file-safety): hand a caller-staged temp file back when target res…
easonLiangWorldedtech Nov 8, 2026
abc6b20
fix(file-safety): hand back a caller-staged temp file when directory …
easonLiangWorldedtech Nov 8, 2026
ddd9119
test(file-safety): assert a directory-setup refusal stops before the …
easonLiangWorldedtech Nov 8, 2026
db582ba
test(tools): drive the guardedWrite double's abort through requestAbort
easonLiangWorldedtech Nov 8, 2026
bbedf8b
test(tools): drive the guarded-write cancellation double through Task…
easonLiangWorldedtech Nov 9, 2026
94ca5fc
fix(apply-diff): refuse the direct save a stale observation would aut…
easonLiangWorldedtech Nov 13, 2026
fa49239
fix(apply-diff): retire the abandoned read's observation after a stal…
easonLiangWorldedtech Nov 13, 2026
478c107
test(guarded-write): bind the FIFO chain to blocked publishes and a p…
easonLiangWorldedtech Nov 13, 2026
9adcbc9
fix(tools): re-adjudicate the s4b rebase onto main's evolved architec…
Nov 28, 2026
28e95d6
fix(1408): drop the unused catch binding in the two read paths (lint …
easonLiangWorldedtech Nov 28, 2026
1594032
chore(1408): prune the suppression count the lint gate reports as lef…
easonLiangWorldedtech Nov 28, 2026
f4473d3
fix(apply-diff): retire the observation when the rollback itself rejects
easonLiangWorldedtech Nov 29, 2026
b1a8e09
fix(apply-patch): refuse the publish an older observation would autho…
easonLiangWorldedtech Nov 29, 2026
aca45b7
test(guarded-write): gate the FIFO rows instead of timing them
easonLiangWorldedtech Nov 29, 2026
75ee343
fix(read-file): record whether each read handed over the whole file
easonLiangWorldedtech Nov 29, 2026
f9f8815
fix(guarded-write): refuse a full-file replacement over a partial read
easonLiangWorldedtech Nov 29, 2026
c726735
docs(observation-registry): match the docstring to what the code actu…
easonLiangWorldedtech Nov 29, 2026
59cfaa9
fix(guarded-write): read the observation before the validation await
easonLiangWorldedtech Nov 29, 2026
9d84046
fix(guarded-write): report an inspection failure instead of blaming t…
easonLiangWorldedtech Nov 29, 2026
a5567e3
fix(diff-view): keep the file's byte-order mark through the guarded p…
easonLiangWorldedtech Nov 29, 2026
8c16a46
fix(guarded-write): keep the prior completeness when an edit publishes
easonLiangWorldedtech Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/core/task/__tests__/observationRegistry.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

259 changes: 259 additions & 0 deletions src/core/task/__tests__/taskObservationRegistry.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 49 additions & 16 deletions src/core/task/observationRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/**
* 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.
* Each Task owns its own instance so parent and subtask observations are independent.
*
* Pure in-memory — zero I/O, no dependencies. The S4 guarded-write consults
* these observations for the version check and for the completeness check that
* gates a full-file replacement.
* Pure in-memory — zero I/O, no dependencies. The guarded write (src/core/tools/guardedWrite.ts)
* consults these observations twice:
* - every write compares `version` against the token it recomputes under its own lock, which is
* how a stale read or a file replacement is detected;
* - a full-file replacement — kind "create" or "update" landing on a path that was observed and
* is still on disk (src/core/tools/guardedWrite.ts:496) — additionally requires `complete`.
* A targeted edit (kind "edit") is not gated on completeness, and no other production code reads
* the flag: it exists for that one decision.
*
* A publish re-observes the path it wrote, and it records the completeness its own kind earns: a
* full-file replacement produced the whole file, so it records true, while a targeted edit only
* published lines, so it carries the previous value forward (src/core/tools/guardedWrite.ts:521)
* rather than claiming a whole-file read the model never had.
*/

export interface FileObservation {
Expand All @@ -16,10 +24,17 @@ export interface FileObservation {
/** Millisecond timestamp when the observation was recorded. */
observedAt: number
/**
* Whether the read that produced this observation returned the complete
* file. A slice, line-range, truncated, or indentation-block read returns
* only a view of the file; such an observation authorizes targeted edits
* on the view the model saw, but never a full-file replacement.
* Whether what this observation was recorded for covers every line of the file.
*
* A slice, line-range, truncated or indentation-block read hands over a view rather than the
* file and records false. The flag describes the coverage of that delivery and nothing more: it
* is not a claim that the model has seen, or still remembers, every line of the file. Only the
* full-file replacement consults it — that write replaces lines the model cannot see from a
* partial view, so it needs an observation of the whole file to be allowed at all.
*
* A publish records the flag too, and only ever from its own kind: a full-file replacement holds
* the whole file it just wrote, a targeted edit carries forward whatever the observation it was
* issued with said.
*/
complete: boolean
}
Expand All @@ -34,12 +49,18 @@ export class ObservationRegistry {
/**
* Record an observation for a file at its absolute path.
*
* Re-observing replaces the entry with a fresh observedAt timestamp, the
* new version token, and the read's completeness. `complete` defaults to
* true for callers that read the whole file themselves (spec doubles,
* WriteToFileTool). A caller whose read is internal to a targeted edit must
* carry the model's prior completeness instead, so the tool's own read cannot
* upgrade a partial read into authority for a full-file replacement.
* Re-observing replaces the entry with a fresh observedAt timestamp, the new version token,
* and this delivery's completeness.
*
* `complete` defaults to true because the callers that lean on the default either read the whole
* file or published it: guardedWrite records true after a full-file replacement, because the file
* on disk is then exactly the content that write carried (src/core/tools/guardedWrite.ts:521).
* Neither claim says anything about how much of an earlier read the model was shown. On a
* targeted edit guardedWrite passes the flag explicitly instead: the edit published lines
* computed against the current file rather than replacing a view, so it carries forward the
* completeness it was issued with, and a partial read followed by an edit still refuses a later
* full-file replacement. read_file is the caller that passes false, on both of its paths,
* whenever it handed over only a view.
*/
observe(absolutePath: string, version: string, complete: boolean = true): void {
if (this.retired) {
Expand All @@ -56,6 +77,18 @@ export class ObservationRegistry {
return this.entries.has(absolutePath)
}

/**
* Drop the observation for one path, leaving every other path observed.
*
* A tool that abandons its own read - a stale diff it will not save - must not leave
* that read's version token behind as authority for some later write. Retiring the
* whole registry would strip observations that belong to other files and to other
* tasks' work, so the removal is per path. Reports whether an entry was removed.
*/
forget(absolutePath: string): boolean {
return this.entries.delete(absolutePath)
}

clear(): void {
this.entries.clear()
}
Expand Down
Loading
Loading