Rectify: Dispatch Envelope Shape Discrimination Immunity#4118
Merged
Trecek merged 3 commits intoJun 26, 2026
Merged
Conversation
…igations The _fmt_dispatch_food_truck formatter conflated two structurally distinct success=False response shapes (DispatchCompleted(success=False) and DispatchRejected) under a single early-return branch, stripping critical fields (dispatched_session_id, dispatch_status, reason, token_usage, elapsed_seconds) from failed dispatches that actually ran. Changes: - Add 'kind' discriminator to DispatchCompleted.to_envelope() and DispatchRejected.to_envelope() in fleet/state_types.py - Add 'kind' to DispatchEnvelopeResult TypedDict in server/tools/_types.py - Replace formatter's success-based discrimination with kind-based discrimination, with a fallback for fleet_error() envelopes - Add per-shape required-field frozensets (_FMT_DISPATCH_COMPLETED_REQUIRED, _FMT_DISPATCH_REJECTED_REQUIRED) - Add 'kind' to _FMT_DISPATCH_FOOD_TRUCK_SUPPRESSED frozenset - Update _dispatch_food_truck_json_producer to exercise DispatchCompleted(success=False) - Add six new tests covering shape discrimination, envelope contract, structural exclusion guard, per-shape obligations, json producer coverage, and fleet_error() fallback path Issue #4111
Replace fragile if/elif chains in test_shape_field_obligations_per_kind that silently skip unrecognized fields with data-driven maps that fail explicitly when a new field is added to the required frozenset. Also removes the redundant `key = field` intermediate variable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The merged-dict assertion let kind pass even if the completed_failure shape specifically dropped it. Now parse completed_failure.to_envelope() independently and verify kind is present in that single envelope. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
The
_fmt_dispatch_food_truckformatter conflates two structurally distinctsuccess=Falseresponse shapes —DispatchRejected(subprocess never started) andDispatchCompleted(success=False)(subprocess ran and failed) — under a single early-return branch. This strips critical fields (dispatched_session_id,dispatch_status,reason,token_usage,elapsed_seconds) from failed dispatches that actually ran, causing the orchestrator to believe no session ever existed. The architectural solution introduces a typedkinddiscriminator field at the envelope layer, adds the field to the existingDispatchEnvelopeResultTypedDict, and adds per-shape formatter contract tests that structurally prevent any formatter from silently dropping fields for a given envelope shape.Implementation Plan
Plan file:
/home/talon/projects/autoskillit-runs/remediation-20260626-152751-009727/.autoskillit/temp/rectify/rectify_dispatch_envelope_shape_discrimination_2026-06-26_153500.md🤖 Generated with Claude Code via AutoSkillit
Closes #4111
Token Usage Summary
* Step used a non-Anthropic provider; caching behavior may differ.
Token Efficiency
Model Usage Breakdown