Re-sync the Notebook panel after notebook.md writes that bypass the watcher#363
Open
dannon wants to merge 1 commit into
Open
Re-sync the Notebook panel after notebook.md writes that bypass the watcher#363dannon wants to merge 1 commit into
dannon wants to merge 1 commit into
Conversation
…atcher The panel only refreshed when the chokidar watcher caught a change, but the watcher tracks a single file path -- an atomic temp-and-rename save (sed -i, an editor) swaps the inode out from under it, and a plain truncate can race its awaitWriteFinish window -- so a notebook written through bash went stale until the next /notebook. The tool_execution_end hook also only re-emitted for galaxy_ tools. It now calls reemitNotebookIfChanged() after every tool, which re-reads notebook.md and emits through the existing notifyNotebookChange path only when the content actually changed. A dev/ino/size/mtime/ctime stat fingerprint skips untouched files (so it isn't churn on every tool end) and catches inode-replacing or same-size rewrites that a mtime+size check would miss; a content compare suppresses no-op emits. notifyNotebookChange now isolates per-listener exceptions so a bad subscriber can't break the hook, and switching notebook paths resets the emit baselines.
dc0b7ff to
9a1382d
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #253
The Notebook panel only refreshed when the chokidar watcher caught a change to
notebook.md, but the watcher tracks a single file path. An atomic temp-and-rename save (sed -i, an editor) swaps the inode out from under it, and a plain truncate can race itsawaitWriteFinishwindow -- so when the agent wrote the notebook through bash instead of/notebook, the panel went stale. Thetool_execution_endhook also only re-emitted forgalaxy_tools.What this does
tool_execution_endnow calls a newreemitNotebookIfChanged()(instate.ts) after every tool. It re-readsnotebook.mdand emits through the existingnotifyNotebookChangepath only when the content actually changed:dev:ino:size:mtimeMs:ctimeMsstat fingerprint skips the read when the file is untouched, so it isn't I/O churn on every tool end, andIncluding
ino/ctimein the fingerprint (not justmtime+size) is deliberate: an inode-replacing or same-size rewrite with a preserved/coarse mtime is exactly the watcher-evading write this is meant to catch.Two small hardening changes fell out of review of the new emit path:
notifyNotebookChangenow isolates per-listener exceptions (logged, not rethrown), so one misbehaving subscriber can't break thetool_execution_endhook or starve other listeners.setNotebookPathresets the emit baselines, so switching to a new notebook that happens to share the old one's content/fingerprint still re-syncs the panel instead of being suppressed.Scope
This is the contained UI re-sync fix only -- the watcher itself is unchanged (parent-dir watching / a watcher rewrite is a separate, larger change). Two deliberately out-of-scope notes:
reemitfires before the watcher's 500msawaitWriteFinishsettles, the watcher later emits the same content again. The onlyonNotebookChangelistener (the UI bridge) dedups on content, so there's no visible double-render.Tests
New
tests/notebook-reemit.test.ts(7 cases): changed -> emit once, unchanged -> no emit, no re-emit on a second call, no-op without an active notebook, an inode-replacing write with pinned size+mtime still emits (fails on a mtime+size-only guard), a throwing listener neither breaks the caller nor starves other listeners, and a path switch to a same-content notebook still re-emits. The cases run with the real watcher stopped so they're deterministic. Full root suite green (1257 passing); root and Orbit typechecks clean.