<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Failure Map</title>
    <description>The latest articles on DEV Community by Failure Map (@failuremap).</description>
    <link>https://dev.to/failuremap</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4155832%2Ffbd45905-8523-45e7-8704-5d072f8f95fc.png</url>
      <title>DEV Community: Failure Map</title>
      <link>https://dev.to/failuremap</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/failuremap"/>
    <language>en</language>
    <item>
      <title>Three convincing Python fixes that still fail the boundary case</title>
      <dc:creator>Failure Map</dc:creator>
      <pubDate>Thu, 01 Oct 2026 21:20:59 +0000</pubDate>
      <link>https://dev.to/failuremap/three-convincing-python-fixes-that-still-fail-the-boundary-case-5gk7</link>
      <guid>https://dev.to/failuremap/three-convincing-python-fixes-that-still-fail-the-boundary-case-5gk7</guid>
      <description>&lt;p&gt;A fix can remove the first failure and still violate the contract. Here are three small examples where the attempted repair looks reasonable until you run the boundary checks.&lt;/p&gt;

&lt;p&gt;These examples come from Failure Map, a project I created. They are controlled Python models with explicit contracts, not reports of production incidents. The programs below use only the standard library.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Deduplicating values instead of events
&lt;/h2&gt;

&lt;p&gt;The contract is to count each event identity once, while preserving distinct events with equal amounts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;events&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The original implementation adds every delivery and returns 3. The attempted repair deduplicates amounts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It returns 1, although the two distinct event identities should contribute 2. A set is useful only if its equality relation matches the contract. Two events having the same amount does not make them the same event.&lt;/p&gt;

&lt;p&gt;The attempted repair passes the empty-stream check but fails both the replayed-delivery and distinct-equal-amount checks: &lt;strong&gt;1 of 3 passed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://failuremap.org/cases/FA-001" rel="noopener noreferrer"&gt;Inspect FA-001 and download its source&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Moving an expiration boundary by a whole tick
&lt;/h2&gt;

&lt;p&gt;The contract says an entry is valid before its expiration instant and invalid at that instant. An inclusive comparison keeps it alive too long. This attempted repair overcorrects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At &lt;code&gt;now=1&lt;/code&gt; and &lt;code&gt;expires=1&lt;/code&gt;, it correctly returns &lt;code&gt;None&lt;/code&gt;. But at &lt;code&gt;now=0.5&lt;/code&gt;, the entry has not expired; subtracting a whole unit rejects it anyway.&lt;/p&gt;

&lt;p&gt;This is a useful test-design pattern: check the exact boundary, a nearby valid value, and a value beyond it. A patch that happens to work on integer timestamps may be wrong under a contract that admits fractional values.&lt;/p&gt;

&lt;p&gt;The attempted repair passes &lt;strong&gt;2 of 3 checks&lt;/strong&gt;. Fixing the reported expiration instant did not preserve the valid interval.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://failuremap.org/cases/FA-006" rel="noopener noreferrer"&gt;Inspect FA-006 and download its source&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Making pagination inclusive to recover ties
&lt;/h2&gt;

&lt;p&gt;Suppose a page is ordered by a primary key and a unique identifier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="n"&gt;cursor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filtering only on &lt;code&gt;r[0] &amp;gt; cursor[0]&lt;/code&gt; skips &lt;code&gt;[1, 2]&lt;/code&gt;. Changing that operator seems like a quick way to recover tied records:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the cursor row itself returns again. At the last record, the query also returns a record where the next page should be empty. The comparison must respect the complete ordering contract, including the unique tie-breaker.&lt;/p&gt;

&lt;p&gt;The attempted repair passes only the before-first-record check: &lt;strong&gt;1 of 3 passed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://failuremap.org/cases/FA-011" rel="noopener noreferrer"&gt;Inspect FA-011 and download its source&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the failures
&lt;/h2&gt;

&lt;p&gt;Download an open case bundle, extract it, and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 broken.py
python3 attempt.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both programs intentionally exit with status 1 when a recorded check fails. Their JSON output includes inputs where available, actual and expected observations, and pass/fail results. The three attempted repairs above were executed for this article and produced the pass counts reported here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using these tasks for coding-model experiments
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://failuremap.org" rel="noopener noreferrer"&gt;Failure Map&lt;/a&gt; publishes &lt;strong&gt;20,168 open debugging tasks across 254 categories&lt;/strong&gt;. The &lt;a href="https://failuremap.org/api/exports/tasks.jsonl.gz" rel="noopener noreferrer"&gt;compressed JSONL task export&lt;/a&gt; contains prompts, broken implementations, hard-negative repair attempts, and embedded checks. Open sources and observations are CC0.&lt;/p&gt;

&lt;p&gt;That structure is useful for repair-prompt experiments and reinforcement-learning workflows with execution feedback. It is not a collection of open reference solutions: those are omitted from the open export. No coding-model performance improvement is claimed here.&lt;/p&gt;

&lt;p&gt;When designing an evaluation, keep case families and every shared &lt;code&gt;evaluation_group&lt;/code&gt; together. Related faults can share a solution; a random row split can make the result look more independent than it is. Keep grading fixtures outside generated code's control, and execute candidates in an isolated environment.&lt;/p&gt;

&lt;p&gt;The common lesson in these three cases is to preserve the contract while fixing the failure. Testing the nearby valid case is often what exposes the second bug.&lt;/p&gt;

</description>
      <category>coding</category>
      <category>debugging</category>
      <category>python</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
