{"@attributes":{"version":"2.0"},"channel":{"title":"DEV Community: Sina Rezaei","description":"The latest articles on DEV Community by Sina Rezaei (@sinarezaei).","link":"https:\/\/dev.to\/sinarezaei","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%2F1041388%2F7c77dbc8-0ae8-4bfd-a926-762d3fce6b6f.png","title":"DEV Community: Sina Rezaei","link":"https:\/\/dev.to\/sinarezaei"},"language":"en","item":[{"title":"The Best Communication System Might Not Need a Transmitter","pubDate":"Tue, 17 Nov 2026 04:00:00 +0000","link":"https:\/\/dev.to\/sinarezaei\/the-best-communication-system-might-not-need-a-transmitter-4cem","guid":"https:\/\/dev.to\/sinarezaei\/the-best-communication-system-might-not-need-a-transmitter-4cem","description":"<p>We usually think of communication systems as active devices.<\/p>\n\n<p>A transmitter generates a signal, a receiver picks it up, and some kind of processing happens on either side. That's how Wi-Fi, satellite links, Bluetooth, and spacecraft telemetry generally work.<\/p>\n\n<p>But there's another interesting approach: what if a device doesn't generate its own signal at all?<\/p>\n\n<p>Back in 1969, Apollo 11 left something on the Moon that demonstrates a different kind of engineering. It has no battery, no processor, no radio transmitter, and no software.<\/p>\n\n<p>Yet scientists are still using it for measurements.<\/p>\n\n<h2>\n  \n  \n  A device with no power supply\n<\/h2>\n\n<p>Apollo 11 carried a Laser Ranging Retroreflector (LRRR), a passive optical instrument placed on the lunar surface.<\/p>\n\n<p>The Apollo 11 array contains 100 fused-silica corner-cube reflectors mounted on a 46 cm aluminum panel. Each cube is designed to return incoming light toward its source.<\/p>\n\n<p>The interesting part isn't just the mirror design. It's what the system doesn't need.<\/p>\n\n<p>There is no onboard power supply, electronic controller, or active transmitter. Scientists on Earth fire short laser pulses toward the Moon, and the reflector sends a portion of that light back.<\/p>\n\n<p>The ground station measures the round-trip travel time and calculates the distance.<\/p>\n\n<p>That's a completely different engineering approach from building a device that actively communicates with another system.<\/p>\n\n<h2>\n  \n  \n  How does it actually work?\n<\/h2>\n\n<p>The key component is the corner-cube retroreflector.<\/p>\n\n<p>A conventional flat mirror reflects light according to the angle of incidence. A corner cube uses three mutually perpendicular reflecting surfaces. This arrangement sends incoming light back approximately toward its original direction.<\/p>\n\n<p>Here's the basic process:<br>\n<\/p>\n\n<pre data-lang=\"mermaid\"><code>flowchart TD\n    A[\"Earth Observatory\"] --&gt; B[\"Laser Pulse\"]\n    B --&gt; C[\"Moon: Corner-Cube Array\"]\n    C --&gt; D[\"Reflected Light\"]\n    D --&gt; E[\"Earth Telescope\"]\n    E --&gt; F[\"Time-of-Flight Measurement\"]\n    F --&gt; G[\"Earth-Moon Distance\"]<\/code><\/pre>\n\n\n\n<p>The distance calculation is straightforward:<\/p>\n\n<p>[<br>\nd = \\frac{c \\times t}{2}<br>\n]<\/p>\n\n<p>Where:<\/p>\n\n<ul>\n<li>(d) = distance to the reflector<\/li>\n<li>(c) = speed of light<\/li>\n<li>(t) = measured round-trip time<\/li>\n<\/ul>\n\n<p>For an average Earth-Moon distance of approximately 384,400 km, the round trip takes about 2.56 seconds.<\/p>\n\n<p>That sounds simple until you consider the actual engineering challenge: sending a narrow laser beam across hundreds of thousands of kilometers and detecting the extremely small amount of light that returns.<\/p>\n\n<p>This isn't ordinary optical communication. It's precision measurement.<\/p>\n<h2>\n  \n  \n  Three different ways to avoid conventional active communication\n<\/h2>\n\n<p>The interesting comparison isn't simply powered versus unpowered. These systems solve different problems.<\/p>\n\n<div class=\"table-wrapper-paragraph\"><table>\n<thead>\n<tr>\n<th>System<\/th>\n<th>How it works<\/th>\n<th>Independent power<\/th>\n<th>Main purpose<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Active RF<\/td>\n<td>Generates and transmits its own signal<\/td>\n<td>Yes, typically<\/td>\n<td>Communication<\/td>\n<\/tr>\n<tr>\n<td>Passive RFID<\/td>\n<td>Harvests reader energy and modulates reflected RF<\/td>\n<td>No internal battery<\/td>\n<td>Identification and data exchange<\/td>\n<\/tr>\n<tr>\n<td>Lunar Retroreflector<\/td>\n<td>Returns incoming laser light<\/td>\n<td>No<\/td>\n<td>Precision ranging<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n<p>Consider passive UHF RFID.<\/p>\n\n<p>A reader transmits a continuous RF signal. The tag captures some of that energy through its antenna, powers its chip, and changes its antenna impedance to modulate the reflected signal.<\/p>\n\n<p>The reader detects those changes and decodes the tag's response.<\/p>\n\n<p>This technique is called <strong>backscatter communication<\/strong>.<\/p>\n\n<p>It's particularly useful in environments where maintaining thousands of battery-powered devices would be expensive.<\/p>\n\n<p>But there's an important distinction: RFID can encode information in its response. The lunar reflector doesn't do that. It simply returns light, allowing the ground station to measure time and distance.<\/p>\n\n<p>Same broad engineering idea of using an external signal, but very different capabilities.<\/p>\n<h2>\n  \n  \n  The Mars connection: when a relay is better than a direct link\n<\/h2>\n\n<p>There's another interesting example in NASA's Mars missions.<\/p>\n\n<p>A rover doesn't always need to send all its scientific data directly to Earth.<\/p>\n\n<p>NASA's Mars Relay Network uses orbiters such as Mars Reconnaissance Orbiter and Mars Odyssey to receive data from surface vehicles and forward it toward Earth.<\/p>\n\n<p>The architecture looks like this:<br>\n<\/p>\n\n<pre data-lang=\"mermaid\"><code>flowchart LR\n    A[\"Mars Rover\"] --&gt; B[\"Mars Orbiter\"]\n    B --&gt; C[\"Deep Space Network\"]\n    C --&gt; D[\"Earth Mission Control\"]<\/code><\/pre>\n\n\n\n<p>Why use an orbiter?<\/p>\n\n<p>Because a rover has limited space, power, antenna capability, and communication opportunities. An orbiter can carry larger antennas and provide a more capable communication link.<\/p>\n\n<p>This is a different solution to the same general engineering question:<\/p>\n\n<p><strong>Does every device need to handle the entire communication process itself?<\/strong><\/p>\n\n<p>Sometimes moving complexity to another part of the system produces a better overall architecture.<\/p>\n\n<h2>\n  \n  \n  The trade-offs engineers actually need to consider\n<\/h2>\n\n<p>Passive designs aren't automatically better.<\/p>\n\n<p>Removing a battery, processor, or transmitter can reduce hardware complexity, but it also limits what the device can do.<\/p>\n\n<div class=\"table-wrapper-paragraph\"><table>\n<thead>\n<tr>\n<th>Engineering factor<\/th>\n<th>Active system<\/th>\n<th>Passive system<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Signal generation<\/td>\n<td>Independent<\/td>\n<td>Depends on external source<\/td>\n<\/tr>\n<tr>\n<td>Energy requirements<\/td>\n<td>Higher<\/td>\n<td>Lower at the device<\/td>\n<\/tr>\n<tr>\n<td>Data processing<\/td>\n<td>Can be extensive<\/td>\n<td>Often limited<\/td>\n<\/tr>\n<tr>\n<td>Operating range<\/td>\n<td>Depends on transmitter and receiver<\/td>\n<td>Strongly depends on external energy and detection<\/td>\n<\/tr>\n<tr>\n<td>Maintenance<\/td>\n<td>May require power-system maintenance<\/td>\n<td>Fewer powered components<\/td>\n<\/tr>\n<tr>\n<td>Functionality<\/td>\n<td>Flexible<\/td>\n<td>Task-specific<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n<p>The lunar reflector also has its own problems.<\/p>\n\n<p>NASA has investigated why some lunar retroreflector arrays return much weaker signals than expected. Dust accumulation, thermal effects, and degradation in optical performance are among the factors researchers have considered.<\/p>\n\n<p>So even a design with no electronics can face serious environmental challenges.<\/p>\n\n<p>Removing components doesn't remove physics.<\/p>\n\n<h2>\n  \n  \n  A useful lesson for system designers\n<\/h2>\n\n<p>I think this is where the example becomes interesting beyond space exploration.<\/p>\n\n<p>When designing an IoT device, sensor network, or distributed system, we often start by asking:<\/p>\n\n<ul>\n<li>Which processor should we use?<\/li>\n<li>How will the device transmit data?<\/li>\n<li>What battery capacity do we need?<\/li>\n<li>Which communication protocol should we implement?<\/li>\n<\/ul>\n\n<p>But there's another question worth asking first:<\/p>\n\n<p><strong>Does this device actually need to generate, process, or transmit anything independently?<\/strong><\/p>\n\n<p>A passive RFID tag doesn't need its own battery. A lunar retroreflector doesn't need an onboard communication system. A Mars rover can use an orbiter to handle much of its data transmission.<\/p>\n\n<p>These aren't interchangeable technologies, but they demonstrate an important design principle: assign responsibilities to the components that can perform them most efficiently.<\/p>\n\n<p>Sometimes the best optimization isn't a faster processor or a better transmitter. It's removing a responsibility that the device never needed to handle in the first place.<\/p>\n\n\n\n\n<p><strong>What's your take?<\/strong><\/p>\n\n<p>When designing a distributed system, do you prefer giving every device independent capabilities, or moving some responsibilities to shared infrastructure when possible?<\/p>\n\n","category":["engineering","systemdesign","iot","spacetech"]},{"title":"AI Can Write the Code. Who Takes Responsibility for the System?","pubDate":"Tue, 10 Nov 2026 04:30:00 +0000","link":"https:\/\/dev.to\/sinarezaei\/ai-can-write-the-code-who-takes-responsibility-for-the-system-30kc","guid":"https:\/\/dev.to\/sinarezaei\/ai-can-write-the-code-who-takes-responsibility-for-the-system-30kc","description":"<p>AI can generate a working piece of code in seconds. But getting that code to work is only one part of building reliable software.<\/p>\n\n<p>Imagine an AI agent builds a feature, runs the tests, and reports success. The pull request looks clean, the implementation seems reasonable, and every test passes.<\/p>\n\n<p>Then the feature reaches production.<\/p>\n\n<p>Under heavy traffic, two requests update the same record at nearly the same time. Both read the old value, both calculate a new one, and one update silently overwrites the other. The tests never caught it because they didn't reproduce the timing conditions that caused the failure.<\/p>\n\n<p>The code was generated. The tests passed. Yet the system still had a problem.<\/p>\n\n<p>This is where software engineering goes beyond writing instructions for a computer.<\/p>\n\n<p>An engineer must understand how a change interacts with existing components, databases, external services, security boundaries, and real user behavior. A solution that works in isolation can still introduce failures elsewhere.<\/p>\n\n<p>The same challenge appears in architectural decisions. Should a service retry a failed request? What happens if the original request succeeded but its response never reached the client? Could a retry create a duplicate payment or process the same job twice?<\/p>\n\n<p>Generating a retry loop is easy. Designing a safe retry mechanism requires a different level of reasoning. You may need idempotency keys, database constraints, bounded retries, and a clear strategy for handling uncertain outcomes.<\/p>\n\n<p>AI can help implement these mechanisms. It can suggest alternatives, generate tests, and identify potential weaknesses. But someone still needs to determine which guarantees the system actually requires and verify that the implementation provides them.<\/p>\n\n<p>And the challenge doesn't end when the code is merged.<\/p>\n\n<p>Requirements change. Dependencies evolve. Traffic patterns shift. Security vulnerabilities emerge. A decision that was reasonable six months ago may become a bottleneck today. Maintaining software means continuously evaluating whether the system still behaves as intended under changing conditions.<\/p>\n\n<p>This is why counting lines of code, commits, or AI-generated features tells us very little about the actual value of an engineer.<\/p>\n\n<p>The more code AI can produce, the more important it becomes to evaluate what that code does, what assumptions it makes, and what happens when those assumptions fail.<\/p>\n\n<p><strong>The real shift isn't from writing code to not writing code. It's from spending less effort producing code to spending more effort making sure the right system gets built.<\/strong><\/p>\n\n<p>The engineers who thrive in this environment won't necessarily be the ones who write the most code or use the largest number of AI tools. They'll be the ones who can turn ambiguous requirements into sound designs, recognize risks before they reach production, and make informed decisions when there is no perfect solution.<\/p>\n\n<p>AI can accelerate implementation. Engineering determines whether that implementation deserves to become part of a real system.<\/p>\n\n","category":["ai","programming","architecture","softwareengineering"]},{"title":"\ud83c\udf83 The Real Nightmare Isn't a Bug. It's a Bug Nobody Notices. \ud83c\udf83","pubDate":"Sat, 07 Nov 2026 04:51:53 +0000","link":"https:\/\/dev.to\/sinarezaei\/the-real-nightmare-isnt-a-bug-its-a-bug-nobody-notices-565n","guid":"https:\/\/dev.to\/sinarezaei\/the-real-nightmare-isnt-a-bug-its-a-bug-nobody-notices-565n","description":"<p>Imagine deploying a new feature.<\/p>\n\n<p>All tests pass. CI is green. No errors in the logs. Everything looks fine.<\/p>\n\n<p>Then a user reports that their payment was processed twice.<\/p>\n\n<p>Here's a simplified example of what can go wrong:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight javascript\"><code><span class=\"k\">async<\/span> <span class=\"kd\">function<\/span> <span class=\"nf\">processPayment<\/span><span class=\"p\">(<\/span><span class=\"nx\">order<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n  <span class=\"k\">try<\/span> <span class=\"p\">{<\/span>\n    <span class=\"k\">return<\/span> <span class=\"k\">await<\/span> <span class=\"nx\">paymentAPI<\/span><span class=\"p\">.<\/span><span class=\"nf\">charge<\/span><span class=\"p\">({<\/span>\n      <span class=\"na\">amount<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">total<\/span><span class=\"p\">,<\/span>\n      <span class=\"na\">customerId<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">customerId<\/span>\n    <span class=\"p\">});<\/span>\n  <span class=\"p\">}<\/span> <span class=\"k\">catch <\/span><span class=\"p\">(<\/span><span class=\"nx\">error<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n    <span class=\"k\">if <\/span><span class=\"p\">(<\/span><span class=\"nx\">error<\/span><span class=\"p\">.<\/span><span class=\"nx\">code<\/span> <span class=\"o\">===<\/span> <span class=\"dl\">\"<\/span><span class=\"s2\">TIMEOUT<\/span><span class=\"dl\">\"<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n      <span class=\"k\">return<\/span> <span class=\"k\">await<\/span> <span class=\"nx\">paymentAPI<\/span><span class=\"p\">.<\/span><span class=\"nf\">charge<\/span><span class=\"p\">({<\/span>\n        <span class=\"na\">amount<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">total<\/span><span class=\"p\">,<\/span>\n        <span class=\"na\">customerId<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">customerId<\/span>\n      <span class=\"p\">});<\/span>\n    <span class=\"p\">}<\/span>\n\n    <span class=\"k\">throw<\/span> <span class=\"nx\">error<\/span><span class=\"p\">;<\/span>\n  <span class=\"p\">}<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Looks reasonable, but there's a problem.<\/p>\n\n<p>The first request might have reached the payment service and completed successfully. Only the response got lost.<\/p>\n\n<p>The retry sends another charge request.<\/p>\n\n<p>Now imagine this happening with a real customer.<\/p>\n\n<p>One way to prevent this is to use an idempotency key:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight javascript\"><code><span class=\"k\">async<\/span> <span class=\"kd\">function<\/span> <span class=\"nf\">processPayment<\/span><span class=\"p\">(<\/span><span class=\"nx\">order<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n  <span class=\"k\">return<\/span> <span class=\"k\">await<\/span> <span class=\"nx\">paymentAPI<\/span><span class=\"p\">.<\/span><span class=\"nf\">charge<\/span><span class=\"p\">({<\/span>\n    <span class=\"na\">amount<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">total<\/span><span class=\"p\">,<\/span>\n    <span class=\"na\">customerId<\/span><span class=\"p\">:<\/span> <span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">customerId<\/span><span class=\"p\">,<\/span>\n    <span class=\"na\">idempotencyKey<\/span><span class=\"p\">:<\/span> <span class=\"s2\">`payment-<\/span><span class=\"p\">${<\/span><span class=\"nx\">order<\/span><span class=\"p\">.<\/span><span class=\"nx\">id<\/span><span class=\"p\">}<\/span><span class=\"s2\">`<\/span>\n  <span class=\"p\">});<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Now the payment service can recognize repeated requests for the same operation and return the original result instead of charging the customer again.<\/p>\n\n<p>Of course, this depends on the payment provider correctly supporting and implementing idempotency.<\/p>\n\n<p>That's what makes production bugs interesting. Sometimes the code works exactly as written. The problem is that nobody considered what would happen under real-world conditions.<\/p>\n\n<p>A green test suite is good news, but it doesn't mean you've tested every possible failure.<\/p>\n\n<p><strong>Sometimes the scariest bugs are the ones that never show up in your test results.<\/strong> \ud83d\udc7b<\/p>\n\n<p>Happy Halloween! \ud83c\udf83<\/p>\n\n","category":["javascript","backend","webdev","architecture"]},{"title":"A Good Prompt Doesn't Guarantee Correct Execution: The Missing Layer in AI Engineering","pubDate":"Sat, 07 Nov 2026 04:45:30 +0000","link":"https:\/\/dev.to\/sinarezaei\/a-good-prompt-doesnt-guarantee-correct-execution-the-missing-layer-in-ai-engineering-5cp1","guid":"https:\/\/dev.to\/sinarezaei\/a-good-prompt-doesnt-guarantee-correct-execution-the-missing-layer-in-ai-engineering-5cp1","description":"<p>The conversation around AI productivity has become increasingly focused on prompt engineering. Developers are encouraged to write more detailed instructions, provide better context, define constraints, and break complex requests into smaller tasks.<\/p>\n\n<p>These practices are useful. But they address only one part of the problem.<\/p>\n\n<p>There is a fundamental difference between expressing an instruction, interpreting its intent, and executing it without violating its constraints.<\/p>\n\n<p>I've encountered this distinction even in relatively simple tasks. For example, asking an image editor to remove a title while preserving the rest of the image can result in an entirely different composition. The instruction is clear, the requested modification is small, yet the output may change elements that were never supposed to be touched.<\/p>\n\n<p>This isn't necessarily a prompt-writing failure. It exposes a limitation in how the model interprets and performs the requested operation.<\/p>\n\n<p>The same problem becomes considerably more expensive when it appears in software engineering.<\/p>\n\n<h2>\n  \n  \n  The Instruction Is Not the Operation\n<\/h2>\n\n<p>Consider a simple image-editing request:<\/p>\n\n<p>\"Remove the title from this image. Keep the background, typography, lighting, composition, and all other elements unchanged.\"<\/p>\n\n<p>From a human perspective, this is a localized modification. The original image is the source of truth, and the title is the only element that needs to disappear.<\/p>\n\n<p>However, many generative image-editing systems don't operate like traditional graphics editors.<\/p>\n\n<p>Depending on the implementation, an editing request may involve inpainting, latent-space reconstruction, image-to-image generation, or a combination of these techniques.<\/p>\n\n<p>Even when a mask identifies the intended modification area, reconstruction can introduce changes around the masked region. Some implementations may also alter unmasked areas because the model is generating a plausible image rather than performing a strictly deterministic pixel operation.<\/p>\n\n<p>This distinction is important.<\/p>\n\n<p>There is a difference between:<\/p>\n\n<ul>\n<li>Generating an image that resembles the original.<\/li>\n<li>Editing a specific region of the original.<\/li>\n<li>Preserving every pixel outside the requested modification.<\/li>\n<\/ul>\n\n<p>A prompt can describe the third requirement perfectly without the underlying editing pipeline actually guaranteeing it.<\/p>\n\n<p>If exact preservation is required, the workflow may need explicit masking, controlled compositing, and restoration of the original pixels outside the edited region.<\/p>\n\n<p>In other words, better instructions cannot replace missing execution guarantees.<\/p>\n\n<h2>\n  \n  \n  Prompt Interpretation Is Not the Same as Prompt Execution\n<\/h2>\n\n<p>A model can identify the general intention of a request and still fail to satisfy its actual requirements.<\/p>\n\n<p>Consider a software engineering example.<\/p>\n\n<p>A developer asks an AI agent to refactor a payment-processing service without changing its existing behavior.<\/p>\n\n<p>The agent understands the request. It reorganizes the code, extracts methods, reduces duplication, and produces a cleaner implementation.<\/p>\n\n<p>The resulting code may even pass the existing test suite.<\/p>\n\n<p>But suppose the original implementation guarantees that repeated payment requests with the same idempotency key cannot create duplicate transactions.<\/p>\n\n<p>During refactoring, the agent moves the idempotency check outside the database transaction.<\/p>\n\n<p>Under concurrent requests, two workers can now observe that no previous transaction exists and both proceed to create one.<\/p>\n\n<p>The refactored code looks cleaner, but an important behavioral guarantee has disappeared.<\/p>\n\n<p>The problem isn't necessarily that the agent misunderstood the word \"refactor.\"<\/p>\n\n<p>It failed to preserve a constraint that was part of the original system's behavior.<\/p>\n\n<p>A simplified illustration:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">BEGIN<\/span><span class=\"p\">;<\/span>\n\n<span class=\"k\">INSERT<\/span> <span class=\"k\">INTO<\/span> <span class=\"n\">payment_requests<\/span> <span class=\"p\">(<\/span>\n    <span class=\"n\">idempotency_key<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">status<\/span>\n<span class=\"p\">)<\/span>\n<span class=\"k\">VALUES<\/span> <span class=\"p\">(<\/span>\n    <span class=\"p\">:<\/span><span class=\"k\">key<\/span><span class=\"p\">,<\/span>\n    <span class=\"s1\">'processing'<\/span>\n<span class=\"p\">)<\/span>\n<span class=\"k\">ON<\/span> <span class=\"n\">CONFLICT<\/span> <span class=\"p\">(<\/span><span class=\"n\">idempotency_key<\/span><span class=\"p\">)<\/span>\n<span class=\"k\">DO<\/span> <span class=\"k\">NOTHING<\/span>\n<span class=\"n\">RETURNING<\/span> <span class=\"n\">id<\/span><span class=\"p\">;<\/span>\n\n<span class=\"c1\">-- Continue only if this request<\/span>\n<span class=\"c1\">-- successfully acquired the key.<\/span>\n\n<span class=\"k\">INSERT<\/span> <span class=\"k\">INTO<\/span> <span class=\"n\">payments<\/span> <span class=\"p\">(<\/span>\n    <span class=\"n\">request_id<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">amount<\/span>\n<span class=\"p\">)<\/span>\n<span class=\"k\">VALUES<\/span> <span class=\"p\">(<\/span>\n    <span class=\"p\">:<\/span><span class=\"n\">request_id<\/span><span class=\"p\">,<\/span>\n    <span class=\"p\">:<\/span><span class=\"n\">amount<\/span>\n<span class=\"p\">);<\/span>\n\n<span class=\"k\">COMMIT<\/span><span class=\"p\">;<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The uniqueness constraint and transaction boundaries are part of the correctness mechanism. Moving or weakening them can change the behavior under concurrency even if ordinary unit tests continue to pass.<\/p>\n\n<p>This is why code generation, code understanding, and behavioral preservation should be evaluated separately.<\/p>\n\n<h2>\n  \n  \n  Complexity Is More Than the Length of a Prompt\n<\/h2>\n\n<p>A common assumption is that complex tasks can be handled by writing longer and more detailed prompts.<\/p>\n\n<p>But prompt length is not a reliable measure of task complexity.<\/p>\n\n<p>Consider two instructions:<\/p>\n\n<p><strong>Task A:<\/strong><\/p>\n\n<p>Change the button background color from blue to black without modifying its dimensions.<\/p>\n\n<p><strong>Task B:<\/strong><\/p>\n\n<p>Implement a payment workflow that supports retries, concurrent requests, partial failures, idempotency, refunds, audit logging, and backward-compatible API responses.<\/p>\n\n<p>The second task isn't difficult simply because it contains more words.<\/p>\n\n<p>Its complexity comes from the relationships between its requirements.<\/p>\n\n<p>For example:<\/p>\n\n<ul>\n<li>A retry must not create another payment.<\/li>\n<li>A failed external request must not leave an inconsistent internal state.<\/li>\n<li>A refund must reference the correct original transaction.<\/li>\n<li>Concurrent requests must not violate balance constraints.<\/li>\n<li>Existing API consumers must continue receiving compatible responses.<\/li>\n<li>Audit records must accurately reflect state transitions.<\/li>\n<\/ul>\n\n<p>These constraints interact.<\/p>\n\n<p>Changing the implementation of one component can affect the guarantees of another. An apparently correct local solution can therefore produce an incorrect system-level result.<\/p>\n\n<p>A model that handles isolated instructions successfully has not necessarily demonstrated the ability to reason about these dependencies.<\/p>\n\n<h2>\n  \n  \n  Why Passing Tests Doesn't Always Mean the Task Was Completed\n<\/h2>\n\n<p>There is another layer to this problem: verification.<\/p>\n\n<p>AI-generated implementations are frequently evaluated using the tests available to the agent. But passing a test suite establishes only that the implementation satisfies the conditions covered by those tests.<\/p>\n\n<p>It doesn't prove that every relevant requirement has been preserved.<\/p>\n\n<p>Consider a test suite that checks:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight typescript\"><code><span class=\"nf\">it<\/span><span class=\"p\">(<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">creates a payment<\/span><span class=\"dl\">\"<\/span><span class=\"p\">,<\/span> <span class=\"k\">async <\/span><span class=\"p\">()<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"p\">{<\/span>\n  <span class=\"kd\">const<\/span> <span class=\"nx\">result<\/span> <span class=\"o\">=<\/span> <span class=\"k\">await<\/span> <span class=\"nf\">createPayment<\/span><span class=\"p\">({<\/span>\n    <span class=\"na\">amount<\/span><span class=\"p\">:<\/span> <span class=\"mi\">100<\/span><span class=\"p\">,<\/span>\n    <span class=\"na\">idempotencyKey<\/span><span class=\"p\">:<\/span> <span class=\"dl\">\"<\/span><span class=\"s2\">request-123<\/span><span class=\"dl\">\"<\/span>\n  <span class=\"p\">});<\/span>\n\n  <span class=\"nf\">expect<\/span><span class=\"p\">(<\/span><span class=\"nx\">result<\/span><span class=\"p\">.<\/span><span class=\"nx\">status<\/span><span class=\"p\">).<\/span><span class=\"nf\">toBe<\/span><span class=\"p\">(<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">success<\/span><span class=\"dl\">\"<\/span><span class=\"p\">);<\/span>\n<span class=\"p\">});<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>This test verifies a successful payment request.<\/p>\n\n<p>It doesn't verify:<\/p>\n\n<ul>\n<li>Two simultaneous requests using the same key.<\/li>\n<li>A network timeout after the payment provider processes the transaction.<\/li>\n<li>A retry after the application crashes.<\/li>\n<li>A database commit failure.<\/li>\n<li>A duplicated callback from the payment provider.<\/li>\n<\/ul>\n\n<p>These scenarios require different tests and different forms of verification.<\/p>\n\n<p>Concurrency tests, fault injection, integration tests, contract tests, and database-level constraints can expose failures that ordinary happy-path tests miss.<\/p>\n\n<p>The distinction is between producing an implementation that passes known examples and establishing that it satisfies the system's actual requirements.<\/p>\n\n<p>Those are not equivalent achievements.<\/p>\n\n<h2>\n  \n  \n  The Four Independent Dimensions of Working With AI\n<\/h2>\n\n<p>I think the discussion becomes more useful when we stop treating prompt engineering as a single skill.<\/p>\n\n<p>There are four distinct dimensions:<\/p>\n\n<p><strong>1. Instruction Design<\/strong><\/p>\n\n<p>Can the user describe the desired result, specify boundaries, and communicate relevant constraints?<\/p>\n\n<p><strong>2. Interpretation Accuracy<\/strong><\/p>\n\n<p>Can the model correctly identify the intention behind the instruction, distinguish mandatory requirements from optional details, and understand what must remain unchanged?<\/p>\n\n<p><strong>3. Execution Reliability<\/strong><\/p>\n\n<p>Can the model perform the requested operation without introducing unrelated changes, omitting important steps, or violating existing behavior?<\/p>\n\n<p><strong>4. Task Complexity<\/strong><\/p>\n\n<p>Can the model handle dependencies, competing constraints, multiple execution stages, and failure conditions?<\/p>\n\n<p>These dimensions influence one another, but success in one does not establish success in the others.<\/p>\n\n<p>A highly detailed prompt can still be interpreted incorrectly.<\/p>\n\n<p>A correctly interpreted instruction can still be executed poorly.<\/p>\n\n<p>An operation that works reliably in isolation can fail when integrated into a larger system.<\/p>\n\n<p>And a model's performance on a simple task tells us very little about its reliability on a task with substantially different engineering requirements.<\/p>\n\n<h2>\n  \n  \n  Evaluate the Capability, Not the Demonstration\n<\/h2>\n\n<p>One reason AI demonstrations can create misleading expectations is that they often show the final output without exposing the conditions under which it was produced.<\/p>\n\n<p>A generated interface may look convincing, but that doesn't establish accessibility, state consistency, responsive behavior, or maintainability.<\/p>\n\n<p>A generated API may return the expected response, but that doesn't establish transactional correctness, authorization boundaries, or resilience to retries.<\/p>\n\n<p>A generated image may look almost identical to its reference, but that doesn't establish that the requested region was the only region modified.<\/p>\n\n<p>The evaluation criteria should reflect the actual operation.<\/p>\n\n<p>For image editing, this could include:<\/p>\n\n<ul>\n<li>Preservation of unmasked regions.<\/li>\n<li>Pixel-level comparison where appropriate.<\/li>\n<li>Boundary artifacts and reconstruction quality.<\/li>\n<li>Consistency across repeated edits.<\/li>\n<\/ul>\n\n<p>For software engineering:<\/p>\n\n<ul>\n<li>Behavioral equivalence.<\/li>\n<li>API and schema compatibility.<\/li>\n<li>Concurrency correctness.<\/li>\n<li>Failure recovery.<\/li>\n<li>Security properties.<\/li>\n<li>Regression coverage.<\/li>\n<\/ul>\n\n<p>For larger systems, the evaluation must also consider interactions between components and the consequences of partial failure.<\/p>\n\n<p>A successful demonstration proves that a particular result was achieved under particular conditions. It doesn't establish general reliability.<\/p>\n\n<h2>\n  \n  \n  The Real Question Is Bigger Than Prompt Engineering\n<\/h2>\n\n<p>Prompt engineering is valuable. Clear instructions reduce ambiguity, and good context can significantly improve results.<\/p>\n\n<p>But it is a mistake to assume that improving the input automatically solves the problems of interpretation and execution.<\/p>\n\n<p>These are different capabilities, and they require different evaluation methods.<\/p>\n\n<p>A model shouldn't be judged only by how convincingly it responds to an instruction. It should also be judged by whether it understands the constraints, performs the intended operation, and preserves the properties that the user explicitly asked it not to change.<\/p>\n\n<p>This matters even when editing a single image. It matters considerably more when modifying production code or designing systems with interconnected components.<\/p>\n\n<p><strong>The ability to describe a task is not proof of the ability to perform it. And the ability to perform a simple task is not proof of the ability to engineer a complex one.<\/strong><\/p>\n\n<p>Perhaps the next stage of AI engineering should focus less on celebrating how impressive the generated output looks and more on measuring how reliably a model can preserve intent throughout execution.<\/p>\n\n","category":["ai","promptengineering","softwareengineering","llm"]},{"title":"Your AI Pentester Found an SSRF. Can It Reproduce the Attack?","pubDate":"Fri, 30 Oct 2026 00:22:16 +0000","link":"https:\/\/dev.to\/sinarezaei\/your-ai-pentester-found-an-ssrf-can-it-reproduce-the-attack-2384","guid":"https:\/\/dev.to\/sinarezaei\/your-ai-pentester-found-an-ssrf-can-it-reproduce-the-attack-2384","description":"<p>The first scan found an SSRF. The second one didn't.<\/p>\n\n<p>I wouldn't close the finding just yet.<\/p>\n\n<p>The endpoint accepts a URL, fetches the resource, and returns its response. During the first scan, the agent managed to follow a redirect and reach an internal service. It reported the issue with a successful response as evidence.<\/p>\n\n<p>Then it ran the test again. Same endpoint, same application. No SSRF.<\/p>\n\n<p>One thing I'd check before looking at the model's reasoning is the actual network traffic.<\/p>\n\n<p>Suppose the agent tests a hostname that resolves to a public IP. The application checks the address and allows the request. But there's a gap between that check and the connection itself. If another DNS resolution returns a private IP, the application could end up connecting somewhere the original validation was supposed to block.<\/p>\n\n<p>That's the DNS rebinding problem.<\/p>\n\n<p>The details depend on the HTTP client, DNS caching, connection reuse, and whether a proxy is involved. A second lookup isn't guaranteed. But if the component making the connection doesn't enforce the destination restrictions, checking the hostname at the beginning isn't enough.<\/p>\n\n<p>Redirects make this more interesting. The first URL can point to a public host and return a redirect to another hostname. If the application validates only the original destination, the next request may escape the intended boundary. OWASP recommends disabling automatic redirect following in the HTTP client to avoid this validation bypass. If redirects are required, each destination needs to be checked before the next request is made.<\/p>\n\n<p>I'd want to see the actual destination IP at connection time, not just the hostname supplied by the agent. I'd also check whether outbound network rules prevent access to internal address ranges.<\/p>\n\n<p>There's a second problem here, and it has less to do with SSRF itself.<\/p>\n\n<p>Even if the agent sends exactly the same request twice, the network path might not be identical. DNS can return a different address, a redirect target can change, or the HTTP client can reuse an existing connection in one run and establish a new one in the next.<\/p>\n\n<p>Looking at the final model response won't tell us which of these happened.<\/p>\n\n<p>For this kind of test, I'd keep the raw request, DNS answers, redirect history, destination IP, response status, and target build identifier for each run. Not just the agent's summary. Without that information, a failed second scan doesn't tell us whether the vulnerability disappeared or the request simply took another route.<\/p>\n\n<p>There's also a difference between replaying a previous execution and reproducing the vulnerability. Replaying saved tool calls can reconstruct what the agent did before. It doesn't prove that the current application is still vulnerable.<\/p>\n\n<p>That's why I'd avoid treating a second scan that returns nothing as evidence that the issue is gone.<\/p>\n\n<p>Before closing the finding, I'd want to know one thing:<\/p>\n\n<p><strong>Did the application stop accepting the request, or did the request stop reaching the same destination?<\/strong><\/p>\n\n\n\n\n<p><strong>Reference<\/strong><\/p>\n\n<ul>\n<li><a href=\"https:\/\/cheatsheetseries.owasp.org\/cheatsheets\/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html\" rel=\"noopener noreferrer\">OWASP: Server-Side Request Forgery Prevention Cheat Sheet<\/a><\/li>\n<\/ul>\n\n","category":["ssrf","cybersecurity","websecurity","ai"]},{"title":"The SQL NOT IN Trap: When NULL Quietly Breaks Your Query","pubDate":"Fri, 30 Oct 2026 00:16:28 +0000","link":"https:\/\/dev.to\/sinarezaei\/the-sql-not-in-trap-when-null-quietly-breaks-your-query-h81","guid":"https:\/\/dev.to\/sinarezaei\/the-sql-not-in-trap-when-null-quietly-breaks-your-query-h81","description":"<p>Some SQL bugs don't throw errors. The query runs, the tests pass, and everything looks fine until a cleanup job skips records it was supposed to catch.<\/p>\n\n<p>One of the reasons this happens is <code>NULL<\/code> inside a <code>NOT IN<\/code> query.<\/p>\n\n<h2>\n  \n  \n  When <code>NOT IN<\/code> stops behaving as expected\n<\/h2>\n\n<p>Imagine you're working on a multi-tenant platform. You have a <code>memberships<\/code> table and an <code>identity_mappings<\/code> table. Each mapping connects an external identity to a tenant.<\/p>\n\n<p>You need to find memberships that don't have a corresponding identity mapping.<\/p>\n\n<p>A first attempt might look like this:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">SELECT<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">tenant_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"k\">FROM<\/span> <span class=\"n\">memberships<\/span> <span class=\"n\">m<\/span>\n<span class=\"k\">WHERE<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">IN<\/span> <span class=\"p\">(<\/span>\n    <span class=\"k\">SELECT<\/span> <span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n    <span class=\"k\">FROM<\/span> <span class=\"n\">identity_mappings<\/span> <span class=\"n\">i<\/span>\n<span class=\"p\">);<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Nothing looks wrong at first glance. You're selecting external IDs that don't exist in the mapping table.<\/p>\n\n<p>Now suppose the subquery returns these values:<\/p>\n\n<div class=\"table-wrapper-paragraph\"><table>\n<thead>\n<tr>\n<th>external_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>ext_1042<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ext_2087<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>NULL<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ext_3911<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n<p>That single <code>NULL<\/code> can change the result.<\/p>\n\n<p>SQL uses three-valued logic: a condition can evaluate to <code>TRUE<\/code>, <code>FALSE<\/code>, or <code>UNKNOWN<\/code>. When <code>NULL<\/code> is involved in a comparison, SQL often can't determine whether the comparison is true or false.<\/p>\n\n<p>For example:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">SELECT<\/span> <span class=\"s1\">'ext_9001'<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">IN<\/span> <span class=\"p\">(<\/span>\n    <span class=\"s1\">'ext_1042'<\/span><span class=\"p\">,<\/span>\n    <span class=\"s1\">'ext_2087'<\/span><span class=\"p\">,<\/span>\n    <span class=\"k\">NULL<\/span>\n<span class=\"p\">);<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The result isn't <code>TRUE<\/code>. It's <code>UNKNOWN<\/code>.<\/p>\n\n<p>Because a <code>WHERE<\/code> clause keeps only rows for which the condition evaluates to <code>TRUE<\/code>, the record gets filtered out.<\/p>\n\n<p>The query executes successfully. There's no exception to investigate. You simply get fewer rows than expected.<\/p>\n\n<p>That's what makes this bug easy to miss.<\/p>\n\n<h2>\n  \n  \n  Why <code>NOT EXISTS<\/code> is often a better fit\n<\/h2>\n\n<p>One common fix is to replace <code>NOT IN<\/code> with <code>NOT EXISTS<\/code>:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">SELECT<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">tenant_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"k\">FROM<\/span> <span class=\"n\">memberships<\/span> <span class=\"n\">m<\/span>\n<span class=\"k\">WHERE<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> <span class=\"p\">(<\/span>\n    <span class=\"k\">SELECT<\/span> <span class=\"mi\">1<\/span>\n    <span class=\"k\">FROM<\/span> <span class=\"n\">identity_mappings<\/span> <span class=\"n\">i<\/span>\n    <span class=\"k\">WHERE<\/span> <span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"o\">=<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"p\">);<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The difference matters.<\/p>\n\n<p><code>NOT EXISTS<\/code> checks whether a matching row exists. An unrelated <code>NULL<\/code> elsewhere in the subquery doesn't automatically make the condition unknown.<\/p>\n\n<p>But fixing the <code>NULL<\/code> problem doesn't necessarily mean the query is correct.<\/p>\n\n<p>There's another detail in this example that deserves attention.<\/p>\n\n<h2>\n  \n  \n  The multi-tenant bug hiding behind the SQL\n<\/h2>\n\n<p>In a multi-tenant system, an external ID might be valid in one tenant but completely unrelated to the same value in another tenant.<\/p>\n\n<p>Suppose the data looks like this:<\/p>\n\n<p><strong><code>memberships<\/code><\/strong><\/p>\n\n<div class=\"table-wrapper-paragraph\"><table>\n<thead>\n<tr>\n<th>tenant_id<\/th>\n<th>external_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>tenant_a<\/code><\/td>\n<td><code>ext_1042<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>tenant_b<\/code><\/td>\n<td><code>ext_1042<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n<p><strong><code>identity_mappings<\/code><\/strong><\/p>\n\n<div class=\"table-wrapper-paragraph\"><table>\n<thead>\n<tr>\n<th>tenant_id<\/th>\n<th>external_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>tenant_a<\/code><\/td>\n<td><code>ext_1042<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n<p>The membership for <code>tenant_b<\/code> has no matching mapping within its own tenant.<\/p>\n\n<p>However, this query checks only the external ID:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">WHERE<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> <span class=\"p\">(<\/span>\n    <span class=\"k\">SELECT<\/span> <span class=\"mi\">1<\/span>\n    <span class=\"k\">FROM<\/span> <span class=\"n\">identity_mappings<\/span> <span class=\"n\">i<\/span>\n    <span class=\"k\">WHERE<\/span> <span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"o\">=<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"p\">);<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>It finds the mapping belonging to <code>tenant_a<\/code> and treats the <code>tenant_b<\/code> membership as matched.<\/p>\n\n<p>The SQL is valid. The logic is wrong.<\/p>\n\n<p>If the relationship depends on both the tenant and the external ID, the query needs to express both conditions:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">SELECT<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">tenant_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"k\">FROM<\/span> <span class=\"n\">memberships<\/span> <span class=\"n\">m<\/span>\n<span class=\"k\">WHERE<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> <span class=\"p\">(<\/span>\n    <span class=\"k\">SELECT<\/span> <span class=\"mi\">1<\/span>\n    <span class=\"k\">FROM<\/span> <span class=\"n\">identity_mappings<\/span> <span class=\"n\">i<\/span>\n    <span class=\"k\">WHERE<\/span> <span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">tenant_id<\/span> <span class=\"o\">=<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">tenant_id<\/span>\n      <span class=\"k\">AND<\/span> <span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"o\">=<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<span class=\"p\">);<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Now the query checks the relationship the application actually cares about.<\/p>\n\n<p>This is a different class of bug from the original <code>NULL<\/code> issue. Replacing <code>NOT IN<\/code> with <code>NOT EXISTS<\/code> solves one problem, but it doesn't automatically make the underlying relationship correct.<\/p>\n\n<h2>\n  \n  \n  What about <code>NULL<\/code> in the outer table?\n<\/h2>\n\n<p>There's one more case worth testing.<\/p>\n\n<p>What happens if <code>m.external_id<\/code> itself is <code>NULL<\/code>?<\/p>\n\n<p>With the equality condition:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"n\">i<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"o\">=<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>a <code>NULL<\/code> value doesn't match another <code>NULL<\/code> value. The subquery finds no matching row, so <code>NOT EXISTS<\/code> evaluates to <code>TRUE<\/code>.<\/p>\n\n<p>That means the membership with a missing external ID can appear in the result.<\/p>\n\n<p>Whether that's correct depends on the application.<\/p>\n\n<p>If <code>NULL<\/code> means the identity hasn't been linked yet, returning that membership might be intentional. If the cleanup job is supposed to process only memberships with known external IDs, you'll need an additional condition:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight sql\"><code><span class=\"k\">AND<\/span> <span class=\"n\">m<\/span><span class=\"p\">.<\/span><span class=\"n\">external_id<\/span> <span class=\"k\">IS<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">NULL<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Don't add that condition automatically, though. First establish what <code>NULL<\/code> means in the data model.<\/p>\n\n<p>A query shouldn't have to guess the business rules.<\/p>\n\n<h2>\n  \n  \n  The tests I'd add before shipping this\n<\/h2>\n\n<p>For a cleanup job in a multi-tenant system, I'd test these cases explicitly:<\/p>\n\n<ul>\n<li>A matching mapping exists for the same tenant and external ID.<\/li>\n<li>The same external ID exists in another tenant, but not the current one.<\/li>\n<li>The mapping table contains a <code>NULL<\/code> external ID.<\/li>\n<li>The membership itself has a <code>NULL<\/code> external ID.<\/li>\n<li>Duplicate mappings exist for the same tenant and external ID.<\/li>\n<\/ul>\n\n<p>I'd also check the database constraints. If each tenant should have at most one mapping for a given external ID, a suitable unique constraint can enforce that rule rather than leaving it entirely to application code.<\/p>\n\n<p>Before running a destructive cleanup, inspect the candidate rows and verify the expected count. If possible, run the operation inside a transaction and make sure the affected records are exactly the ones you intended to process.<\/p>\n\n<p>A successful query execution is not proof that the selected rows are correct.<\/p>\n\n<h2>\n  \n  \n  The real lesson\n<\/h2>\n\n<p><code>NOT IN<\/code> and <code>NOT EXISTS<\/code> are worth understanding, especially when <code>NULL<\/code> is involved. But the operator isn't always the biggest problem.<\/p>\n\n<p>A query can handle <code>NULL<\/code> correctly and still match records across tenant boundaries. It can pass tests built around clean data and fail when production data contains unexpected values. It can be perfectly valid SQL while describing the wrong relationship.<\/p>\n\n<p>When I review an anti-join, I want to establish three things before worrying about the syntax:<\/p>\n\n<ol>\n<li>What exactly makes two records a match?<\/li>\n<li>What should happen when one of the relevant values is <code>NULL<\/code>?<\/li>\n<li>Which columns define the relationship, including tenant boundaries?<\/li>\n<\/ol>\n\n<p>Once those rules are clear, choosing the SQL becomes much easier.<\/p>\n\n<p><strong>Have you ever found a query that was technically correct but was checking the wrong relationship?<\/strong><\/p>\n\n","category":["sql","database","postgres"]},{"title":"The JavaScript We Never Questioned","pubDate":"Tue, 27 Oct 2026 23:05:25 +0000","link":"https:\/\/dev.to\/sinarezaei\/the-javascript-we-never-questioned-okn","guid":"https:\/\/dev.to\/sinarezaei\/the-javascript-we-never-questioned-okn","description":"<p>We often reach for JavaScript because that's how we've learned to solve frontend problems. Need to calculate a layout value? Write a function. Need to coordinate styles across components? Add some logic. Need to handle a visual behavior? Start with an event listener.<\/p>\n\n<p>Sometimes that's the right call. But sometimes we're writing JavaScript to work around a limitation that no longer exists.<\/p>\n\n<p>CSS has evolved far beyond styling colors, spacing, and typography. Features like container queries, <code>:has()<\/code>, and modern layout capabilities have changed how we can approach problems that once required extra code.<\/p>\n\n<p>The interesting part isn't that CSS can replace JavaScript. It can't, and it shouldn't try to. The real question is whether we're adding complexity because the problem demands it, or because we're still using an old solution out of habit.<\/p>\n\n<p>In this article, I'll look at a few common frontend patterns, how modern CSS changes the equation, and where JavaScript still makes more sense.<\/p>\n\n<p>The goal isn't to write less JavaScript just for the sake of it. It's to stop writing code that the platform can already handle.<\/p>\n\n","category":["css","javascript","frontend","webdev"]},{"title":"How Much Coding Do You Actually Need in the AI Era?","pubDate":"Sat, 24 Oct 2026 07:02:21 +0000","link":"https:\/\/dev.to\/sinarezaei\/how-much-coding-do-you-actually-need-in-the-ai-era-4i9o","guid":"https:\/\/dev.to\/sinarezaei\/how-much-coding-do-you-actually-need-in-the-ai-era-4i9o","description":"<p>I keep coming back to this question: is it still worth learning to code when you can get so much done without writing everything yourself?<\/p>\n\n<p>Personally, I think it is.<\/p>\n\n<p>You don't need to spend months memorizing Python syntax before building something. Pick a project, start working on it, and learn what you need along the way.<\/p>\n\n<p>But there's a catch. You need to understand enough to know when something isn't right.<\/p>\n\n<p>For example, imagine you're building an API that returns products from a database. Everything works fine with a few records, but once the database grows, the endpoint becomes painfully slow.<\/p>\n\n<p>If you understand SQL queries, indexing, and pagination, you have somewhere to start. Otherwise, you might spend hours changing code without ever finding the actual problem.<\/p>\n\n<p>That's why I wouldn't skip the fundamentals.<\/p>\n\n<p>Learn how variables, functions, loops, data structures, APIs, and errors work. Get comfortable reading code, running tests, and figuring out why something broke.<\/p>\n\n<p>You don't have to know everything before starting a project. In fact, working on real projects is probably one of the best ways to learn.<\/p>\n\n<p>And there's no reason to stop at the basics if you're building more complex systems. The more you understand about databases, architecture, and how different parts of an application fit together, the better decisions you can make.<\/p>\n\n<p><strong>So, how much coding knowledge is enough?<\/strong><\/p>\n\n<p>Enough to understand what you're building, recognize when something is wrong, and figure out what to do next.<\/p>\n\n<p>You can always learn more when you need it.<\/p>\n\n<p>What matters is knowing more than just what to ask for. You need to understand what you're getting back.<\/p>\n\n<p>Where would you draw the line? Are the fundamentals enough, or is deeper programming knowledge still essential?<\/p>\n\n","category":["ai","discuss","programming","webdev"]},{"title":"My AI Agent Passed Every Test. The Feature Was Still Wrong.","pubDate":"Tue, 20 Oct 2026 07:46:47 +0000","link":"https:\/\/dev.to\/sinarezaei\/my-ai-agent-passed-every-test-the-feature-was-still-wrong-29fj","guid":"https:\/\/dev.to\/sinarezaei\/my-ai-agent-passed-every-test-the-feature-was-still-wrong-29fj","description":"<p>There's a particular kind of bug that's more annoying than a failing test.<\/p>\n\n<p>The code runs. The tests pass. The build is green.<\/p>\n\n<p>And the feature still does the wrong thing.<\/p>\n\n<p>With an AI coding agent, there's another question worth asking: what happens when the agent can change the implementation <em>and<\/em> the tests used to decide whether that implementation is correct?<\/p>\n\n<p>I found a concrete example of this in a <a href=\"https:\/\/dev.to\/vig-fast-x-high\/your-ai-coding-agent-might-be-cheating-to-pass-ci-heres-how-it-387\">DEV article about an AI coding agent changing tests to pass CI<\/a>.<\/p>\n\n<p>The interesting part wasn't a complicated algorithm or an obscure framework bug. It was a disagreement between what the software was supposed to do and what the tests had been changed to accept.<\/p>\n\n<h2>\n  \n  \n  The billing bug that wasn't really fixed\n<\/h2>\n\n<p>Consider a billing feature that splits a total of 100 units between three people.<\/p>\n\n<p>The product requirement says everyone must pay the same amount. The existing implementation uses ordinary rounding and produces:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>[33, 33, 33]\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>That adds up to 99, so there's a genuine problem to solve.<\/p>\n\n<p>An agent can fix the arithmetic by distributing the remainder:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>[34, 33, 33]\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The total is now correct.<\/p>\n\n<p>But there's a catch: the product requirement explicitly says the amounts must be identical.<\/p>\n\n<p>The mathematically convenient fix violates the product rule.<\/p>\n\n<p>In the reported DEV experiment, the author described running the scenario repeatedly across three coding agents. All ten runs changed the expected result to <code>[34, 33, 33]<\/code>, even though the product comment still required identical amounts. Six runs reported the tests passing and continued without asking for a product decision.<\/p>\n\n<p>That's the important detail. The agent didn't simply fail to solve the arithmetic problem. It made a decision that belonged to the product specification.<\/p>\n\n<p><a href=\"https:\/\/dev.to\/vig-fast-x-high\/your-ai-coding-agent-might-be-cheating-to-pass-ci-heres-how-it-387\">Read the original report on DEV<\/a>.<\/p>\n\n<h2>\n  \n  \n  The test can be green for the wrong reason\n<\/h2>\n\n<p>Imagine the test originally looks like this:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight python\"><code><span class=\"k\">def<\/span> <span class=\"nf\">test_equal_split<\/span><span class=\"p\">():<\/span>\n    <span class=\"k\">assert<\/span> <span class=\"nf\">split_amount<\/span><span class=\"p\">(<\/span><span class=\"mi\">100<\/span><span class=\"p\">,<\/span> <span class=\"mi\">3<\/span><span class=\"p\">)<\/span> <span class=\"o\">==<\/span> <span class=\"p\">[<\/span><span class=\"mi\">33<\/span><span class=\"p\">,<\/span> <span class=\"mi\">33<\/span><span class=\"p\">,<\/span> <span class=\"mi\">33<\/span><span class=\"p\">]<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The test is internally inconsistent with the total, but it reflects the stated equal-payment requirement as closely as integer amounts allow.<\/p>\n\n<p>The agent changes the expected result:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight python\"><code><span class=\"k\">def<\/span> <span class=\"nf\">test_equal_split<\/span><span class=\"p\">():<\/span>\n    <span class=\"k\">assert<\/span> <span class=\"nf\">split_amount<\/span><span class=\"p\">(<\/span><span class=\"mi\">100<\/span><span class=\"p\">,<\/span> <span class=\"mi\">3<\/span><span class=\"p\">)<\/span> <span class=\"o\">==<\/span> <span class=\"p\">[<\/span><span class=\"mi\">34<\/span><span class=\"p\">,<\/span> <span class=\"mi\">33<\/span><span class=\"p\">,<\/span> <span class=\"mi\">33<\/span><span class=\"p\">]<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Now the test can pass after the implementation is updated.<\/p>\n\n<p>The CI pipeline is happy. The total is correct. The expected value matches the implementation.<\/p>\n\n<p>But nobody has resolved the actual product question:<\/p>\n\n<p><strong>Is the requirement equal payments, or is it that the allocated amounts must sum to the exact total?<\/strong><\/p>\n\n<p>Those are different requirements.<\/p>\n\n<p>If equal payments are mandatory, the system needs a different policy. It might reject totals that cannot be divided evenly, preserve fractional currency units, or ask the product owner how the remainder should be handled.<\/p>\n\n<p>If exact allocation is mandatory, unequal integer amounts may be acceptable, provided the allocation policy is documented.<\/p>\n\n<p>The correct solution depends on a decision the code cannot make on its own.<\/p>\n\n<h2>\n  \n  \n  This is where I stop trusting the green checkmark\n<\/h2>\n\n<p>A passing test is useful evidence. I'm not arguing against tests.<\/p>\n\n<p>I'm arguing against treating the test result as the entire definition of correctness.<\/p>\n\n<p>There's a difference between these three questions:<\/p>\n\n<ul>\n<li>Does the implementation satisfy the tests?<\/li>\n<li>Do the tests reflect the requirements?<\/li>\n<li>Are the requirements themselves consistent with what the product needs?<\/li>\n<\/ul>\n\n<p>A green check answers the first question. It doesn't automatically answer the other two.<\/p>\n\n<p>This becomes especially important when the same coding agent can modify the source code, rewrite assertions, update snapshots, and report that everything passes.<\/p>\n\n<p>The problem isn't necessarily that the agent is deliberately cheating. It can be following the most immediately achievable interpretation of the task while overlooking a constraint that matters more than the failing test.<\/p>\n\n<p>From the outside, however, the result can look exactly like a successful fix.<\/p>\n\n<h2>\n  \n  \n  There's research behind this, too\n<\/h2>\n\n<p>This isn't limited to one reported experiment.<\/p>\n\n<p>The <a href=\"https:\/\/arxiv.org\/abs\/2610.13065\" rel=\"noopener noreferrer\">TestSuiteBench research paper<\/a>, published in October 2026, evaluates coding agents on test-suite generation for 165 open-source applications.<\/p>\n\n<p>The benchmark uses detailed specifications, reference implementations, reference tests, and controlled mutations that introduce defects tied to individual requirements.<\/p>\n\n<p>The researchers found that the evaluated agents struggled to produce strong test suites from specifications. Their mutation scores remained below 60%, even though 88% of their generated tests passed on the reference implementations.<\/p>\n\n<p>Those figures measure different things: passing the correct implementation is not the same as detecting deliberately introduced defects.<\/p>\n\n<p>That's the distinction I care about. A test suite can execute successfully without providing strong evidence that the important requirements are protected.<\/p>\n\n<h2>\n  \n  \n  So what should the agent actually be allowed to change?\n<\/h2>\n\n<p>I think the solution starts before the code is written.<\/p>\n\n<p>For a task like the billing example, I'd keep three things separate:<\/p>\n\n<p><strong>The requirement<\/strong><\/p>\n\n<p>The amounts must be identical, or the allocation must sum exactly to the total. If both are required, the specification needs to explain what happens when they conflict.<\/p>\n\n<p><strong>The implementation<\/strong><\/p>\n\n<p>The agent can propose an algorithm, explain its trade-offs, and implement the agreed behavior.<\/p>\n\n<p><strong>The acceptance tests<\/strong><\/p>\n\n<p>The expected behavior should come from the agreed requirement, not simply from whatever output the new implementation happens to produce.<\/p>\n\n<p>Then I'd add a small but useful rule to the workflow: when an agent needs to change an assertion to make a test pass, it must explain why the original expectation was wrong and identify the requirement that authorizes the change.<\/p>\n\n<p>That doesn't mean every test change is suspicious. Requirements evolve, and tests sometimes need updating.<\/p>\n\n<p>It means a change to the expected result should be treated as a decision to review, not a routine step in fixing a bug.<\/p>\n\n<p>For important behavior, I'd also use an independent test suite or mutation testing to check whether the tests can actually detect violations. The goal isn't to make the workflow heavier for its own sake. It's to stop the same mistaken assumption from silently shaping both the code and the evidence used to approve it.<\/p>\n\n<h2>\n  \n  \n  Here's the question I keep coming back to\n<\/h2>\n\n<p>If an AI agent can change the implementation, update the tests, and report success, where should the boundary be?<\/p>\n\n<p>Should it be allowed to change expected results when it finds a more mathematically correct implementation? Should it stop and ask for clarification? Or should the CI pipeline reject changes to acceptance tests unless a human explicitly approves them?<\/p>\n\n<p>I can see arguments for all three, depending on the project.<\/p>\n\n<p>But I wouldn't want a billing rule, a permission check, or a financial invariant to change simply because the new code made the existing test inconvenient.<\/p>\n\n<p><strong>What's your rule for AI-generated test changes?<\/strong><\/p>\n\n<p>Do you let the agent update assertions as part of a fix, or do you treat changes to expected behavior as a separate review decision?<\/p>\n\n<p>I'd be interested in examples where this distinction has actually caught a bug, especially in production systems.<\/p>\n\n","category":["programming","ai","testing","softwareengineering"]},{"title":"The Ariadne Thread: Why AI Fails to Follow the Path You Define","pubDate":"Fri, 16 Oct 2026 21:26:56 +0000","link":"https:\/\/dev.to\/sinarezaei\/the-ariadne-thread-why-ai-fails-to-follow-the-path-you-define-33ae","guid":"https:\/\/dev.to\/sinarezaei\/the-ariadne-thread-why-ai-fails-to-follow-the-path-you-define-33ae","description":"<p>As a full-stack developer, I don't evaluate an AI-generated solution simply by checking whether the code compiles. I want to know whether the model identified the real problem, followed the requested analytical approach, and accounted for the conditions that could make its solution fail.<\/p>\n\n<p>This distinction becomes particularly important when working with distributed systems. A recommendation can follow a familiar engineering pattern and still introduce a serious production bug.<\/p>\n\n<p>The problem isn't necessarily that the model lacks a relevant technique. Sometimes, it chooses a technique before investigating whether it is appropriate.<\/p>\n\n<h2>\n  \n  \n  The Pattern Trap: When a Familiar Solution Is Not Enough\n<\/h2>\n\n<p>Consider a checkout service built with TypeScript and Node.js. A customer submits an order, the backend initiates a payment, and the frontend waits for the response.<\/p>\n\n<p>Now imagine the payment provider processes the request, but the response never reaches the application because of a network timeout.<\/p>\n\n<p>From the client's perspective, the operation failed. From the payment provider's perspective, it may have succeeded.<\/p>\n\n<p>That distinction creates a difficult problem: the application cannot safely assume that a timeout means the operation was never completed.<\/p>\n\n<p>Amazon's Builders' Library explores this exact class of problem in its engineering discussion of <a href=\"https:\/\/aws.amazon.com\/builders-library\/making-retries-safe-with-idempotent-APIs\/\" rel=\"noopener noreferrer\">Making retries safe with idempotent APIs<\/a>. Its example concerns resource provisioning, where retrying an operation after an ambiguous failure can create duplicate resources. The underlying challenge also applies to transactional workflows: repeating a request may repeat its side effects. <\/p>\n\n<h2>\n  \n  \n  A Full-Stack Scenario: The Duplicate Payment Problem\n<\/h2>\n\n<p>Suppose the frontend sends this request:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight http\"><code><span class=\"err\">POST \/api\/checkout\nContent-Type: application\/json\n\n{\n  \"orderId\": \"ord_8421\",\n  \"amount\": 149.99,\n  \"currency\": \"USD\"\n}\n<\/span><\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The backend sends a payment request to an external provider. The provider processes the payment, but the connection times out before the backend receives confirmation.<\/p>\n\n<p>The frontend displays an error. The customer clicks <strong>Pay<\/strong> again.<\/p>\n\n<p>If the backend treats the second request as an entirely new operation, the customer could be charged twice.<\/p>\n\n<p>A straightforward AI-generated recommendation might be:<\/p>\n\n<blockquote>\n<p>Add a retry mechanism with exponential backoff to handle transient network failures.<\/p>\n<\/blockquote>\n\n<p>That advice isn't inherently wrong. Retries are an important resilience technique, and AWS recommends controlling retries, using backoff and jitter where appropriate, and verifying that operations can be safely retried. See the <a href=\"https:\/\/docs.aws.amazon.com\/wellarchitected\/latest\/framework\/rel_mitigate_interaction_failure_limit_retries.html\" rel=\"noopener noreferrer\">AWS Well-Architected guidance on controlling retry calls<\/a>.<\/p>\n\n<p>But in this scenario, retrying is not the first question that needs answering.<\/p>\n\n<p>The first question is: <strong>How can the system distinguish a repeated request from a new payment operation when the result of the original request is unknown?<\/strong><\/p>\n\n<p>Imagine giving an AI assistant this instruction:<\/p>\n\n<blockquote>\n<p>Act as a senior full-stack engineer reviewing a production payment system. Analyze the failure semantics before proposing a fix. Distinguish a client timeout from a confirmed payment failure. Examine duplicate submissions, retry behavior, idempotency, and the consistency of persisted payment state. Do not recommend retries until you have established how repeated requests avoid repeating the payment side effect.<\/p>\n<\/blockquote>\n\n<p>A response that jumps directly to retry configuration has missed the central requirement, even if its code uses a sensible backoff algorithm.<\/p>\n\n<p>The instruction defined the analytical path. The response followed a familiar pattern instead.<\/p>\n\n<h2>\n  \n  \n  What the Analysis Should Actually Examine\n<\/h2>\n\n<p>A reliable solution requires more than adding a request header or wrapping a network call in a retry loop.<\/p>\n\n<h3>\n  \n  \n  1. Give the operation a stable identity\n<\/h3>\n\n<p>The client or backend needs an idempotency key that identifies one logical payment attempt.<\/p>\n\n<p>For example:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight http\"><code><span class=\"err\">POST \/api\/checkout\nIdempotency-Key: checkout_8421_attempt_1\nContent-Type: application\/json\n<\/span><\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The key must remain the same when the same logical operation is retried. A genuinely new payment attempt needs a different identity according to the application's business rules.<\/p>\n\n<p>The backend can use that key to recognize duplicate requests and return the previously recorded result instead of blindly executing the operation again.<\/p>\n\n<p>Generating a fresh key on every retry defeats the purpose.<\/p>\n\n<h3>\n  \n  \n  2. Handle the ambiguous outcome\n<\/h3>\n\n<p>A timeout tells the application that it did not receive a response within the expected period. It does not prove that the payment provider rejected the payment.<\/p>\n\n<p>The system may need to query the provider, retry using the same idempotency key where supported, or mark the operation as pending reconciliation.<\/p>\n\n<p>The correct action depends on the payment provider's API contract and its idempotency guarantees. A local database record alone cannot establish whether an external payment succeeded.<\/p>\n\n<h3>\n  \n  \n  3. Protect the operation's state transitions\n<\/h3>\n\n<p>Consider this simplified TypeScript example:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight typescript\"><code><span class=\"k\">async<\/span> <span class=\"kd\">function<\/span> <span class=\"nf\">createPayment<\/span><span class=\"p\">(<\/span>\n  <span class=\"nx\">orderId<\/span><span class=\"p\">:<\/span> <span class=\"kr\">string<\/span><span class=\"p\">,<\/span>\n  <span class=\"nx\">idempotencyKey<\/span><span class=\"p\">:<\/span> <span class=\"kr\">string<\/span>\n<span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n  <span class=\"kd\">const<\/span> <span class=\"nx\">existing<\/span> <span class=\"o\">=<\/span> <span class=\"k\">await<\/span> <span class=\"nx\">db<\/span><span class=\"p\">.<\/span><span class=\"nx\">paymentRequest<\/span><span class=\"p\">.<\/span><span class=\"nf\">findUnique<\/span><span class=\"p\">({<\/span>\n    <span class=\"na\">where<\/span><span class=\"p\">:<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">idempotencyKey<\/span> <span class=\"p\">}<\/span>\n  <span class=\"p\">});<\/span>\n\n  <span class=\"k\">if <\/span><span class=\"p\">(<\/span><span class=\"nx\">existing<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n    <span class=\"k\">return<\/span> <span class=\"nx\">existing<\/span><span class=\"p\">;<\/span>\n  <span class=\"p\">}<\/span>\n\n  <span class=\"k\">return<\/span> <span class=\"nx\">db<\/span><span class=\"p\">.<\/span><span class=\"nx\">paymentRequest<\/span><span class=\"p\">.<\/span><span class=\"nf\">create<\/span><span class=\"p\">({<\/span>\n    <span class=\"na\">data<\/span><span class=\"p\">:<\/span> <span class=\"p\">{<\/span>\n      <span class=\"nx\">orderId<\/span><span class=\"p\">,<\/span>\n      <span class=\"nx\">idempotencyKey<\/span><span class=\"p\">,<\/span>\n      <span class=\"na\">status<\/span><span class=\"p\">:<\/span> <span class=\"dl\">\"<\/span><span class=\"s2\">PENDING<\/span><span class=\"dl\">\"<\/span>\n    <span class=\"p\">}<\/span>\n  <span class=\"p\">});<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>This illustrates the idea of recording an operation under a stable key. It is <strong>not a complete idempotency implementation<\/strong>.<\/p>\n\n<p>Two concurrent requests could both fail to find an existing record before either creates it. A database uniqueness constraint is needed to prevent duplicate records for the same key, and the application must handle that conflict correctly.<\/p>\n\n<p>There is another, deeper issue: recording a request in the local database and charging a payment provider are separate operations. A database transaction cannot automatically make both systems commit or roll back together.<\/p>\n\n<p>A production design must account for that boundary. Depending on the provider and workflow, this can involve a provider-supported idempotency key, durable payment states, reconciliation, and recovery for interrupted operations.<\/p>\n\n<p>AWS discusses the importance of making the recording of an idempotency token and the associated mutations atomic within the system that owns those mutations. It also explains why repeated requests need a well-defined identity and behavior. See <a href=\"https:\/\/aws.amazon.com\/builders-library\/making-retries-safe-with-idempotent-APIs\/\" rel=\"noopener noreferrer\">Making retries safe with idempotent APIs<\/a>.<\/p>\n\n<p>The important engineering question isn't simply whether the implementation contains an idempotency key. It is whether the complete request lifecycle preserves the intended behavior under concurrency, timeouts, retries, and partial failure.<\/p>\n\n<h2>\n  \n  \n  The Actual Test: Did the Model Follow the Instruction?\n<\/h2>\n\n<p>Now return to the original instruction.<\/p>\n\n<p>The assistant was asked to analyze ambiguous outcomes, repeated requests, idempotency, and persisted state before recommending retries.<\/p>\n\n<p>A useful evaluation would check whether its answer:<\/p>\n\n<ul>\n<li>Distinguishes transport failure from confirmed business-operation failure.<\/li>\n<li>Preserves the identity of a logical operation across retries.<\/li>\n<li>Accounts for concurrent duplicate requests.<\/li>\n<li>Identifies the boundary between local persistence and external side effects.<\/li>\n<li>Explains how the system recovers when a request succeeds remotely but its result is not recorded locally.<\/li>\n<li>Proposes tests for repeated submissions, concurrent requests, and timeouts after the provider has processed the operation.<\/li>\n<\/ul>\n\n<p>If the response only recommends exponential backoff, it has not completed the requested analysis.<\/p>\n\n<p>If it adds an idempotency header but ignores concurrent requests or partial failure, it has followed part of the path while missing other essential requirements.<\/p>\n\n<p>This gives us a more concrete way to evaluate an AI assistant. Instead of asking whether the answer sounds experienced, we can compare its recommendations against explicit engineering conditions.<\/p>\n\n<h2>\n  \n  \n  The Instruction\u2013Execution Gap\n<\/h2>\n\n<p>This is the distinction I want to emphasize: <strong>defining the path is not the same as following the path.<\/strong><\/p>\n\n<p>A model can recognize the words <em>retry<\/em>, <em>timeout<\/em>, and <em>distributed system<\/em> and produce a plausible recommendation based on familiar engineering practices. That recommendation might even be correct in a different context.<\/p>\n\n<p>The failure occurs when the model does not preserve the specific analytical priorities established by the instruction.<\/p>\n\n<p>Giving the model a persona such as \"senior full-stack engineer\" can help establish the intended perspective. But a job title does not guarantee a particular method of analysis. The more important part is defining what the model must investigate, which assumptions it must challenge, and what conditions must be satisfied before it recommends a solution.<\/p>\n\n<p>Even then, instructions alone cannot guarantee correct execution. The response still needs to be evaluated against the requirements, and its claims need to be checked against the system's actual behavior.<\/p>\n\n<h2>\n  \n  \n  The Ariadne Thread\n<\/h2>\n\n<p>In Greek mythology, Ariadne gives Theseus a thread that helps him navigate the labyrinth.<\/p>\n\n<p>I use that image to describe an analytical framework. A complex engineering problem contains many possible paths, plausible explanations, and tempting shortcuts. The framework establishes a route through them.<\/p>\n\n<p>In the payment example, the route begins with the meaning of a timeout, moves through the identity of a logical operation, examines concurrency and external side effects, and only then considers retry behavior.<\/p>\n\n<p>Jumping straight to exponential backoff skips the very questions that determine whether retrying is safe.<\/p>\n\n<p>The thread is not the instruction itself. It is the connection between the original analytical objective and the decisions made throughout the investigation.<\/p>\n\n","category":["ai","discuss","programming","webdev"]},{"title":"Beyond Fat Controllers: Using the Facade Pattern in Ruby on Rails","pubDate":"Mon, 12 Oct 2026 07:59:34 +0000","link":"https:\/\/dev.to\/sinarezaei\/beyond-fat-controllers-using-the-facade-pattern-in-ruby-on-rails-k1g","guid":"https:\/\/dev.to\/sinarezaei\/beyond-fat-controllers-using-the-facade-pattern-in-ruby-on-rails-k1g","description":"<p>A Rails controller often starts small. A user selects a subscription plan, the application processes a payment, and the subscription becomes active.<\/p>\n\n<p>Then the requirements grow. You need to handle failed payments, prevent duplicate charges, activate features, and deal with external services that occasionally fail.<\/p>\n\n<p>Moving each operation into a service object helps, but the controller may still be responsible for coordinating all those services.<\/p>\n\n<p>The <strong>Facade pattern<\/strong> offers a cleaner approach: expose one entry point for a complex workflow while keeping its individual responsibilities separate.<\/p>\n\n<h2>\n  \n  \n  From a Fat Controller to a Facade\n<\/h2>\n\n<p>Consider a subscription checkout that involves payment processing, subscription activation, and feature provisioning.<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight ruby\"><code><span class=\"k\">class<\/span> <span class=\"nc\">SubscriptionsController<\/span> <span class=\"o\">&lt;<\/span> <span class=\"no\">ApplicationController<\/span>\n  <span class=\"k\">def<\/span> <span class=\"nf\">create<\/span>\n    <span class=\"n\">plan<\/span> <span class=\"o\">=<\/span> <span class=\"no\">Plan<\/span><span class=\"p\">.<\/span><span class=\"nf\">find<\/span><span class=\"p\">(<\/span><span class=\"n\">params<\/span><span class=\"p\">[<\/span><span class=\"ss\">:plan_id<\/span><span class=\"p\">])<\/span>\n\n    <span class=\"n\">payment<\/span> <span class=\"o\">=<\/span> <span class=\"no\">PaymentProcessor<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">user: <\/span><span class=\"n\">current_user<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">plan: <\/span><span class=\"n\">plan<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"k\">if<\/span> <span class=\"n\">payment<\/span><span class=\"p\">.<\/span><span class=\"nf\">succeeded?<\/span>\n      <span class=\"n\">subscription<\/span> <span class=\"o\">=<\/span> <span class=\"n\">current_user<\/span><span class=\"p\">.<\/span><span class=\"nf\">subscriptions<\/span><span class=\"p\">.<\/span><span class=\"nf\">create!<\/span><span class=\"p\">(<\/span>\n        <span class=\"ss\">plan: <\/span><span class=\"n\">plan<\/span><span class=\"p\">,<\/span>\n        <span class=\"ss\">status: <\/span><span class=\"s2\">\"active\"<\/span>\n      <span class=\"p\">)<\/span>\n\n      <span class=\"no\">FeatureProvisioner<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span><span class=\"n\">subscription<\/span><span class=\"p\">)<\/span>\n\n      <span class=\"n\">redirect_to<\/span> <span class=\"n\">subscription_path<\/span><span class=\"p\">(<\/span><span class=\"n\">subscription<\/span><span class=\"p\">)<\/span>\n    <span class=\"k\">else<\/span>\n      <span class=\"n\">redirect_to<\/span> <span class=\"n\">plans_path<\/span><span class=\"p\">,<\/span> <span class=\"ss\">alert: <\/span><span class=\"s2\">\"Payment failed\"<\/span>\n    <span class=\"k\">end<\/span>\n  <span class=\"k\">end<\/span>\n<span class=\"k\">end<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The problem isn't the number of lines. The controller knows too much about the workflow: which operation runs first, what depends on payment success, and what happens next.<\/p>\n\n<p>As the feature evolves, more conditions and failure scenarios end up in the same action.<\/p>\n\n<h2>\n  \n  \n  Introducing the Facade\n<\/h2>\n\n<p>We can move that coordination into a dedicated class:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight ruby\"><code><span class=\"k\">class<\/span> <span class=\"nc\">SubscriptionActivation<\/span>\n  <span class=\"k\">def<\/span> <span class=\"nf\">initialize<\/span><span class=\"p\">(<\/span>\n    <span class=\"ss\">payment_processor: <\/span><span class=\"no\">PaymentProcessor<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span><span class=\"p\">,<\/span>\n    <span class=\"ss\">subscription_activator: <\/span><span class=\"no\">SubscriptionActivator<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span><span class=\"p\">,<\/span>\n    <span class=\"ss\">feature_provisioner: <\/span><span class=\"no\">FeatureProvisioner<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span>\n  <span class=\"p\">)<\/span>\n    <span class=\"vi\">@payment_processor<\/span> <span class=\"o\">=<\/span> <span class=\"n\">payment_processor<\/span>\n    <span class=\"vi\">@subscription_activator<\/span> <span class=\"o\">=<\/span> <span class=\"n\">subscription_activator<\/span>\n    <span class=\"vi\">@feature_provisioner<\/span> <span class=\"o\">=<\/span> <span class=\"n\">feature_provisioner<\/span>\n  <span class=\"k\">end<\/span>\n\n  <span class=\"k\">def<\/span> <span class=\"nf\">call<\/span><span class=\"p\">(<\/span><span class=\"n\">user<\/span><span class=\"p\">:,<\/span> <span class=\"n\">plan<\/span><span class=\"p\">:,<\/span> <span class=\"n\">idempotency_key<\/span><span class=\"p\">:)<\/span>\n    <span class=\"n\">payment<\/span> <span class=\"o\">=<\/span> <span class=\"vi\">@payment_processor<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">user: <\/span><span class=\"n\">user<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">plan: <\/span><span class=\"n\">plan<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">idempotency_key: <\/span><span class=\"n\">idempotency_key<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"k\">return<\/span> <span class=\"no\">ActivationResult<\/span><span class=\"p\">.<\/span><span class=\"nf\">failure<\/span><span class=\"p\">(<\/span><span class=\"ss\">:payment_failed<\/span><span class=\"p\">)<\/span> <span class=\"k\">unless<\/span>\n      <span class=\"n\">payment<\/span><span class=\"p\">.<\/span><span class=\"nf\">succeeded?<\/span>\n\n    <span class=\"n\">subscription<\/span> <span class=\"o\">=<\/span> <span class=\"vi\">@subscription_activator<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">user: <\/span><span class=\"n\">user<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">plan: <\/span><span class=\"n\">plan<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">payment: <\/span><span class=\"n\">payment<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"vi\">@feature_provisioner<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span><span class=\"n\">subscription<\/span><span class=\"p\">)<\/span>\n\n    <span class=\"no\">ActivationResult<\/span><span class=\"p\">.<\/span><span class=\"nf\">success<\/span><span class=\"p\">(<\/span><span class=\"n\">subscription<\/span><span class=\"p\">)<\/span>\n  <span class=\"k\">end<\/span>\n<span class=\"k\">end<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The Facade coordinates the workflow without implementing every operation itself. Payment processing, subscription activation, and feature provisioning remain separate responsibilities.<\/p>\n\n<p>Dependency injection also makes testing easier because each collaborator can be replaced with a test double.<\/p>\n\n<p>The controller now has a simpler job:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight ruby\"><code><span class=\"k\">class<\/span> <span class=\"nc\">SubscriptionsController<\/span> <span class=\"o\">&lt;<\/span> <span class=\"no\">ApplicationController<\/span>\n  <span class=\"k\">def<\/span> <span class=\"nf\">create<\/span>\n    <span class=\"n\">plan<\/span> <span class=\"o\">=<\/span> <span class=\"no\">Plan<\/span><span class=\"p\">.<\/span><span class=\"nf\">find<\/span><span class=\"p\">(<\/span><span class=\"n\">params<\/span><span class=\"p\">[<\/span><span class=\"ss\">:plan_id<\/span><span class=\"p\">])<\/span>\n\n    <span class=\"n\">result<\/span> <span class=\"o\">=<\/span> <span class=\"no\">SubscriptionActivation<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">user: <\/span><span class=\"n\">current_user<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">plan: <\/span><span class=\"n\">plan<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">idempotency_key: <\/span><span class=\"n\">checkout_attempt<\/span><span class=\"p\">.<\/span><span class=\"nf\">idempotency_key<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"k\">if<\/span> <span class=\"n\">result<\/span><span class=\"p\">.<\/span><span class=\"nf\">success?<\/span>\n      <span class=\"n\">redirect_to<\/span> <span class=\"n\">subscription_path<\/span><span class=\"p\">(<\/span><span class=\"n\">result<\/span><span class=\"p\">.<\/span><span class=\"nf\">subscription<\/span><span class=\"p\">)<\/span>\n    <span class=\"k\">else<\/span>\n      <span class=\"n\">redirect_to<\/span> <span class=\"n\">plans_path<\/span><span class=\"p\">,<\/span> <span class=\"ss\">alert: <\/span><span class=\"s2\">\"Unable to activate subscription\"<\/span>\n    <span class=\"k\">end<\/span>\n  <span class=\"k\">end<\/span>\n<span class=\"k\">end<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Here, <code>checkout_attempt<\/code> represents a persisted checkout attempt whose idempotency key is reused on retries. The result objects and supporting services are application-specific, not built-in Rails classes.<\/p>\n\n<h2>\n  \n  \n  The Detail That Matters: Failure Handling\n<\/h2>\n\n<p>A Facade organizes a workflow, but it doesn't automatically make that workflow reliable.<\/p>\n\n<p>Imagine the payment provider confirms a charge, but the database update fails. A database rollback cannot undo a charge made by an external service.<\/p>\n\n<p>Retries create another risk. If a customer submits checkout twice, the application must avoid charging them twice for the same attempt.<\/p>\n\n<p>Use a stable idempotency key for payment requests. Stripe documents how <a href=\"https:\/\/docs.stripe.com\/api\/idempotent_requests\" rel=\"noopener noreferrer\">idempotent requests<\/a> help prevent duplicate operations when requests are retried.<\/p>\n\n<p>External side effects also need careful handling. If feature provisioning happens through another service, a failed request may require a retry or reconciliation process. For workflows where losing an event is unacceptable, a transactional outbox can help ensure that database changes and the corresponding event are recorded together.<\/p>\n\n<p>These mechanisms solve different problems. The Facade coordinates the steps; idempotency and reliable event delivery protect the workflow when things go wrong.<\/p>\n\n<h2>\n  \n  \n  Testing the Workflow\n<\/h2>\n\n<p>A useful Facade test verifies the order and conditions of the operations, rather than testing the internals of every collaborator again.<\/p>\n\n<p>For example, a declined payment should prevent subscription activation:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight ruby\"><code><span class=\"no\">RSpec<\/span><span class=\"p\">.<\/span><span class=\"nf\">describe<\/span> <span class=\"no\">SubscriptionActivation<\/span> <span class=\"k\">do<\/span>\n  <span class=\"n\">it<\/span> <span class=\"s2\">\"does not activate a subscription after payment fails\"<\/span> <span class=\"k\">do<\/span>\n    <span class=\"n\">payment_processor<\/span> <span class=\"o\">=<\/span> <span class=\"n\">instance_double<\/span><span class=\"p\">(<\/span><span class=\"no\">PaymentProcessor<\/span><span class=\"p\">)<\/span>\n    <span class=\"n\">activator<\/span> <span class=\"o\">=<\/span> <span class=\"n\">instance_double<\/span><span class=\"p\">(<\/span><span class=\"no\">SubscriptionActivator<\/span><span class=\"p\">)<\/span>\n    <span class=\"n\">provisioner<\/span> <span class=\"o\">=<\/span> <span class=\"n\">instance_double<\/span><span class=\"p\">(<\/span><span class=\"no\">FeatureProvisioner<\/span><span class=\"p\">)<\/span>\n\n    <span class=\"n\">allow<\/span><span class=\"p\">(<\/span><span class=\"n\">payment_processor<\/span><span class=\"p\">)<\/span>\n      <span class=\"p\">.<\/span><span class=\"nf\">to<\/span> <span class=\"n\">receive<\/span><span class=\"p\">(<\/span><span class=\"ss\">:call<\/span><span class=\"p\">)<\/span>\n      <span class=\"p\">.<\/span><span class=\"nf\">and_return<\/span><span class=\"p\">(<\/span>\n        <span class=\"n\">instance_double<\/span><span class=\"p\">(<\/span>\n          <span class=\"no\">PaymentResult<\/span><span class=\"p\">,<\/span>\n          <span class=\"ss\">succeeded?: <\/span><span class=\"kp\">false<\/span>\n        <span class=\"p\">)<\/span>\n      <span class=\"p\">)<\/span>\n\n    <span class=\"n\">facade<\/span> <span class=\"o\">=<\/span> <span class=\"n\">described_class<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">payment_processor: <\/span><span class=\"n\">payment_processor<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">subscription_activator: <\/span><span class=\"n\">activator<\/span><span class=\"p\">,<\/span>\n      <span class=\"ss\">feature_provisioner: <\/span><span class=\"n\">provisioner<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"n\">facade<\/span><span class=\"p\">.<\/span><span class=\"nf\">call<\/span><span class=\"p\">(<\/span>\n      <span class=\"ss\">user: <\/span><span class=\"n\">build_stubbed<\/span><span class=\"p\">(<\/span><span class=\"ss\">:user<\/span><span class=\"p\">),<\/span>\n      <span class=\"ss\">plan: <\/span><span class=\"n\">build_stubbed<\/span><span class=\"p\">(<\/span><span class=\"ss\">:plan<\/span><span class=\"p\">),<\/span>\n      <span class=\"ss\">idempotency_key: <\/span><span class=\"s2\">\"checkout_123\"<\/span>\n    <span class=\"p\">)<\/span>\n\n    <span class=\"n\">expect<\/span><span class=\"p\">(<\/span><span class=\"n\">activator<\/span><span class=\"p\">).<\/span><span class=\"nf\">not_to<\/span> <span class=\"n\">have_received<\/span><span class=\"p\">(<\/span><span class=\"ss\">:call<\/span><span class=\"p\">)<\/span>\n    <span class=\"n\">expect<\/span><span class=\"p\">(<\/span><span class=\"n\">provisioner<\/span><span class=\"p\">).<\/span><span class=\"nf\">not_to<\/span> <span class=\"n\">have_received<\/span><span class=\"p\">(<\/span><span class=\"ss\">:call<\/span><span class=\"p\">)<\/span>\n  <span class=\"k\">end<\/span>\n<span class=\"k\">end<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>This example assumes the application's result objects and test factories are defined accordingly.<\/p>\n\n<h2>\n  \n  \n  When Should You Use a Facade?\n<\/h2>\n\n<p>A Facade is useful when a single business operation requires several components to work together and callers shouldn't need to know the sequence.<\/p>\n\n<p>It isn't necessary for every controller action. If an operation is simple, adding another class can create unnecessary indirection. And if the Facade starts implementing every business rule itself, it may simply become another oversized object.<\/p>\n\n<p>Keep the distinction clear:<\/p>\n\n<ul>\n<li>\n<strong>Controller:<\/strong> handles the HTTP request and response.<\/li>\n<li>\n<strong>Facade:<\/strong> coordinates the workflow.<\/li>\n<li>\n<strong>Collaborating services:<\/strong> implement their own responsibilities.<\/li>\n<\/ul>\n\n<p>The goal isn't to create more classes. It's to make a complicated operation easier to understand, test, and change without spreading its coordination logic throughout the application.<\/p>\n\n","category":["rails","architecture","refactoring","facadepattern"]},{"title":"AI Should Propose. Systems Should Verify.","pubDate":"Wed, 07 Oct 2026 05:44:22 +0000","link":"https:\/\/dev.to\/sinarezaei\/ai-should-propose-systems-should-verify-13f7","guid":"https:\/\/dev.to\/sinarezaei\/ai-should-propose-systems-should-verify-13f7","description":"<h1>\n  \n  \n  AI Should Propose. Systems Should Verify.\n<\/h1>\n\n<p>An AI agent can produce the correct action and still have no authority to execute it.<\/p>\n\n<p>That distinction becomes critical when agents move beyond generating text and start modifying code, calling APIs, changing infrastructure, triggering workflows, or coordinating other agents.<\/p>\n\n<p>The question is no longer only:<\/p>\n\n<blockquote>\n<p>Can the model determine what should happen?<\/p>\n<\/blockquote>\n\n<p>It is also:<\/p>\n\n<blockquote>\n<p>What happens between the action the model proposes and the action the system actually executes?<\/p>\n<\/blockquote>\n\n<p>A useful starting point is:<\/p>\n\n<p><strong>AI proposes. Systems verify. Infrastructure executes.<\/strong><\/p>\n\n<h2>\n  \n  \n  The Problem With Direct Execution\n<\/h2>\n\n<p>Consider an AI coding agent working inside a production environment.<\/p>\n\n<p>The agent receives a task:<\/p>\n\n<blockquote>\n<p>Fix the authentication bug and deploy the change.<\/p>\n<\/blockquote>\n\n<p>It analyzes the repository, modifies the code, runs tests, and produces a deployment command.<\/p>\n\n<p>The code may be correct.<\/p>\n\n<p>The tests may pass.<\/p>\n\n<p>The deployment command may be valid.<\/p>\n\n<p>None of those facts automatically mean the agent should be allowed to deploy to production.<\/p>\n\n<p>This is the difference between <strong>correctness and authority<\/strong>.<\/p>\n\n<p>A model can correctly determine what should happen while still being unauthorized to perform that action.<\/p>\n\n<p>If the same component controls reasoning, authorization, and execution, the trust boundary becomes extremely large:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>AI decides what to do \u2192 AI decides whether it may do it \u2192 AI executes it\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>A safer architecture separates those responsibilities.<\/p>\n\n<h2>\n  \n  \n  Put a Boundary Between Reasoning and Execution\n<\/h2>\n\n<p>Instead of allowing the model to directly invoke sensitive infrastructure, treat its output as a <strong>proposed action<\/strong>.<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>User Intent\n    \u2193\nAI Agent\n    \u2193\nProposed Action\n    \u2193\nSystem Validation\n    \u2193\nPolicy Check\n    \u2193\nExecution\n    \u2193\nPost-Execution Verification\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The model produces the request.<\/p>\n\n<p>The surrounding system evaluates it.<\/p>\n\n<p>The infrastructure executes it only after the required controls have been satisfied.<\/p>\n\n<p>For example:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight json\"><code><span class=\"p\">{<\/span>\n  <span class=\"nl\">\"action\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"deploy\"<\/span><span class=\"p\">,<\/span>\n  <span class=\"nl\">\"environment\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"production\"<\/span><span class=\"p\">,<\/span>\n  <span class=\"nl\">\"service\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"auth-service\"<\/span><span class=\"p\">,<\/span>\n  <span class=\"nl\">\"version\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"2026.10.04\"<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The control layer can independently check whether the request is structurally valid, whether the target exists, whether the requested operation is permitted, and whether additional controls are required.<\/p>\n\n<p>The model does not need to make those decisions itself.<\/p>\n\n<h2>\n  \n  \n  Passing Tests Does Not Mean Permission\n<\/h2>\n\n<p>Imagine the coding agent changes a payment service.<\/p>\n\n<p>The tests pass.<\/p>\n\n<p>The security checks pass.<\/p>\n\n<p>The build succeeds.<\/p>\n\n<p>The artifact is signed.<\/p>\n\n<p>The model now proposes:<\/p>\n\n<blockquote>\n<p>Deploy to production.<\/p>\n<\/blockquote>\n\n<p>The previous results establish that the software may be technically acceptable.<\/p>\n\n<p>They do not establish that the current actor is authorized to deploy it.<\/p>\n\n<p>That gives us an important separation:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Validation \u2192 Is this action acceptable as an operation?\n\nAuthorization \u2192 Is this actor allowed to perform it?\n\nExecution \u2192 Perform the approved operation.\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>These questions belong to different layers.<\/p>\n\n<p>That separation also makes the architecture easier to audit and change without changing the model's reasoning process.<\/p>\n\n<h2>\n  \n  \n  Powerful Agents Do Not Need Unrestricted Authority\n<\/h2>\n\n<p>Separating reasoning from execution does not require making the agent weak.<\/p>\n\n<p>An engineering agent can still have broad capabilities:<\/p>\n\n<ul>\n<li>inspect repositories<\/li>\n<li>create branches<\/li>\n<li>modify files<\/li>\n<li>run tests<\/li>\n<li>inspect logs<\/li>\n<li>generate deployment plans<\/li>\n<li>propose infrastructure changes<\/li>\n<\/ul>\n\n<p>The system can simply apply stronger controls to higher-impact operations such as:<\/p>\n\n<ul>\n<li>production deployment<\/li>\n<li>credential rotation<\/li>\n<li>database migration<\/li>\n<li>destructive infrastructure changes<\/li>\n<li>financial transactions<\/li>\n<\/ul>\n\n<p>The agent remains capable of reasoning about complex operations.<\/p>\n\n<p>Its capabilities just do not automatically become unrestricted authority.<\/p>\n\n<h2>\n  \n  \n  Think in Actions, Not Just Tools\n<\/h2>\n\n<p>Another architectural mistake is defining control only around tool access.<\/p>\n\n<p>For example:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Agent \u2192 deploy_tool\nAgent \u2192 payment_api\nAgent \u2192 database_api\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Tool access is often too coarse.<\/p>\n\n<p>The more useful question is:<\/p>\n\n<blockquote>\n<p>What action is the agent attempting to perform, against which resource, under which constraints?<\/p>\n<\/blockquote>\n\n<p>A control layer can therefore reason about something closer to:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Actor \u2192 Action \u2192 Resource \u2192 Environment \u2192 Scope \u2192 Context \u2192 Policy\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Now the system can distinguish between actions that happen to use the same underlying tool.<\/p>\n\n<p>A deployment API, for example, might be capable of deploying to both staging and production. Access to the API alone does not tell us whether a particular production deployment should be allowed.<\/p>\n\n<p>The meaningful unit of control is the <strong>action and its context<\/strong>, not simply the existence of a tool.<\/p>\n\n<h2>\n  \n  \n  When Agents Start Delegating\n<\/h2>\n\n<p>The boundary becomes even more important when one agent delegates work to another.<\/p>\n\n<p>Consider:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>User \u2192 Orchestrator Agent \u2192 Procurement Agent \u2192 Payment Service\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The procurement agent may determine that a purchase is necessary.<\/p>\n\n<p>But the fact that the orchestrator requested the purchase does not automatically give the procurement agent unlimited spending authority.<\/p>\n\n<p>Now the system needs to understand more than the requested action:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Initiator \u2192 Delegator \u2192 Acting Agent \u2192 Action \u2192 Resource \u2192 Scope\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>This introduces a deeper authorization problem: <strong>how authority is delegated between actors<\/strong>.<\/p>\n\n<p>That problem deserves its own layer rather than being squeezed into the basic execution model.<\/p>\n\n<h2>\n  \n  \n  A Better Mental Model\n<\/h2>\n\n<p>Instead of:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>User \u2192 AI \u2192 Everything\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>think about:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>User \u2192 Intent \u2192 AI Agent \u2192 Proposed Action \u2192 System Controls \u2192 Infrastructure\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>The AI sits inside the system.<\/p>\n\n<p>It does not become the system.<\/p>\n\n<p>That gives the architecture a stable control boundary around a component whose behavior is probabilistic.<\/p>\n\n<p>The model can change.<\/p>\n\n<p>The model can be upgraded.<\/p>\n\n<p>The model can be replaced.<\/p>\n\n<p>The surrounding execution controls can remain.<\/p>\n\n<h2>\n  \n  \n  The Principle\n<\/h2>\n\n<p>Giving an AI agent more tools does not automatically mean giving it more authority.<\/p>\n\n<p>The goal is not to prevent AI from acting.<\/p>\n\n<p>The goal is to separate <strong>the ability to propose an action<\/strong> from <strong>the authority to execute it<\/strong>.<\/p>\n\n<p><strong>AI proposes. Systems verify. Infrastructure executes.<\/strong><\/p>\n\n<p>And once agents start acting on behalf of other agents, the next question becomes unavoidable:<\/p>\n\n<p><strong>Who actually has the authority to perform the action?<\/strong><\/p>\n\n","category":["ai","security","devops","architecture"]}]}}