Skip to content

fix(memory): fence Wiki publication after lock ownership is lost - #423

Open
Afloat16 wants to merge 1 commit into
simplexai-labs:mainfrom
Afloat16:afloat/wiki-publication-lock-fence
Open

Afloat16 wants to merge 1 commit into
simplexai-labs:mainfrom
Afloat16:afloat/wiki-publication-lock-fence

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Stop Wiki publication after the lock library reports lost ownership, checking before destructive writes and again after staging before rename. Unique temporary-file cleanup and successor lock ownership remain intact.

How it was verified

  • Base: 77abdcb; Node 26.5.0, pnpm 11.7.0.

  • Before: 3 regression failures and 2 passing layout controls on base.

  • After: 6 tests pass (3 lock-loss regressions, layout and existing lock compromise controls); node-services typecheck, changed ESLint and diff pass.

  • Command: pnpm --filter @linger/node-services exec vitest run tests/memory/published-lock-fence.test.ts tests/memory/personal-layout.test.ts tests/memory/filesystem-lock-compromise.test.ts --maxWorkers=1.

  • The full owning-app fast gate now passes; see the exact-head validation below.

  • Focused tests for the changed behavior

  • make check BASE=origin/<target-branch> or the fast checks of every touched app

  • No contracts changed

Boundary

Nearest owning documentation records the behavior. No network call or dependency is added.

The fault tests use real page files and the production publication API. They deliver the existing lock library's compromise callback after staging a file or while scanning the tree, then verify that replacement, retirement and case-renaming do not mutate the old page. A subsequent valid writer succeeds. These are deterministic loss-of-ownership tests, not a claim of testing a live distributed filesystem.

These are ownership checks at mutation boundaries, not an atomic filesystem fencing primitive. They cannot prevent a new ownership loss occurring between the final check and the filesystem mutation.

Validation follow-up

On 8f5928215f0175a3fdf98e1ffc49423ea375fa79, pnpm --filter @linger/node-services check passes with Node 26.5.0 and pnpm 11.7.0: the feature catalog/typecheck and full ESLint gates pass, followed by 269 test files passed, 8 skipped; 2,714 tests passed, 51 skipped. No additional test exclusions, source changes, or lockfile changes were needed.

This establishes the owning app's full fast gate. Unrelated full-repository and optional integration/acceptance suites were not run. The deterministic loss-of-ownership tests retain the filesystem fencing limits described above.

The first complete invocation had one failure in the unchanged Document realtime admission test: a second connection was admitted after the first connection's 250 ms token expired. The two authentication log entries were 362 ms apart. The test file passes both tests when run directly on this head and on original base 77abdcb37f779f9c9d2de89fa245efa88d3f6584; the Document implementation and test directory are unchanged between those revisions. The complete check was then rerun once with an isolated temporary directory and passed. No test timeout, assertion or skip was changed.

@Afloat16
Afloat16 marked this pull request as ready for review November 25, 2026 06:02

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve (0 findings)

Scope: base main, merge base 77abdcb3, 1 commit, 3 files reviewed. Helper skill loaded: ponytail-review (sections 1–3); coderbook and karpathy-guidelines were not loaded, and their criteria were applied from the review brief. Ran in a separate session.

Findings

None.

Verified as fine

  • Fence mechanism is reused, not duplicated. assertDirectoryLock already exists (apps/node-services/src/memory/filesystem-lock.ts:9) and reads the per-operation state.error that onCompromised sets (filesystem-lock.ts:41-43). The PR only adds calls to it. The new pattern (assert before the temp write, assert again before rename) is the same one used in fs-utils.ts:23,29,45,50 and user-memory-sync.ts:75,77.
  • Every destructive mutation in publishMemoryWiki is now fenced. The case-collision unlink is fenced at published-memory-files.ts:157, the staged rename at :177, and the retirement unlink at :195. The trailing writeAtomicJsonFile and the finally markMemoryChanged were already fenced inside fs-utils.ts. mkdir and the reads are not destructive.
  • Temp cleanup and the successor lock are safe after loss of ownership. The finally { fs.rm(tmp, { force: true }) } deletes only this writer's randomUUID() file. withDirectoryLock skips release() when state.error is set (filesystem-lock.ts:52), so a successor's lock is not released. The test asserts both (readdir(memory-state) is empty, and release is not called).
  • The tests fail without the fix. I put the base version of published-memory-files.ts back in place and ran published-lock-fence.test.ts. All 3 tests failed: without the fence, the outer post-operation assert still throws, but the page has already been replaced or unlinked. With the PR, both published-lock-fence.test.ts and filesystem-lock-compromise.test.ts pass (4/4).
  • Test doubles match the real library. Only proper-lockfile.lock is mocked, and it captures the real onCompromised option that the production code passes. The filesystem calls are real, with spies that pass through to the real functions.
  • The PR body is upfront that the remaining window between the final check and the syscall is a known limit; the code does not claim otherwise.
  • Docs: src/memory/README.md records the behavior in the same PR. There are no contract or env changes, and no CJK in the added lines or the commit message.

Process notes

  • 1 commit, no merge commits, no fixup commits. The commit author is linked to the GitHub account Afloat16.
  • Merge state is BLOCKED (waiting on the required review).

CI

repository-gate, changes and check (web) pass; the other jobs were skipped by the path filter. CI does not run node-services tests (.github/workflows/ci.yml:11-14). I ran them locally: vitest run tests/memory/published-lock-fence.test.ts tests/memory/filesystem-lock-compromise.test.ts passed (4/4), and the new test file fails 3/3 against the base source.

Automated review by Claude Code


Automated review of 8f59282 by Claude Code.

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.

1 participant