Skip to content

fix: refresh workspace context after mutating tools - #19

Open
Dcastroro wants to merge 1 commit into
rasbt:mainfrom
Dcastroro:fix/refresh-workspace-context-15
Open

Dcastroro wants to merge 1 commit into
rasbt:mainfrom
Dcastroro:fix/refresh-workspace-context-15

Conversation

@Dcastroro

Copy link
Copy Markdown

After write_file, patch_file, or run_shell, the next model turn currently receives the original workspace snapshot. This can leave git status, branch, recent commits, and project documentation stale.

Keep the rules/tools/examples prefix stable and render workspace context separately. Mark that context dirty only after a mutating tool actually executes, and rebuild it once before the next prompt. Invalidation also happens if execution raises after a partial mutation. Argument validation, approval checks, and path restrictions are unchanged.

Fixes #15.

Validation:

  • New regression cases on base 717cae4: 5 failed, 3 passed.
  • Full suite on Windows (Python 3.10 and 3.13) and Linux (Python 3.12): 26 passed, 1 skipped in each environment; fake model responses and temporary local repositories only.
  • Untouched base suite on Windows: 18 passed, 1 skipped.
  • ruff check . with Ruff 0.17.1 reports 13 existing diagnostics on both base and this branch, with identical rule/message counts and no new diagnostics. The full lint check therefore remains failing; no rules or workflow checks are suppressed. These unrelated baseline diagnostics are outside this fix.
  • git diff --check: passed.

The tests cover all three mutating tools, branch/commit changes, partial failure, stable prompt prefix, and no refresh after reads, denied writes, or invalid arguments. No runtime dependencies, credentials, or workflow changes are introduced.

AI assistance: repository research, implementation, and validation were performed with AI assistance. The regression results and the pre-existing lint limitation are provided for maintainer review.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 12:05

Copilot AI 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.

🟢 Approval recommended

The change is minimal and correctly scoped—dirty-marking only runs for executed mutating tools while preserving prompt ordering and the stable prefix—and it is comprehensively covered by the new regression tests.

No open issues 🎉

What changed in this PR

This PR fixes stale workspace context (git status, branch, recent commits, project docs) being presented to the model after a tool mutates the workspace within a session. Previously, WorkspaceContext.text() was embedded in the once-built prompt prefix, so it never reflected changes made by write_file, patch_file, or run_shell. The fix keeps the rules/tools/examples prefix stable and renders the workspace context as a separate, refreshable section, rebuilding it only when a mutating tool has actually executed (tracked via a workspace_dirty flag set in a finally block, so partial mutations before a failure are still captured). This addresses issue #15 and preserves the existing prompt ordering and prefix-cache behavior.

Changes:

  • Added a workspace_dirty flag that run_tool sets after executing write_file, patch_file, or run_shell (including on partial-failure), and prompt() rebuilds WorkspaceContext and clears the flag before composing the next prompt.
  • Removed workspace.text() from build_prefix and moved it into prompt() as a distinct section, keeping the overall section order unchanged.
  • Added regression tests covering refresh after each mutating tool, git branch/commit changes, partial failure, the stable prefix, and no-refresh after reads, denied writes, or invalid arguments.
File Description
mini_coding_agent.py Introduces workspace_dirty, removes workspace text from the stable prefix, refreshes WorkspaceContext in prompt(), and marks dirty in run_tool's finally for mutating tools.
tests/​test_mini_coding_agent.py Adds a git fixture and parametrized regression tests validating workspace refresh behavior and stable-prefix invariants.

Review effort: Balanced

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.

fix(context): refresh workspace state after tool-driven file changes

2 participants