StateWise: Diagnosing and repairing persistent operation state before agent actionsStateWise: Diagnosing and Repairing Persistent Operational State Before Agent Actions
StateWise repairs invalid persistent state before actions; across 150 cases of corrupted memory, OC 93.3%, baseline 38.7%, no unsafe actions observed.
The paper states that this type of failure does not require an attacker. Coding agents reuse persistent operational records across tasks that may be outdated, conflicting, or mismatched in scope. Decision-critical means that, with other planning inputs fixed, changing or removing the record changes the proposed action. Failure means a defective record changes the action and leads to an incorrect or unsafe result. Recovery validates premises before external side effects, writes back by scope, and replans.
- Coding agents reuse persistent operational records across tasks. Changes in environment or requirements can invalidate records, and action review, provenance tracing, and clarification may not correct the underlying persistent state. The authors audited coding agent trajectories and believe that continued reuse of invalid records connects to task failures and unsafe modifications.
- Before side effects occur, StateWise uses record-level counterfactual replanning to identify decision-critical records, then determines validity through reliability checks, read-only verification, or targeted clarification. Confirmed corrections are written back by type and scope with lineage preserved; the agent replans from the repaired state and executes only after independent checks pass, otherwise it stops safely.
- Under 150 cases with corrupted target memory, StateWise has OC 93.3% and AC 92.8%, the baseline has OC 38.7% and UAR 42.7%, and the authors state no unsafe actions were observed. On 32 four-task sequences, AFS is 90.6%; on 106 unseen configurations, OC is 93.4% and UAR is zero.
- The authors state that the audit relies on model annotations and mainly covers one agent family; the executable evaluation is limited to controlled single-record defects, simulated developer responses, a limited cross-model set, and four-task sequences. The paper does not report numerical values for attribution F1 and call, token, and interaction costs.
- Evaluated models
- GPT-5.6-solDeepSeek v4 ProQwen 3.7 MaxClaude Fable 5
- Benchmarks
- SWE-chat150 executable coding-agent cases150-case set with erroneous target values150-case set with correct values and defective supporting context20-case cross-model set32 four-task sequences
- Metrics
- OCACCSUARRRAFS
The paper proposes the StateWise framework, which diagnoses and repairs persistent operational state before an agent executes an action. The framework uses record-level counterfactual replanning to identify decision-critical records, then confirms their current validity through reliability checks, read-only verification of machine-observable facts, and targeted clarification of developer intent, and supports persistent corrections with a repair lineage bound to typed evidence. Across 150 executable coding agent cases, when persistent state was corrupted, StateWise achieved an overall correctness rate of 93.3%, compared to 38.7% for the baseline agent, with no unsafe actions.
Paper analysis
What problem does this paper attempt to solve?
Coding agents may reuse persistent operational records that have become stale; StateWise diagnoses and repairs them by scope before acting.
Coding agents treat possibly stale persistent operation records as premises for subsequent actions; existing mechanisms often do not correct the record itself.
- Scenario: Coding agents carry environment facts, repository policies, developer intent, task progress, and historical observations across tasks. The authors state that correctness and operational safety depend on whether these premises remain valid in the current context.
- Existing limitations: Action-level guardrails may not correct persistent state errors; source trustworthiness or one-session correction does not guarantee the record is still valid or written back. When multiple records jointly support an action, reviewing only the operation cannot separate each record's influence and scope. The authors state these failures do not require an attacker.
- Observation: From 100 SWE-chat sessions, the authors had the model annotate 60 candidate chains, and after checking turns and timestamps, retained 40. The authors state that after conflicting evidence appears, historical operational information still guides actions.
- Method: The authors propose StateWise: before execution, locate decision-critical records, verify their validity, write back by scope, then replan, with an independent state–action check deciding execution or safe stop.
- Threat model:
- Goal: Verify premises before execution, save confirmed corrections in the applicable scope, and replan. Tasks that should execute must complete the specified changes; tasks that should stop must safely refuse.
- Defect types: Records can be incorrect, stale, conflicting with new evidence, or applicable only to another scope. r★ is the authoritative valid reference in the current environment and scope.
- Victim system: Coding agents that use tools and carry persistent operation records. Inputs are proposed actions with external side effects, retrieved context, and persistent storage.
- Failure condition: persistent-state-induced action failure: the record is defective, and relative to the valid reference it changes the proposal and leads to incorrect or unsafe results. Decision-critical means that when other planning inputs are fixed, changing or removing the record changes the proposal.
What related research exists?
Related work covers memory validity, decision provenance, and action supervision; the authors place recovery at the intersection of the three.
Related work is organized into three groups: memory continuity, decision impact tracing, and action supervision.
Memory and fact updating
- Memory systems: A-Mem (Xu et al., 2025) builds links among structured memories and updates representations with new information; Mem0 (Chhikara et al., 2025) extracts and integrates conversational information for persistent retrieval. Memory benchmarks examine cross-session recall, reasoning, and adaptation to updated information.
- Recency: Temporal question answering studies facts whose validity changes; agent memory work examines stale records, superseded evidence, and temporal validity in retrieval; knowledge editing studies fact updates and their effects on related and unrelated knowledge.
- The paper only adds: for operational records, one must also check whether a correction still applies to the current task and scope.
Impact tracing
- Untrusted input: Prompt injection work examines how untrusted external content changes agent behavior; the paper names indirect prompt injection, AgentDojo (Debenedetti et al., 2024), and InjecAgent (Zhan et al., 2024).
- Attribution: MemLineage (Ouyang and Hou, 2026) performs memory lineage, along with source analysis, information-flow tracing, and attribution to earlier context.
- The paper notes: these methods help locate sources, especially when information may be untrusted; real records can still become stale due to environmental changes, and diagnosis must also connect to current values and applicability to current actions.
Supervision and execution boundaries
- Intervention and clarification: Human supervision and mixed-initiative interfaces provide intervention pathways. The paper paraphrases that repeated confirmations may encourage routine approval, and poorly explained warnings may be ignored. Clarification methods seek missing information or user intent; the paper names Ask-or-Assume (Edwards and Schuster, 2026) among others.
- Action protection: Safety Sentry (Chen et al., 2026) routes between executing, asking, or refusing. Execution control constrains resource access; risk frameworks evaluate actions in simulation or executable environments. The paper notes that cross-task recovery must also write corrections into persistent records within the applicable scope.
Baselines and data
- Baseline methods: Bare Approval, Rationale Approval, Clarification; MemLineage, Safety Sentry, Ask-or-Assume; CRITIC (Gou et al., 2024), which uses external tool feedback to evaluate and correct outputs; Live Refresh, which prompts checking the current workspace and refreshing, with the agent choosing timing and targets.
- Benchmarks: The audit uses SWE-chat. The main evaluation has 150 executable coding cases; there are also two sets of 150 cases each, a 20-case cross-model set, and 32 four-task sequences. Case sources in Figure 4 include MemLineage, STALE, Ask-or-Assume, ClarEval, OpenAgentSafety, AgentDojo, Dialogue-SWEBench, OSGuard, MCP-SafetyBench. The text states the cases consist of self-designed tasks together with cases from these directions.
The authors' positioning is: when an erroneous persistent record affects actions, recovery must locate that record, establish its current validity, and retain the correction within the appropriate scope.
How does the paper address this problem?
StateWise uses counterfactual replanning to locate decision-critical records, then validates validity and persistently repairs by scope.
StateWise is placed after the base planner produces a proposal with external side effects and before execution. It binds decision impact, current validity, and persistent repair to the same record.
Setting and Failure Definition
- A persistent record is r = (k, v, τ, σ, π), namely typed key, semantic value, time and freshness, scope, source and authority. Storage itself does not indicate content correctness or current validity.
- The retrieval context is S, the proposed action is the planner's output on the task and this context, normalized to tool, operation, target, parameter, and scope. Stop decisions are also explicitly represented.
- A record is decision-critical if, with other planning inputs fixed, intervening on only that record changes the proposal: P(Ti, Ir(Si,t)) ≠ ai,t. This formula compares only the effect of this one record.
- An action failure induced by persistent state is D(r̂,Ti)=1 ∧ â ≠ a⋆ ∧ J(o(â); gi, Hi)=0. D being 1 means the semantic value conflicts with the authoritative validity reference, or the scope and authority do not apply to the current task; J being 1 means the task goal and all hard safety invariants hold simultaneously.
- Acceptable recovery requires that updates come from an authority commensurate with the facts, such as current environment observations or developer statements of intent; the revised action satisfies hard constraints and permissions; active records outside the repair scope remain unchanged; the revised result makes J equal to 1. A task whose goal includes a specified change should be executed; a task whose goal is to stop should be safely refused. Until the premises it depends on are resolved, the corresponding side effects are not allowed.
Attribution
- Candidates come from retrieved records linked to parameters, goals, policies, environment, or scope; those with conflicting values are retained together. The construction draws on agent attribution and memory lineage methods.
- An intervention removes or changes only this one record; probes change only the planning context, not persistent storage. Figure 3 marks three probe types: removal, uncertain (masked or unknown), and substitution (plausible value). Operations, goals, parameters, scope, and risk categories are compared.
- Those with positive counterfactual dependence and compatible type and scope bindings enter Ddep. On proposals with consequences, those with strong source links but still uncertain dependence enter Uattr. The output is the union of the two, with binding and dependence evidence attached. The paper does not give the number of probes.
Resolution
- First check type, scope, source authority, freshness, and evidence of updates or conflicts. When evidence is sufficient, classification can be direct; only unresolved premises enter additional verification.
- For machine-observable facts, registered read-only validators are invoked to observe the current repository or environment, and the evidence is bound to the record's type and scope. For developer intent or preferences that observation cannot establish, targeted clarification naming the disputed fact and its scope is raised.
- The state is valid, defective, or unresolved. Valid records keep their semantic value; defective ones enter repair with correction evidence; unresolved ones block execution.
Repair and Action Control
- Typed evidence grounding binds confirmed corrections to the attributed record, semantic type, and the scope established by the evidence, replacing the defective active value within that scope, and retaining the original record and correction evidence as lineage. Active records outside the scope remain unchanged. If there is no defect, no semantic update is made.
- After premises are resolved, the planner retrieves from the updated storage and replans. Corrections can change the operation, goal, parameter, or stop decision. Under the reset boundary in Section 3, after subsequent tasks clear the conversation and workspace, the correction can still be retrieved through persistent storage.
- An independent check compares the revised proposal's parameters, scope, and resolved state, and checks hard invariants and permissions. Execution requires the unresolved set to be empty and the checks to pass; approvals required by permission policy must be obtained before execution. Otherwise, an explicit safe stop is returned.
- A declarative interface provides tool operations, typed state and action slots, scope semantics, and validator adapters. The authors state that this interface lets the same recovery core adapt to supported repositories and tools. Authoritative reference values and result-scoring oracles sit outside the planner and resolver.
What experiments did the paper conduct?
On the 150-case main evaluation with corrupted memory, StateWise has OC 93.3% versus the baseline's 38.7%, with no unsafe actions observed.
Experimental setup
- Planners: The main planner is GPT-5.6-sol. Cross-model additionally tests DeepSeek v4 Pro, Qwen 3.7 Max, Claude Fable 5; Figure 7 abbreviates them as DeepSeek v4, Qwen 3.7, Claude Fable 5.
- Case scale: The pipeline was developed on 40 cases, then evaluated on 150 main cases after finalization, of which 125 require action and 25 require safe stopping. Two additional sets of 150 cases each contain 105 action tasks and 45 safety-stop tasks: one uses incorrect target values, the other retains correct values but has defective supporting context. Cross-model uses a separate 20 cases. Cross-task uses 32 four-task sequences.
- Controls: Correct, corrupted, removed target memory; Bare Approval, Rationale Approval, Clarification; MemLineage, Safety Sentry, Ask-or-Assume, CRITIC, Live Refresh. Within the same comparison, cases, task conditions, and evaluation rules are fixed.
- Metrics and judgment: OC is the proportion of all episodes that are correct and safe; AC is the proportion of should-execute tasks completed correctly and safely; CS is the proportion of should-stop tasks stopped correctly and safely; UAR is the proportion of episodes with at least one safety violation. RR is the proportion of subsequent contexts that retrieve the repaired record; AFS is the proportion of sequences where all subsequent tasks are correct and safe. Correctness and safety are judged by predefined outcome checks and safety constraints. The paper does not specify the LLM judge model or thresholds, nor does it report the number of repetitions.
- Values not given: Record-level AP, AR, AF1 defined in Table 1, as well as model calls, tokens, and user interaction costs, are not given specific numbers in the text. The Discussion states developer responses are simulated. Figure 4 mentions annotation agreement, but the text does not give the agreement rate.
Main results
Target memory conditions on the 150-case main evaluation. RQ1 does not name the model again; the setup section's main planner is GPT-5.6-sol. Numbers come from RQ1's textual description of Figure 5.
Swipe horizontally to read the table
Condition OC AC UAR Correct target memory 80.7% 76.8% 0.0% Corrupted target memory 38.7% 27.2% 42.7% Removed target memory 45.3% 35.2% 9.3% StateWise, incorrect memory 93.3% 92.8% no unsafe actions observed - The authors state that changing only one target memory with all other conditions fixed, an incorrect record harms task performance and induces unsafe actions, consistent with the failure chains in Section 3.
- After removing that memory, the authors state completion rates remain closer to the corrupted condition than to correct memory; avoiding misleading information does not recover the historical information needed to complete the task.
- The authors state StateWise recovers from the incorrect memory, and no unsafe actions were observed. The UAR percentage for this condition is not written in the paper.
Interventions that do not repair persistent state
- Figure 6 compares interventions under corrupted target memory. Bare Approval has OC 36.0%, AC 23.2%; Rationale Approval has OC 40.7%, AC 29.6%. No unsafe actions were observed for either. The authors state they protect the workspace by not executing, but the task-completion gap remains large.
- CRITIC has OC 48.0%, UAR 28.0%. Safety Sentry has UAR 4.7%, AC 3.9%; the text does not give OC for that condition. In the same shared comparison, StateWise has OC 88.7%, AC 84.8%, UAR 0.0%. The authors state its OC and AC are highest in that comparison. The paper does not state whether Figure 6 uses the same set as the 150-case main evaluation.
- Live Refresh performed a refresh in 105 of 150 episodes, with OC 42.0% and UAR 15.3%. The authors state refresh remains selective, and obtaining current information still requires locating and revising the relevant premises. OC and UAR for Ask-or-Assume, MemLineage, and Clarification are not given in the text.
Other states, cross-model, and interface migration
- When the target value is correct but freshness, source, or supporting context is defective, OC is 88.0%, AC is 82.9%, and no unsafe actions were observed (RQ3). The setup section also has a 150-case set retaining correct values with defective supporting context; the RQ3 sentence does not specify which set the 88.0% comes from.
- Across four planners on a separate 20 cases, OC ranges 80.0%–94.4%, AC 69.2%–90.9%, with no unsafe actions observed (Figure 7). The paper does not give individual scores per model.
- After finalization on 40 cases, the evaluation includes 8 repositories, 2 tool operations, 6 semantic state types, and 54 state–action combinations not seen in development. Of the 150 cases, 106 contain unseen configurations. On these 106 cases, OC is 93.4%, AC 92.6%, UAR 0; on seen configurations, OC is 93.2%. New state-type cases have OC 95.1%, and new repository cases have OC 98.4% (RQ6, Figure 9). The authors state the same core can be reused through the given interface contract.
Cross-task reuse
- In 32 four-task sequences, T1 can trigger repair, and T2–T4 test reuse. Conversation and workspace are cleared between tasks, retaining only persistent storage (Table 2).
- Starting from incorrect memory, StateWise has T1 90.6%, T2–T4 92.7%, AFS 90.6%, RR 97.9%. The correct-memory reference has T2–T4 91.7%, AFS 87.5%. The authors state it reaches the level of that reference and that repaired records remain retrievable after transient context is cleared.
- Corrupted memory has T2–T4 1.0%, AFS 0.0%. The authors state the tested baselines have subsequent-task completion rates of 1.0%–6.2%, AFS no higher than 3.1%, and do not explicitly leave verified corrections for subsequent reuse.
Other ablations and analyses
- Removing components one at a time on the same 150 main cases (Figure 8): removing Resolution or Persistent Repair drops OC by 78.7 and 76.7 percentage points respectively, with AC falling to 0.
- Removing Attribution drops OC by 53.3 percentage points; this variant also disables downstream state intervention, and the authors state the loss is the combined contribution of that path.
- Removing Typed Grounding drops OC by 27.3 percentage points. The authors report the above four losses remain significant after Holm correction across six comparisons.
- Removing Replanning or Residual Gate drops OC by 2.7 percentage points each. The authors state the main benefit comes from correcting the state on which planning is based.
- Among the 40 retained chains in Figure 2, causes can overlap: Stale 17 (43.3%), Conflict 30 (75.0%), Scope Mismatch 25 (63.3%), Unverified History 25 (63.3%). Consequences are task failure 17 (43.3%), user correction 15 (38.3%), unsafe modification 6 (15.0%).
What are some points that can be further explored?
The authors state that the audit relies on model annotations, the evaluation includes controlled single-record defects, and they suggest deployment studies to examine interacting records.
Limitations and future directions noted by the authors
- The audit relies on model annotation and mainly covers one agent family (Discussion).
- The executable evaluation uses controlled single-record defects, simulated developer responses, what the authors call a limited cross-model set, and four-task sequences (Discussion).
- The authors state that longer deployment studies with independent human annotation should examine interacting records, conflicting corrections, and partial evidence (Discussion).
- Extension to external services and collaborative agents also requires broader verifier coverage and mechanisms for handling shifting authority and overlapping scopes (Discussion).
- Applicability depends on explicit record–action bindings, obtainable authoritative evidence, and repair scopes established for persistent updates (Discussion). The authors state these requirements suit inspectable runtime and workspace state, verifiable repository policies, and developer choices resolvable with targeted clarification.
Experimental coverage
- The audit covers 100 sessions of SWE-chat; model annotation of 60 candidate chains, with 40 retained after verification. Sources are Claude Code 28 and OpenCode 12 (Figure 2).
- Main evaluation of 150 cases, of which 125 should execute and 25 should stop; the pipeline was developed on 40 cases. The main planner is GPT-5.6-sol. Two additional sets of 150 cases each contain 105 action tasks and 45 safety-stop tasks.
- Cross-model uses four planners and a separate 20 cases. Cross-task is 32 four-task sequences; conversation and workspace are reset between tasks, retaining only persistent storage.
- Interface migration statistics on configurations unseen after finalization: 106 of 150 cases, plus 8 repositories, 2 tool operations, 6 semantic state types, 54 state–action combinations (RQ6).
- The text defines AP, AR, AF1 and model calls, tokens, interaction costs, but does not report these values; it also does not report the number of repetitions, or the specific values of Exact Agreement and Cohen's κ in Figure 4.
Summarize the main content of the paper
StateWise repairs stale persistent premises before action; under 150 cases of corrupted memory, OC is 93.3%, and the baseline is 38.7%.
StateWise is a framework that diagnoses and repairs the persistent operational state of coding agents before executing actions with side effects.
- Problem: Operational records reused across tasks can become stale, conflicting, or scope-mismatched; blocking the current action, tracing provenance, or clarifying does not necessarily correct the underlying persistent premise. The authors retained 40 candidate failure chains from 100 sessions of SWE-chat.
- Approach: Use constrained counterfactual replanning to identify decision-critical records, then perform checks, read-only validation, or targeted clarification by type and authority, and write back confirmed corrections along with provenance by scope; then replan, and only execute if independent checks pass, otherwise stop safely.
- Main results: In the main evaluation with 150 cases and corrupted target memory, baseline OC is 38.7%, AC is 27.2%, UAR is 42.7%; StateWise's OC is 93.3%, AC is 92.8%, and the authors report no unsafe actions observed. When that memory is removed, OC is 45.3%.
- Continuation and transfer: On 32 four-task sequences, StateWise's AFS is 90.6%, subsequent tasks completed correctly and safely is 92.7%, RR is 97.9%. On 106 unseen configurations, OC is 93.4%, UAR is 0.
- Components and conclusion: Removing Resolution or Persistent Repair drops OC by 78.7 and 76.7 percentage points respectively, and AC drops to 0. The authors state the implementation is open-sourced. Their conclusion is that invalid records can continue to affect subsequent plans after an action is blocked, so records and their applicable scope should become evidence-supported recovery objects.