fix(workflow): invalidate subgraph cache on YAML file edit (#622)#635
Draft
eldar702 wants to merge 1 commit into
Draft
fix(workflow): invalidate subgraph cache on YAML file edit (#622)#635eldar702 wants to merge 1 commit into
eldar702 wants to merge 1 commit into
Conversation
…BMB#622) The module-level _SUBGRAPH_CACHE in workflow/subgraph_loader.py was keyed solely on the resolved file path with no staleness check, so once a subgraph YAML was parsed it was never re-read for the lifetime of the process. Editing a workflow used by a subgraph node and re-running it executed the stale version until ChatDev was restarted. Store the file's mtime alongside the cached payload and reload when the on-disk mtime changes. Unedited files are still served from cache, so there is no behavior change for the common path. Adds tests/test_subgraph_loader_cache.py with a RED-first regression test (edit-then-reload returns the new content) plus a cache-preservation test proving unchanged files are not re-parsed.
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.
Problem
Fixes #622. Editing a workflow YAML used by a subgraph node and re-running the subgraph executes the old version; only restarting ChatDev picks up the change.
workflow/subgraph_loader.pycaches parsed subgraphs in a module-level dict_SUBGRAPH_CACHEkeyed only on the resolved file path, with no staleness check:Once a subgraph is loaded, the on-disk YAML is never re-read for the process lifetime — exactly the reporter's "stale until restart" symptom.
Fix
workflow/subgraph_loader.py— store the file'sst_mtimealongside the cached payload and reload when the on-disk mtime changes:The cache is preserved for unedited files (no extra parse on the common path) — the only new behavior is invalidation when the file actually changes. No new dependencies. 12-line change in 1 source file.
Test (RED-first)
Adds
tests/test_subgraph_loader_cache.py:test_reload_after_edit_returns_new_content— write a subgraph YAML, load it (assertsv1), edit the same file (bumping mtime viaos.utimeto defeat coarse-clock filesystems), load again, assert it now reflectsv2. This test is RED onmain(returns the cachedv1) and GREEN with this fix.test_unchanged_file_is_served_from_cache— proves an unedited file is not re-parsed, so the perf-oriented cache is retained.Verified RED→GREEN locally:
Verification
uv run pytest tests/test_subgraph_loader_cache.py→ 2 passed.uv run pytest(excluding the pre-existing-on-mainhangingtests/test_websocket_send_message_sync.py) → 56 passed. That websocket test hangs identically on a pristinemaincheckout and is untouched by this PR.🤖 AI-assistance: Claude (Opus 4.8), reviewed