Claim the DevFlow mutation lease before agent mutations - #260
Open
aritchie wants to merge 1 commit into
Open
Conversation
DevFlow agents from 0.1.0-preview.12 enforce a mutation lease by default (AgentOptions.RequireMutationLease): every v1 PUT/POST/DELETE is rejected with 409 Conflict (reason "lease") unless the caller has claimed it. Sherpa never claimed one, so every property edit in the Inspector failed and the unhandled HttpRequestException crashed the Blazor UI. - Add DevFlowMutationLease/DevFlowMutationLeaseHandler, which claim the lease via POST /api/v1/agent/lease and tag requests with the X-DevFlow-Lease headers; agents without the endpoint (404) are left alone. - Route every DevFlowV1Client mutation through the lease, and use the handler in DevFlowAgentClient (profiling, DevFlow page). - Surface the agent's error message from SetPropertyAsync and show it in the Properties pane instead of an unhandled exception. Fixes #251 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMQybcsC24APNz8Vfhbbhw
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The lease changes span multiple mutation clients and lack live end-to-end verification.
Pull request overview
Adds DevFlow mutation-lease support for current agents and surfaces mutation errors in the Inspector.
Changes:
- Claims leases before v1 mutations with legacy-agent fallback.
- Integrates lease handling into DevFlow clients.
- Adds property error handling and lease tests.
File summaries
| File | Summary |
|---|---|
tests/MauiSherpa.Core.Tests/Services/Inspector/DevFlowMutationLeaseTests.cs |
Tests lease claims and error propagation. |
src/MauiSherpa.Core/Services/Inspector/DevFlowV1Client.cs |
Claims leases before v1 mutations. |
src/MauiSherpa.Core/Services/Inspector/DevFlowMutationLease.cs |
Implements lease negotiation and HTTP handling. |
src/MauiSherpa.Core/Services/DevFlowAgentClient.cs |
Adds lease handling to the client. |
src/MauiSherpa.AppInspector/Pages/Inspector/DevFlowTreeTab.razor |
Displays property mutation errors. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes #251
Root cause
The issue suspected stale capture epochs, but the agent only validates epochs when the request carries one, and Sherpa never sends one. The actual 409 comes from the mutation lease that DevFlow agents enforce by default starting with
0.1.0-preview.12.26421.1(AgentOptions.RequireMutationLease = true, confirmed in the shippedMicrosoft.Maui.DevFlow.Agent.Abstractions.dll). Any v1 PUT/POST/DELETE without a claimed lease gets:Sherpa never claimed a lease, so every property edit failed, even on an untouched app, and refreshing the tree couldn't help.
SetPropertyAsyncalso calledEnsureSuccessStatusCode(), which dropped the error body, and the Razor handlers didn't catch the exception, so it surfaced as an unhandled Blazor error.Changes
DevFlowMutationLease/DevFlowMutationLeaseHandler(new): claims the lease withPOST /api/v1/agent/lease(action: "claim", holderinspector, labelMAUI Sherpa) before v1 mutations, and adds the sameX-DevFlow-Lease/Holder/Labelheaders as the officialAgentClient. Re-claiming renews the lease. The claim never forces a takeover. If the agent returns 404 (it predates leases), Sherpa stops claiming.DevFlowV1Client: every mutation (property set, UI actions, WebView input, storage, sensors, profiler, network clear) now claims the lease first.SetPropertyAsyncthrows aDevFlowAgentExceptionthat carries the agent's error message.DevFlowAgentClient: its HttpClient uses the lease handler, so profiling and the DevFlow page work against current agents too.DevFlowTreeTab.razor: all property editors go throughSetPropertyAndRefreshAsync. It catches failures and shows a dismissible error in the Properties pane.Testing
DevFlowMutationLeaseTests: the claim is sent before the mutation and the lease header matches; agents without leases keep working and aren't re-claimed; agent 409 messages reach the caller; the handler claims only for v1 mutations.MauiSherpa.Core.Tests: 596/596 pass. TheMauiSherpa.AppInspectorproject builds with 0 errors.Follow-up
If another DevFlow session (VS Code, Copilot) holds the lease, edits now show the agent's "Take control…" message instead of crashing. Sherpa doesn't offer a forced takeover (
force: true) yet.🤖 Generated with Claude Code
https://claude.ai/code/session_01LMQybcsC24APNz8Vfhbbhw