Faith Forge LabsPeru

Why an unchanged reference passed once and failed next

A staff member enters a reference, sees it accepted and then sees the same value rejected on another validation pass. Reformatting the reference may appear to help, but the evidence does not yet show that its characters are wrong.

This fictional repair concerns an internal application with an owner-approved test format: REF- followed by exactly two ASCII digits. REF-41 is a synthetic internal fixture, not a proposed format for an official Peruvian reference. The example isolates an application defect without creating a universal validation rule for outside systems.

Repeat the input without changing it

The reviewer invokes the same validation function three times with the exact string REF-41. The results are true, false and true. The stored bytes and the visible field do not change between calls.

Another valid fixture, REF-52, shows the same alternating behaviour when tested from the same clean starting state. That pattern points away from a particular spelling error. Trimming spaces or replacing a hyphen cannot explain why unchanged input changes its result.

Inspection finds one shared regular-expression object created as /^REF-[0-9]{2}$/g. Its pattern represents the intended fictional format, but the global flag introduces state through lastIndex. The application reuses that object for independent validation checks.

Inspect the state that survives the first check

The first successful match advances the object’s lastIndex to the end of REF-41. The next test begins from that retained position. Because the pattern is anchored to the beginning, it cannot match the same complete string from that later position; the failed global search resets lastIndex. The following call starts from zero and succeeds again.

The ECMAScript matching algorithm defines this interaction between global or sticky matching and lastIndex. It is useful when searching repeatedly through a string. It is an inappropriate dependency for this application’s independent whole-value checks.

The reviewer records both the Boolean result and lastIndex at each step. The problem is no longer described as a mysterious intermittent rejection. The validator carries search state from an earlier call into a decision that should depend only on the current input.

Restore the intended rule

The developer replaces the shared global search with /^REF-[0-9]{2}$/, without global, sticky or multiline flags. Each validation checks the whole supplied value under the same rule. No input character is silently rewritten.

The repair is narrow. It does not change which official reference types the wider application supports, invent a missing reference or claim that format conformity establishes a record’s existence. A separate authorised lookup or source review still provides that evidence where required.

The existing application can represent the needed field and return an understandable error. Replacement would not address a different fundamental capability gap in this case; the owner chooses the validator correction and its regression fixture.

Check successful and unsuccessful sequences

Sequence Expected result after correction
REF-41 repeated three times true, true, true
REF-52 after REF-41 true
XREF-41 false: extra prefix
REF-410 false: extra digit
REF-4A false: disallowed character
REF-41 followed by a newline false: extra line terminator
Invalid value followed by REF-41 false, then true

The isolated review produces those results. The last valid check does not depend on whether a previous value succeeded or failed. A separate field’s validation remains unchanged, and the application still shows an associated error for a genuinely invalid reference.

The test also compares the accepted string with the submitted string. REF-41 remains REF-41. There is no hidden normalization that could conceal a different identity. The record’s reference type and source remain as supplied in the approved fixture.

Examine the two places validation may run

A real interface may validate on editing, before submission and again at the receiver. Multiple checks are not inherently the defect; allowing one check to influence another through unintended mutable state is the problem demonstrated here.

The receiving application must enforce its actual input contract independently. A browser-side fix alone does not establish that every receiver or official service accepts the same value. The handover identifies which validator was changed and which downstream rules were merely preserved.

The completed outcome is a stable decision for unchanged input, with invalid controls still rejected. The continuity and repair service uses evidence like this to distinguish a small supported correction from a justified platform replacement.