Skip to content

fix(watch): preserve final rapid-write state#78

Open
reneleonhardt wants to merge 1 commit into
JordanCoin:mainfrom
reneleonhardt:fix/watch-debounce
Open

fix(watch): preserve final rapid-write state#78
reneleonhardt wants to merge 1 commit into
JordanCoin:mainfrom
reneleonhardt:fix/watch-debounce

Conversation

@reneleonhardt

@reneleonhardt reneleonhardt commented Jul 12, 2026

Copy link
Copy Markdown

What does this PR do?

  • Preserve the final state from rapid successive file writes.
  • Skip a debounced write only when the cached file size already matches the file on disk.
  • Refresh stale graph state instead of treating every write inside the debounce window as a duplicate.
  • Strengthen the daemon test to require the final source-file event and a positive delta.

Type of change

  • Bug fix
  • New feature
  • New language support
  • Documentation
  • Other (describe below)

Checklist

  • I've tested this locally with go build && ./codemap .
  • I've read CONTRIBUTING.md (for new language support)
  • I've updated documentation if needed

Additional notes

Filesystem watchers can emit multiple write notifications for one logical save. Time-based debouncing alone could discard the final notification while the cached graph still described an earlier file state. The debounce decision now checks the current file size against the cached state before skipping a rapid write.

Focused debounce/daemon tests pass with the full race suite, formatting,
module verification, vet, staticcheck, and a debug build/smoke run.

Reviewer setup:

set -euo pipefail

ROOT=$PWD
BRANCH=fix/watch-debounce
REVIEW_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/codemap-watch-debounce.XXXXXX")
WT="$REVIEW_ROOT/worktree"
DEBUG_BIN="$REVIEW_ROOT/codemap-debug"
COVERAGE_OUT="$REVIEW_ROOT/coverage.out"

git worktree add --detach "$WT" "$BRANCH"

cleanup() {
  cd "$ROOT"
  git worktree remove --force "$WT"
  rm -rf "$REVIEW_ROOT"
}
trap cleanup EXIT

cd "$WT"
go fmt ./...
git diff --exit-code
go mod verify
go vet ./...
staticcheck ./...
go test ./watch -run 'TestDaemonDoesNotDebounceWriteWhenCachedSizeIsStale|TestEventDebouncerSkipsRapidWrites|TestDaemonStartTracksWriteEventsAndState' -count=1
go test -race -coverprofile="$COVERAGE_OUT" ./...
go build -gcflags='all=-N -l' -o "$DEBUG_BIN" .
"$DEBUG_BIN" .
cleanup
trap - EXIT

Developed with carefully directed, manually reviewed AI assistance. Allow edits by maintainers is enabled, so maintainers are welcome to fix wording or make minor cleanup directly; broader review feedback will be incorporated.

Co-Authored-By: GPT-5.6 Sol codex@openai.com

Co-Authored-By: GPT-5.6 Sol <codex@openai.com>
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