Status: accepted 11 October 2026 by Dmitriy Zhuk and Yevhen Kariakin; withdrawal proposed 15 October 2026 by decision 007 (pending the founder's acceptance). The implementation was removed from the API; this page stays as history.
006 — Catalog mirror with an explicit observation time
The agent's catalog questions are answered from a copy of the catalog kept in the Store Deputy API, and every answer says when that copy was last observed. No change is ever planned from the copy. The mirror holds products, variants, categories and manufacturers of each connected store, is filled only through the driver's list and get of decision 004, and is queried with one SQL statement that returns compact rows and a total. Orders and customers are never copied. When the agent proposes a change, the API reads the selected items live, and the live value, not the mirrored one, becomes the expected of the conditional write.
Context
Decision 004 fixed that catalog_query_products does the whole query in one call and returns at most 50 compact rows with a total, because an Agentfy turn allows eight model round-trips and nothing bounds a tool result on the way to the model. It left open where the API gets the data: a copy in the API, or live pages from the shop at query time. Four readers of the catalog were found, with different freshness needs:
- The agent's questions (
catalog_query_products; PRODUCTS-02, ANALYTICS-03 in the scenario matrix): filters on status, price, stock, category and name, a total and whether more exist. Minutes of staleness are acceptable if the answer says so. - Matching a supplier price file (STOR-5, PRICES-02): an index over the whole catalog by SKU, code and GTIN. Protocol 1's
catalog.listexists for exactly this, withupdatedSincedescribed as "a hint, not a guarantee; a full pass is the reliable rebuild" (product.list). - Expanding a
selectioninto items withexpected: a copy is useless here; a staleexpectedturns everyapplyinto aconflict. - Reading back after
applyand reconciliation: always live.
So the choice concerns the first two readers only; the other two are live in every design. Facts found while exploring:
- The module never calls the API. Every request in Module Protocol 1 goes from the API to the module, including pairing; the OpenCart 3 module has no outbound HTTP call at all. A signal from the shop to the API is a new direction in the protocol.
- The API has no scheduler. The only background loop is a 15-second timer in the organization chat; the price-change job of STOR-5 "waits for part 2" for the same reason. One worker serves both the mirror and the change engine.
- The neutral
Producthas nocategoryIdsand nomanufacturerId. The category filter that 004 promises has nothing to filter on until the model gains these read-only fields. - Live pages do not scale.
listreturns at most 500 products per page; one neutral product is 761 bytes; a catalog of ten thousand products is twenty pages and several megabytes for every question, from a shop that is often on shared hosting. Shopify meters its Admin API by query cost. - Pushing the filter into the driver gives three filter languages. Shopify's
productsquery has its own search syntax, WooCommerce's REST API takesmin_price,stock_statusandmodified_after, and OpenCart 3 on MyISAM has no index on price. Decision 004 already put queries in the API for this reason; this decision gives them a place to run. - Platforms differ in change signals. Shopify delivers
products/create,products/updateandproducts/deletewebhooks; WordPress haswoocommerce_update_productand similar hooks; OpenCart 3 has admin events such asadmin/model/catalog/product/editProduct/after, which an extension that writes SQL directly bypasses, just as it bypassesdate_modified.
Decision
- A catalog mirror in the API, with an explicit observation time. Every read tool answers from the mirror and carries
observedAt(the oldest row in the answer) and the store'ssyncState:building,fresh,stale,failedorpaused. The agent is told to name the time when the data is older than a threshold, and abuildingstate is reported as "the index is being built, N of M", never as an empty catalog. - Catalog only. Products, variants, categories and manufacturers. Orders and customers are never copied: they are personal data, and the scenarios that need them (ORDERS-01, ORDERS-02, CUSTOMERS-01) work with live
searchandlistover a window the owner names, filtered in the API and bounded as every read is. - Polling is the only write path into the mirror; events are hints. A full pass through
listruns when a store connects or reconnects, once a day, when the manifest's capabilities change and when an operator asks for it. An incremental pass withupdatedSinceruns on an interval, after a hint and after Store Deputy's ownapply. A hint names ids and nothing else: Shopify webhooks for theshopifykind, a newcatalog.changedoperation sent by the module for themodulekind (the OpenCart module from its admin event, the WooCommerce plugin from its hook). The API queues the ids and reads them throughget; the body of a hint is never written to the mirror. A lost hint costs freshness, not correctness. - One table per mirrored resource, typed filter columns, the full neutral shape in JSON.
CatalogProductkeyed by(storeId, id)with the columns a filter or a compact row needs (code, SKU, GTINs, MPN, name, status, price amount as a number, currency, stock quantity, storefront ids, category ids, manufacturer id, the shop'supdatedAt), plusobservedAt,deletedAtfor tombstones, anddatawith the product exactly as the driver returned it, extensions included.CatalogVariantwithparentId, and smallCatalogCategoryandCatalogManufacturer. A query is one SQL statement withcount(*)for the total; a full product forcatalog_get_productscomes fromdata. - The mirror is a read model, never a source of truth. No write to a shop takes a value from the mirror. A proposal expands its
selectionon the mirror into ids, then reads every id live throughgetin batches of at mostmaxIdsPerRead; the live value becomesexpected, and an item that no longer matches the selection by its live value is dropped from the plan and listed on the approval card ("1 998 of 2 000; 2 changed after the question and were excluded"). The read-back after a successfulapplyis written to the mirror at once, so the owner's own change is visible to the next question without waiting for a pass. - Pause stops synchronization and writes, not reads of the copy. While the owner's switch in the shop is on, read tools answer from the mirror with
syncState: paused; every proposal is refused as today. Disconnecting a store orconnection.revokedeletes its mirror rows in the same transaction; the data of a store that left does not stay.
Alternatives considered
- Live pages at query time. Always fresh and no storage. Rejected: megabytes and seconds for every question, load on the shop proportional to the catalog and to the number of questions, and a total that still needs every page.
- A copy, refreshed before every answer. The mirror as a base, but each question first pulls
listwithupdatedSince. Rejected: freshness then depends ondate_modified, which direct SQL writes do not update, so the answer looks fresh and is not; and the shop is hit on every question anyway. - Polling only, no hints. Simplest, the protocol stays one-directional. Rejected: freshness equals the polling interval, and seeing a change within a minute means polling every connected shop every minute, idle or not. Kept as the behaviour when a platform has no hint.
- Events as the source. The webhook carries the product; the mirror is updated from its body. Rejected: Shopify sends duplicates and does not guarantee order, the OpenCart module would have to serialize the product on every save, and there would be three write paths into the mirror instead of one.
- Pushing filters into the driver (the filter tree of the Module JSON 1.0 proposal). Rejected in 004 and again here: every platform implements its own subset, with its own holes, and the API cannot promise a total.
- One generic
jsonbtable for every resource. Rejected: money is a four-decimal string in the neutral model, so a price range needs expression indexes with casts, and the name needs its own index too; the same columns, hidden in indexes, without the benefit of a schema. - In process memory or Redis. Rejected: a restart of the API would mean a full pass on every connected shop at once.
Consequences
- A question about the catalog is one SQL statement, whatever the catalog size; the shop is read in the background and in batches, never in the agent's turn except for the live reads of a proposal.
- Store Deputy keeps a copy of every connected catalog. Its size is bounded by the shops, not by the plans, until the founder decides whether a plan limits catalog size.
- The API gains a background worker, shared with the change engine's apply job; a connect now starts a full pass, and the store's page shows "indexing" until it ends.
- Module Protocol gains its first operation in the direction module → API,
catalog.changed, signed with the connection secret like every other call, and the API gains one inbound endpoint for hints of every kind. A module without it is served by polling alone. - The neutral
ProductgainscategoryIdsandmanufacturerId, read-only in this decision; Artem's module must return them. - The result of every read tool gains
observedAt,syncStateandtotalincontracts/mcp/tools.yaml. - Decision 003's
products.searchwith a filter tree is not needed: the filter runs in PostgreSQL over the mirror.
Scope
In: what is mirrored, how it is filled, how it is stored, how reads report freshness, how proposals re-read live, Pause, disconnection, isolation, the contract changes, how it is proved. Out: mirroring orders or customers, analytics (ANALYTICS-*), catalog size limits per plan, the polling intervals and the stale threshold (to be measured on the test shops), the creation of products through the agent, the WooCommerce plugin itself.
Constraints and numbers
| Fact | Where |
|---|---|
| The module has no outbound HTTP call; every request goes API → module | module/opencart3x/upload, no curl_init anywhere |
| The API has no scheduler; the only background loop is a 15-second timer | api/src/slices/agent/orgChat/domain/orgChat.service.ts:17 |
| The price-change job waits for a worker ("part 2") | api/src/slices/operations/priceChange/README.md:15 |
Product required fields: no categoryIds, no manufacturerId | contracts/module/protocol.yaml, $defs.Product.required |
list: 1 to 500 per page, default 100; updatedSince is a hint, not a guarantee | contracts/module/protocol.yaml:750, docs/protocol/index.md:593 |
OpenCart cursor: the last product_id; updatedSince becomes date_modified >= in shop time | docs/protocol/index.md:764 |
Store.manifest is already a cache with a refresh time | api/src/slices/store/store/store.prisma:18 |
| Eight model round-trips per turn; one neutral product 761 bytes; tool results unbounded | decision 004, numbers |
catalog.list was specified "to build the API's matching index for a supplier price file" | contracts/module/protocol.yaml:745 |
What this supersedes or must be reconciled with
- Closes the open question of decision 004 on where
catalog_query_productsreads from, and the related question of decision 005 on how the Shopify driver feeds the mirror: throughlistandgetlike every driver, with webhooks as hints. - Builds on 005: synchronization reads the shop only through
ICommerceDriver, so the module driver and the Shopify driver feed the mirror with the same code. - Changes Module Protocol 1 in two places once accepted: the read-only fields
categoryIdsandmanufacturerIdonProduct, andcatalog.changedas the first module → API operation, with its own signature rule incontracts/module/operations.json. - Makes the
products.searchfilter tree of decision 003 unnecessary; 003 is superseded by 004 since 11 October 2026. contracts/, the Prisma schema and the new slice change only after this record is accepted, with fixtures in the same change andbun run contracts:checkandbun run api:testpassing.
Open questions
| Question | Owner |
|---|---|
| The copy of every connected catalog was accepted on 11 October 2026. Still open: does a plan limit its size? | Dmitriy Zhuk |
The polling intervals, the daily full pass window and the stale threshold; to be measured on the two local test shops. | yevhen.kariakin |
Whether the OpenCart module registers the admin event and sends catalog.changed in its first version, or polling alone serves OpenCart at first. | Artem Belikov |
Whether catalog.changed and the Shopify webhooks share one inbound URL with the app/uninstalled webhook of decision 005. | yevhen.kariakin |
| Shopify's official webhook retry and deduplication rules (already open in 005). | yevhen.kariakin |
Whether the first version indexes the name with pg_trgm or a plain ILIKE suffices while catalogs are small. | yevhen.kariakin |