Task 0492 — root cause investigation: supplier-stock 500 (usa-fed.com)

Investigated November 3, 2026. Read-only. This supersedes the October 22 closure review (task-0492-closure-review.md), which correctly located the endpoint but could not identify the failing branch without a production log line.

Verdict: NOT resolved. The task's assumed root cause was wrong.

All three investigations agree (Coder, POS Production, and this coordinator):

The failure chain (strong temporal association, 2026-11-03T20:24:21-22Z)

Correlation caveat. The storefront request -> purchasing request -> product-database request link for any one specific failure is not proven by request id. Searching purchasing logs for three sampled storefront Job UUIDs (including the latest) returned no matches, because purchasing replaces the storefront's short middleware id with a new UUID. What is proven is the conjunction below: the storefront logs the 500 with body failed to get products, purchasing logs a failed to get products failure against /products/get/id in the same second, product-database-next logs the decimal-id ObjectID parse failures plus (BadValue) $in needs an array in that same second, and the deployed binary emits the products.go:402 warning text verbatim. Treat the chain as a strong temporal association, not as a proven end-to-end request identity.

  1. Storefront (usa-fed-webstore) calls purchasing-service GET /api/vendor-stock and logs at 20:24:22Z, pod usa-fed-webstore-deployment-59bf985bb7-lmxlx, Job aea0192f-a388-4c89-803a-62c2de18ead8, loggerID 9c54bda3-483e-4ba5-a136-943cc1fa01e7: Errors getting fulfillment options for products: [error getting supplier stock: failed to get supplier stock: 500 Internal Server Error, failed to get products\n] Logged upstream status: 500. Logged response body: failed to get products\n.
  2. Purchasing-service pod purchasing-service-deployment-9c5cf8674-fn8hf logs at 20:24:21Z, request prz4oi6uxr88dch2, regenerated Job 068b91fb-f456-43d5-b7fa-7303cb8c2c82: failed to get products: failed to get product from http://product-database-next-service.next-erp/products/get/id: 500, Internal Server Error\n — and GET /api/vendor-stock finished with error. This is a product-loading failure, not a vendorStocks Mongo decode or response-encoding failure.
  3. product-database-next pod product-database-next-deployment-5b94fb795-lf89m logs, same second, Job 3f33f226-df52-4a09-b69f-a800bea4119e: server error: (BadValue) $in needs an array — preceded by one warning per product id: error parsing ID <id> to primitive: the provided hex string is not a valid ObjectID, skipping
  4. 20 distinct legacy decimal POS product ids failed parsing in that single request: 112109, 112131, 215793, 265558, 266328, 500615, 503467, 507524, 519647, 523695, 554406, 554417, 563558, 564557, 585190, 585714, 588573, 588584, 604688, 607510.

Root cause: two defects, the first one primary

(1) PRIMARY — identity-namespace mismatch (caller/integration)

The storefront sends POS stock numbers; product-database-next only accepts 24-character hex Mongo ObjectIDs. The ids are never translated on the way.

Deployed source path (POS Production verified against the running commits):

So valid POS-native ids enter an ObjectID-only lookup unconverted.

These are not all Atosa products. Live stockusaf rows exist for the failing ids, and they span multiple vendors:

stock number vendor item
112109 ATNI glass rimmer
215793 ATNI baguette pan
523695 TLDD glass mug
604688 BAZA hand soap

That independently rules out a vendor-specific (ATO/ATOS) explanation for the 500.

(2) SECONDARY — nil-array handling (turns it into a 500)

next-erp → product_database/src/internal/database/products.go:391-408 (GetManyProductsByIDs):

var filteredList bson.A                       // nil slice
for _, id := range ids {
    if id == "" { continue }
    objectID, err := primitive.ObjectIDFromHex(id)
    if err != nil {
        conn.log.Warnf(jobID, "error parsing ID %v to primitive: %v, skipping\n", id, err)
        continue
    }
    filteredList = append(filteredList, objectID)
}
filter := bson.D{{Key: "_id", Value: bson.D{{Key: "$in", Value: filteredList}}}}

Because every POS stock number fails primitive.ObjectIDFromHex, nothing survives the filter and filteredList stays a nil bson.A. $in then marshals as null rather than [], and Mongo rejects it: (BadValue) $in needs an array → HTTP 500. Initialising it as bson.A{} or short-circuiting to an empty result set would avoid the invalid query.

Fixing the nil array alone will not establish correct stock availability. It would turn the 500 into an empty/200 response while the ids are still wrong. Both defects need addressing, and the decision of which side owns the translation (purchasing should send ObjectIDs, or product-database-next should accept POS stock numbers and translate them) belongs to the implementer.

Route registered at product_database/src/main.go:342 (/products/get/id).

Authoritative source confirmation (fetched remotes, not working trees)

Verified directly against next-erp remotes:

Ref Commit products.go Same defect?
origin/main 4b19f41d0e551a1ed83d385a795e793c8c9a6563 GetManyProductsByIDs at :391; var filteredList bson.A :396; warning text :403; $in build :408 YES
origin/store_service-staging 5273eadf0e3c3dcf31c3bb43257beef0be22a8b5 same defect at :396 / :403 YES

git show origin/main:product_database/src/main.go confirms the route /products/get/id at :342. The last commits touching products.go on main are unrelated (admin specification persistence, manufacturer/supplier filtering, product asset deletion, pagination, supplier-name lookup) — nothing addresses the nil-slice / $in: null path.

Note: next-erp has no refs/heads/staging; the purchasing pipeline uses main. The real checkout is ~/sites/next-erp (~/sites/review-next-erp is a different, older tree at 5a2fd015).

Regression-test home: product_database/src/internal/database/products_test.go already has TestGetManyProductsByIDs at :1501 (call at :1975) — that is where a regression case for the all-ids-invalid path belongs.

Deployment proof: the running binary emits the warning text verbatim as error parsing ID %v to primitive: %v, skipping, character-for-character the format string at products.go:403, with the same primitive.ObjectIDFromHex error text the provided hex string is not a valid ObjectID. That matches the deployed code path, independent of image tags.

Frequency — the failure is live and continuous

A 30-day exact-phrase Loki search returned 2,199 matching lines (limit 5,000, not truncated); earliest returned day October 19. No claim is made about retention or completeness before that date. Counts are failure-log frequency, not an error rate — no traffic denominator was collected.

Deduplicated by Job within each UTC day (warning and error lines can describe the same failure):

UTC date lines unique Jobs UTC date lines unique Jobs
2026-10-19 3 3 2026-10-28 34 19
2026-10-20 87 56 2026-10-29 223 126
2026-10-21 33 24 2026-10-30 196 102
2026-10-22 138 132 2026-10-31 41 23
2026-10-23 61 53 2026-11-01 112 64
2026-10-24 52 28 2026-11-02 319 171
2026-10-25 4 2 2026-11-03 99 53
2026-10-26 748 411
2026-10-27 49 35

November 3 is partial, through approximately 20:35Z. The first occurrence in the window (2026-10-19) is three days before this task was opened, and it has never stopped.

Coder's source findings (next-erp / new-webstore / pos, fresh remote fetches)

Refs inspected: new-webstore/staging a3b91c9cff8e68f9567df0fa6fcf9112028200af and main 38059314cb867eb4303fe283fa3b1c7516614c4d; next-erp store_service-staging 5273eadf0e3c3dcf31c3bb43257beef0be22a8b5 and main 4b19f41d0e551a1ed83d385a795e793c8c9a6563; pos/staging 8c0c233aabcd75976ad2f848b7bf86b358065e53.

The 84ff596f change was never integrated at all

84ff596faac9ad22d4e41117e08bbb3cb58a2bc6 is not an ancestor of storefront staging or main. git branch -a --contains locates it only on the local codex/usa-fed-catalog-paging branch. At that commit, backend/repositories/storerepo/vendor_products.go:38-45 validates an optional positive filter.VendorID and replaces vendorCode with vendorId for catalog selection. Current staging's same file :37-44 still sends vendorCode, and backend/domain/store/vendor_products.go:13-16 has no VendorID field — main lacks it too. This is not an ancestry discrepancy with equivalent code already integrated; the feature was never merged.

Nearby staging commits are not supplier-stock fixes: 5224cd7c3746 (batch catalog pricing), eb047cca08e9 (unified dealer checkout/orders), e171dba7ea81 (list-price fallback), 428b11dd3014 (dealer eligibility / credit-limit diagnostics). No staging commit changes suprepo, domain/supplier, or fulfillment_service.go relative to 84ff596f. The entire supplier HTTP adapter is byte-identical at 84ff596f, staging, and main.

POS-side commits 86ca9be61e5f (numeric vendor-ID support), aea3954ae045 (vendor-master fallback), e765bdc6c39f / 3d19227aaa94 (AQ catalog, dealer purchasing) are likewise not ATO→ATOS aliasing or a purchasing Mongo-stock fix.

Purchasing controller and stock repo are byte-identical at d9345c63, main, and store_service-staging: purchasing_service/controllers/vendor_controller.go blob 3f99214eceebf2e23a4a71e88cb7c972e541c169; purchasing_service/repositories/stock/mongo_vendor_stock_repo.go blob b579df4dfbe788dd6a506b4042a606982b89c8f0.

Exact 500 / non-500 paths (purchasing vendor_controller.go:155-203)

Condition Response
empty / missing vendorId 400 vendorId is required (:159-163)
no productId query entries 400 at least one productId is required (:167-171)
productService.GetProducts error 500 failed to get products (:175-179)
successful but empty product list 404 no products found (:182-185)
vendor stock repo error 500 failed to get vendor stock (:189-193)
JSON encode error attempted 500 failed to encode response (:197-201) — if a 200 was already committed it cannot retroactively become 500

Storefront side: backend/domain/store/fulfillment_service.go:738-766 calls GetSupplierStock(SourceId, products, jobId) per configured source; any source error propagates. backend/repositories/suprepo/erp_supplier_repo.go:49-77 sends GET /api/vendor-stock with vendorId=<configured source string> and a repeated productId=<global product ID>, and turns any non-200 into failed to get supplier stock: <status>, <body> (:68-71). Transport, request-construction, and invalid-JSON-on-200 errors return separately (:57-65, :74-77).

Important nuance: a purchasing 500 does not prove a browser product-page 500. Storefront products_controller.go:306-320 logs fulfillment errors, clears the fulfillment options, and continues encoding details — so the user-facing symptom is a missing-availability product page, not a 500 page.

Product-service layer purchasing_service/services/product/erp_product_service.go:41-78 POSTs /products/get/id; construction/transport/read/decode failures and any non-2xx product-database status become an error → purchasing 500, including an upstream product-database 404. A successful empty list instead gives purchasing 404.

Mongo vendor-stock repo (mongo_vendor_stock_repo.go): :31-45 constructor rejects empty collection/db/ProductSourceConfigs or nil dependencies — startup/setup failures, not ordinary per-request 500s. :155-165 empty product list / runtime-empty config errors can become 500. :167-185 a missing supported SKU is skipped; if all products lack one it returns nil, nil → 200/null, not 500. :194-212 a map-cardinality guard can fail if the product service returns duplicate product ids → 500 — possible in code, not established as this incident's cause. :266-290 client/query failure (5-second context; auth, selection, connectivity, timeout) → 500. :295-297 decode/iteration error → 500. :281-284 the exact Mongo filter is productId $in plus an exact-string vendorId. :299-315 missing records are synthesized empty stock, not errors. GET uses the singular getMongoSupplierStock (:266), not the plural batch helper (:218) used by upserts.

Wrong-ID hardening verdict (no hardening found)

So neither "wrong id definitely caused the 500" nor "optional vendor_id fixed it" is supported. Wrong ids can hide availability behind a 200.

Mapping and spelling

Deployment proof (production)

Verified two ways — Prometheus kube_pod_container_info (~20:38Z) and the Portainer Kubernetes API directly. Both current deployments specify the same image, and GET pods confirms 2 Ready/Running app containers each:

Deployment Generation Image Digest
usa-fed-webstore-deployment gen185 registry.ddst.dev:443/webstore:527d5a4f296c88f13eb1306c1aea7d1f5dc8c0bc sha256:ad44fbe3741de5123b9d7f81575151497fae6844a9ac020aa2a406942dbff375
webstore-deployment gen244 same same

527d5a4f... is the November 3 19:06:51Z merge of codex/aq-catalog-profile-headers (PR #259). It is not the old task reference 84ff596f, and the July c2c34f2b... image in the local context file is stale. The deployed-commit source wires vendor programs through NewPOS, not the legacy Mongo repository, and contains no vendor_id/VendorID/VendorId reference in domain/vendorpricing; the deployed vendor-products code sends vendorCode, not the optional vendorId branch from 84ff596f.

Purchasing deployment tag is 0396eee26332a98be8e2209461725627a71c9ae0; that exact commit was inspected for the id-forwarding behaviour described above.

Access note for future runs: portainer.ddst.dev does not resolve from Phil-Z-Standard (Windows or WSL). It is reachable from the SSH fallback host with DNS resolved there and --resolve preserving TLS.

Identity nuance on the ATO/ATOS answer

295889 is the established POS identity for ATOS (vendor_cd ATOS, assigned_no 295889, id 5965), not a configured optional vendor_id — no such field exists in the deployed program document or in the deployed domain/vendorpricing. Do not label it as one.

Remaining mapping evidence gap

The storefront's InitVendorPrograms is wired through StoreService.Config.Shared.BaseURL = http://store-service.next-erp, not directly through POSCatalog.API. Live store-service-config has PosApiClient.Host = https://staging.esreco.net, and the storefront's POSCatalog API points there as well. The public storefront program GET returns 401. Production POS/program records agree on ATOS, but the authenticated runtime program response via its staging-host gateway has not been obtained, so full effective storefront agreement cannot be claimed. This is the remaining mapping evidence gap — not an ATO discrepancy found in production.

The running image tag for product-database-next itself is still unknown — only the storefront deployments were confirmed.

Live storefront startup config (current failing pod, 19:09:09Z)

AppBaseUrl                      = https://www.usa-fed.com
SupplierService.Type            = ErpSupplierRepository
SupplierService.Config.BaseURL  = http://purchasing-service.next-erp
SupplierSKUSources.SourceId     = "22644"
VendorPricing.Enabled           = true
VendorPricing.StoreID           = 6a30669e430d9db8df61cacf
POSCatalog.API.BaseURL          = https://staging.esreco.net
POSCatalog LocationCd / DealerCommerce catalog scope = USAF

Two open questions from this: the live storefront's POSCatalog API points at staging.esreco.net, not production (intentional or misconfiguration?); and SupplierSKUSources.SourceId = 22644 is a purchasing supplier identity that must not be equated with the Atosa POS identity 295889.

ATO vs ATOS — the production answer

Read-only replica selects at 2026-11-03 13:36-13:38 MST, default_transaction_read_only=on, pg_is_in_recovery()=true:

Conclusion: ATOS is the production POS identity. ATO is not supported by any live production record — most likely a storefront display/config value or a fixture. The purchasing SourceId 22644 is a separate identity space and must not be equated with Atosa POS assigned_no 295889.

Limit on that conclusion: the storefront's effective Atosa program payload and any optional nested catalog vendor_id were not read from its authenticated API — public GET /api/vendor-programs returns 401 AUTHENTICATION_REQUIRED — and the live POSCatalog target is staging.esreco.net. The production replica program record alone does not prove which program payload the live storefront currently receives. No claim of full storefront-to-POS mapping agreement or divergence is justified yet.

Secondary observation (not the cause)

Purchasing-service logs, on every vendor-stock call at severity error: Invalid job ID: <16-char base62 id>, making new one: <uuid>. The storefront's own Job UUID and purchasing's regenerated UUID are different namespaces — purchasing regenerates the short middleware id. This is self-healing and is not the cause of the 500.

Still open (not required for the root-cause verdict)

  1. Exact cross-service request correlation — a request id, URL, or query capture that preserves product ids and job ids across storefront -> purchasing -> product-database. Not achievable today because purchasing regenerates the job id.
  2. Authenticated read of the storefront's current Atosa program/catalog payload — public GET /api/vendor-programs returns 401 AUTHENTICATION_REQUIRED; this is needed to check the optional nested vendor_id and to confirm whether the staging.esreco.net POSCatalog target is intentional.
  3. A verified successful read of an affected product page with correct vendor and availability. No original affected URL/SKU was supplied. Unrelated vendor-22644 successes and Stocks:[] responses are not closure evidence.
  4. The running image tag for product-database-next itself (only the storefront pods were confirmed via Prometheus).

Production access used

Read-only. Production logs were read directly through Grafana/Loki because that evidence had been missing for 12 days; production database reads were routed through POS Production, the task's recorded authorized path. No production writes, restarts, or deployments. No task YAML or production data changes other than this task's own state.

POS Production's full sanitized report — UTC daily table, evidence limits, and access limitations — is retained alongside this file as task-0492-production-findings.txt in the same investigations/ directory. Coder's full self-contained source report (full commit hashes, line references, complete error-path walk, closure checklist) is retained as task-0492-current-staging-findings.md in the same directory. POS Production's follow-up (Portainer deployment verification, deployed id forwarding, the POS stock-number examples, and the vendorStocks correction) is retained as task-0492-followup.txt in the same directory.

Loki datasource UID be5wy0358579cb; the proxy path requires the /uid/ segment: https://grafana.ddst.dev/api/datasources/proxy/uid/be5wy0358579cb/loki/api/v1/query_range. Direct loki.ddst.dev:3100 is not reachable from Phil-Z-Standard. Storefront, purchasing-service and product-database-next run in Kubernetes in the next-erp namespace, not on the .80 POS fleet.