# native-repair / tracking — result Base commit 28ff85f. I changed only `web/src/native/client.ts`, `web/tests/native-client.test.mjs` and `web/tests/fixtures/native-client/unrelated-revert.json` (new). All exported names and types are unchanged: `readNative` and `NativeSnapshot` keep their shapes. I added no dependency, contract, transfer or signing key, and changed no package or build file. No live payment was made. ## Defects, what happened, what happens now Line numbers marked "was" are from 28ff85f. Line numbers marked "now" are in the changed `web/src/native/client.ts`. 1. **Job id lost while a later step is pending** (was client.ts:203 and :227-232). - Before: `snapshot.jobId` was set only after both `/jobs/` and `/jobs//result` answered. `readCompletion` ran before that, so it could throw first, for example on `awaiting-confirmations` while the completion was under three blocks deep. A paid, admitted order then came back with no job id. - Now: the admission is parsed before the completion is read (now :239-247). Once the matched Intake entry has `order.status === "paid"` and its admission names a valid job, the snapshot keeps `paid`, `payer`, `requestId` and that `jobId`, whatever is still pending. That covers an unconfirmed completion, a missing completion receipt, and a job API 404 or rate limit. - If the job answers with a different `id`, `paidBy` or result `jobId`, the job id is removed again (`delete snapshot.jobId`, now :281) and the reason stays `job-identity-mismatch`. - An unpaid order never gets the job id. - Paid and complete need exactly the same evidence as before. 2. **Confirmed refusal after admission stayed pending** (was client.ts:211-216). - Before: any refusal with `admission.result.kind === "job"` threw `admission-refusal-disagreement`. - Now (:252-267, :288-293): a refusal with an admitted job continues to the job read. It returns `phase: "refused"`, reason `request-refused`, with paid and job id kept, only when all of these hold: - the entry state is `refused`; - the canonical `Completed` log, three blocks deep, has status 1; - the job state and the result state are both `refused`, and the result is not `complete`. - Anything less stays pending with `admission-refusal-disagreement`: a running or failed job, a missing result state, no confirmed completion, a status-2 completion, or an entry still `admitted`. - Refusal without an admitted job behaves as before. 3. **Any reverted transaction read as a failed order** (was client.ts:185). - Now the transaction is first bound to its receipt by the new `readTransaction` (:107-131), which checks hash, block, sender and target. - A reverted transaction returns `failed` / `request-reverted` only when it was sent to the Intake and its calldata decodes as `request` with `JOB_ACTION` and the IMD token (:218-224). - Otherwise it returns `pending`, `paid: false`, reason `not-an-intake-request`. That includes a different target, action or token, and calldata that does not parse. - The real mainnet revert `0x4a94111a874a4b82f8aae04b4ceede15566d28ce167eea6eaec918397f8d039c` (to `0x1111111254…0a65`, selector `0x07ed2379`) is now `not-an-intake-request`. 4. **A request through another contract looked like an order still indexing** (was client.ts:91-98). - Now, when the transaction and receipt agree on a target that is not the Intake (:116-121): - If the successful receipt has any log emitted by the Intake, the result is `unsupported-transaction`, pending and unpaid. - If it never touched the Intake, the result is `not-an-intake-request`, pending and unpaid. Point 4 of the brief does not cover this case; I chose the code. - A transaction and receipt that disagree with each other (hash, block, sender, `to`), or a request with non-zero value, still give `request-transaction-mismatch`. 5. **A transaction with no receipt yet was called `read-unavailable`** (was client.ts:275). - Now `canonicalReceipt` (:70-82) maps a `TransactionReceiptNotFoundError` (matched by name anywhere in the cause chain, so it works across viem bundles) and a null receipt to `awaiting-receipt`. - `read-unavailable` is kept for other failed reads, such as an RPC that throws or a fetch transport error. - This also applies to the completion transaction's receipt. All other reason codes are unchanged. ## Tests (offline) I added 21 tests to `web/tests/native-client.test.mjs`, going from 58 to 79 tests in that file: - **Defect 1:** - The job id is kept under three blocks of depth (`awaiting-confirmations`), with a missing completion receipt (`awaiting-receipt`), and on a job 404 (`awaiting-index`). - No job id is shown before the order is paid. - Three identity-mismatch cases end with no job id. - **Defect 2:** - A confirmed refusal after admission maps to `refused` with the job id. - Six partial refusals stay pending. - **Defect 3:** - The real unrelated mainnet revert, replayed from `tests/fixtures/native-client/unrelated-revert.json`. That file holds the raw JSON-RPC receipt, transaction and block header, fetched once from Ethereum mainnet and formatted with viem's `formatTransactionReceipt` and `formatTransaction`. - Reverts with another action, another token, unparseable calldata or another target. - **Defect 4:** - A request through another contract gives `unsupported-transaction`. - A transaction that never touched the Intake gives `not-an-intake-request`. - **Defect 5:** - `TransactionReceiptNotFoundError` and a null receipt give `awaiting-receipt`. - A thrown RPC error stays `read-unavailable`. **Before and after:** I put the 28ff85f `client.ts` back temporarily with the new test file. - With the old client, 11 of 79 fail, one for every defect test above. - The guard tests pass on both versions, because they assert behaviour that already held: identity mismatch, unpaid order, partial refusal. - With the new client, 79 of 79 pass. No existing assertion stated a defect, so I edited none. The existing `maps confirmed request revert to failed without payment` test still passes unchanged, because its transaction is a real Intake `request`. ## Commands (from `web/`, `TMPDIR` set to `test/scratch/tmp`) | Command | Exit | Result | |---|---|---| | `npm ci` | 0 | installed | | `npx tsc --noEmit` | 0 | no errors | | `node --test tests/native-client.test.mjs` (old client.ts, new tests) | 1 | 79 tests, 68 pass, 11 fail (the new defect tests) | | `node --test tests/native-client.test.mjs` | 0 | 79 tests, 79 pass | | `node --test tests/*.test.mjs` | 1 | 237 tests, 226 pass, **9 fail**, 2 todo | | `node scripts/i18n-check.mjs` | 0 | 605 strings, 9 languages, PASS | **The 9 failures** are `tests/native-i18n.test.mjs:157`, ": every checkout/native customer string has a registered entry with its placeholders", for fr, es, ru, ja, zh, pt, it, th and pcm. The scanner finds the three new reason codes in client.ts and they have no translation entry: - `awaiting-receipt` (`src/native/client.ts:82`, also :77) - `unsupported-transaction` (`src/native/client.ts:120`) - `not-an-intake-request` (`src/native/client.ts:224`) The brief requires these codes, and their entries belong in `web/src/i18n-ui/checkout.ts` (`CHECKOUT_KEYS`, next to `"read-unavailable"` at about line 85), which this item may not touch. The later translation wave needs to add them. Every other test passes. ## New customer-visible English There are no new sentences. The only new visible text is three reason codes, which `web/src/native/view.tsx:187` renders as-is (`

{s.reason}

`): "awaiting-receipt", "unsupported-transaction", "not-an-intake-request". ## Defects seen outside my files - `web/src/i18n-ui/checkout.ts` has no entries for the three new reason codes, which causes the 9 i18n test failures above. - `web/src/native/view.tsx:187` shows the raw reason code to the customer. It is not run through `t()` and has no plain-language wording. ## What stays unproven - Everything was tested offline against mocked viem and fetch. I never ran it against the live Intake, the api.imd.fun index or a real IMD.fun job, and made no payment. - The real-revert fixture shows the classification only. I did not test live RPC behaviour, such as viem's actual error wrapping for a missing receipt. The name-based check covers viem's `TransactionReceiptNotFoundError` directly or as a cause. - `unsupported-transaction` is detected by "the receipt has any Intake log while the target is another contract". Such orders are not followed to a report: they stay pending and unpaid by design. - The live api.imd.fun index may never return the exact refusal-after-admission combination (entry `refused`, Completed status 1, job and result `refused`). The test is built from the brief's description. - How `checkout.tsx`, `view.tsx`, `swarm.ts` and `pages.tsx` use the kept job id belongs to other items and is not checked here.