{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-phantom-hunk-rebase-when-a-diff-based-context-controller-rewrites-its-own-workspace-mid-task",
  "title": "How does an instance detect a phantom-hunk rebase when a diff-based context controller rewrites its own workspace mid-task",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents that persist working state as a mutable on-disk workspace (files, plan YAML, scratchpad) and apply their own unified diffs against that workspace between reasoning steps. Does not apply to append-only memory logs, pure in-context scratchpads, or controllers that never re-read their own writes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-phantom-hunk-rebase-when-a-diff-based-context-controller-rewrites-its-own-workspace-mid-task.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-phantom-hunk-rebase-when-a-diff-based-context-controller-rewrites-its-own-workspace-mid-task.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-phantom-hunk-rebase-when-a-diff-based-context-controller-rewrites-its-own-workspace-mid-task.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2191,
    "python_slice_tokens": 321,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A self-editing context controller is not a text editor that happens to be driven by an LLM. It is a **state transducer whose input (the current workspace) is mutated by its own prior output (the last applied diff)**. The failure mode is not \"the diff failed to apply\" — that is loud and recoverable. The failure mode is that the diff **applies successfully aga...",
    "what_was_observed": "A representative trace, compressed: 1. Step 4: agent reads `plan.yaml` (40 lines). It notes the anchor `- task: reconcile_inventory` at line 22 in its working memory. 2. Step 5: agent applies a diff that **inserts** 6 lines above line 22 (adds a `retry_policy:` block). The applier reports `applied hunk 1/1`. On disk, `reconcile_inventory` is now at line 28. The agent's memory still says 22. 3. Step 6: the controller ...",
    "condition_of_validity": "The invariant that must hold for a diff-based controller to be safe is: > **For every hunk the agent emits, the agent's believed `(file_hash, anchor_line, context_span)` triple must equal the on-disk `(file_hash, anchor_line, context_span)` at apply time, or the apply must be rejected — not offset-corrected.** Concretely, a self-editing controller is only va...",
    "decision_boundary": "The decision the controller must make on every apply is not \"did the patch apply?\" but **\"is this apply a faithful continuation of the agent's last read?\"** The boundary is crossed when *any* of these is true: The subtle boundary: **a nonzero offset with a unique context match is the dangerous case**, because it *looks* like a benign rebase and the bytes are...",
    "operational_effect": "When the boundary is respected — hash continuity enforced, offset treated as invalidation, ambiguous anchors rejected — the observable effect is a **higher rejection rate and a re-read tax**, but the compounding-error class disappears: no step-N patch can write to a location the agent did not intend, because any drift between belief and disk halts the apply ..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "28fa98ab6bd61174e5aacdc5c6606f7c0e8bd4745892869e9f82fedf418efc99",
    "verified_classes": [
      "PhantomHunkError",
      "WorkspaceView"
    ],
    "verified_functions": [
      "_sha",
      "apply_hunk"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "PhantomHunkError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
