feat(context): config hot-reload via ContextPipeline middleware#111
Merged
yishuiliunian merged 5 commits intomainfrom Apr 15, 2026
Merged
feat(context): config hot-reload via ContextPipeline middleware#111yishuiliunian merged 5 commits intomainfrom
yishuiliunian merged 5 commits intomainfrom
Conversation
Wire the existing ContextPipeline into the agent loop so middleware runs before every LLM call. Add ConfigRefreshMiddleware that detects mid-session changes to memory, instructions, and settings files via mtime polling, computes line-level diffs, and injects system-reminder messages into the working message copy — without touching the system prompt (preserving Anthropic prefix cache). Key changes: - file_snapshot: FileSnapshot with stat-then-read ordering, ordered line diff preserving duplicates, formatted change summaries - config_refresh: Middleware checking 9 watched paths (global+project memory, instructions, settings) with Mutex for interior mutability - context_pipeline: bridge method on AgentLoopRunner (non-fatal) - pipeline_setup: builds pipeline with all watched paths - params: extracted types from mod.rs to stay under 200-line limit - turn_tool_phase: extracted tool execution phase from turn_exec.rs
Windows filesystems can have coarse mtime granularity (up to 1s on HFS+/NTFS). Tests that write a file and immediately check for changes may see the same mtime. Add 1.1s sleep between snapshot load and file modification in affected tests.
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.
Summary
ContextPipeline(previously test-only) into the agent loop as a pre-LLM middleware pipelineConfigRefreshMiddlewarethat detects mid-session file changes (memory, instructions, settings) via mtime polling and injects diffs assystem-reminderuser messagesChanges
New files (loopal-context):
middleware/file_snapshot.rs—FileSnapshotwith stat-then-read TOCTOU safety, ordered line diff preserving duplicates, formatted change summariesmiddleware/config_refresh.rs—ConfigRefreshMiddlewareimpl withMutex<Vec<FileSnapshot>>for interior mutabilitytests/suite/file_snapshot_test.rs— 15 tests (diff, format, snapshot lifecycle, unicode, sequential changes)tests/suite/config_refresh_test.rs— 5 tests (no-change, injection, dedup, cache safety, multi-file)New files (loopal-runtime):
agent_loop/context_pipeline.rs— bridge methodrun_context_pipeline()(non-fatal, errors logged and swallowed)agent_loop/pipeline_setup.rs—build_context_pipeline()watching 9 file paths (global+project memory/instructions/settings)agent_loop/params.rs— extractedAgentConfig,AgentLoopParams,AgentDeps, etc. frommod.rsagent_loop/turn_tool_phase.rs— extracted tool execution phase fromturn_exec.rsModified files:
middleware/mod.rs— export new modulesrunner.rs— addedpipeline: ContextPipelinefieldturn_exec.rs— callrun_context_pipeline()before LLM, delegate tool phasemod.rs— build pipeline inagent_loop(), re-export fromparams.rsWatched paths (9 total)
~/.loopal/memory/MEMORY.md.loopal/memory/MEMORY.md~/.loopal/LOOPAL.md~/.loopal/LOOPAL.local.mdLOOPAL.md.loopal/LOOPAL.local.md~/.loopal/settings.json.loopal/settings.json.loopal/settings.local.jsonTest plan
bazel build //... --config=clippy— zero warningsbazel test //crates/loopal-context:loopal-context_test— 20 tests pass (including new)bazel test //crates/loopal-runtime:loopal-runtime_test— all pass