S00-005: Select idb and verify transactional storage failure policies

Changes: Propose ADR 0004 comparing native IndexedDB, idb and Dexie; select idb 8.0.4 with account, transaction, quota, upgrade and key ownership policy. Repair rollback and add injected quota/blocked upgrade checks, exact wrapper lock, runtime guard, license texts and reproduction notes. Preserve historical recovery artifacts.
Validation: Fresh-cache npm ci and npm run check passed on Node 24.21.0/npm 11.19.0; manifest, HTTPS/SHA512 and license checks passed. make check passed 72 tooling tests; tasks.py validate and git diff --check passed. Native browser quota, disk durability and process restart were not tested; ADR remains proposed for independent QA.

Task: S00-005
Agent: auto-storage-0ce544ac4b40
Role: storage
Action: claim
Status: review

Task title: Выбрать IndexedDB wrapper и migration policy
This commit is contained in:
wt committed 2026-10-15 18:33:15 +07:00
1 parent 8f918bc040
commit 0e2b3098df
17 files changed
+713 -128

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
# ADR 0004: IndexedDB wrapper and migration policy
- Status: proposed; independent QA acceptance pending.
- Task / requirements: S00-005 / STORE-001, STORE-004.
- Date: 2026-10-15.
- Decision owner: auto-storage-0ce544ac4b40 (storage).
- Reviewer: assigned qa, not yet reviewed.
## Context and required capabilities
Choose browser persistence tooling and policy, using accepted ADR 0001 (TypeScript,
ESM, Node 24.21.0/npm 11.19.0). Account history, crypto state and settings require
isolation, transactional writes and honest failure reporting. This decision does
not define application record schemas or port signatures. The registry reserves
`docs/contracts/persistence.md` for S01; that file does not exist yet. No current
experiment needs a new shared interface. Downstream implementation must wait for
its accepted models/lifecycle/persistence contracts.
## Candidates and primary sources
Documentation and registry metadata inspected on 2026-10-15:
| Candidate | Benefits | Cost / outcome |
| --- | --- | --- |
| Native IndexedDB | Standard API, no package | Event/request handling requires more adapter code; reference behavior, not selected ergonomics |
| idb 8.0.4, ISC | Promise API, typed schemas, explicit transaction completion and upgrade callbacks | Native transaction lifetime still applies; selected and executed |
| Dexie 4.4.6, Apache-2.0 | Query helpers, declarative versions and transaction API | Broader abstraction than this bounded adapter needs; researched, not installed or benchmarked |
Select **idb 8.0.4**. Its small API surface keeps native transaction boundaries
visible while providing promises and TypeScript declarations. Dexie remains a
viable option if measured query requirements justify it. No speed or security
superiority is claimed. `npm view` verified exact candidate versions/licenses;
installed idb metadata has no runtime dependencies. Only the isolated experiment
manifest/lock changes here; production adoption belongs to later scoped tasks.
Sources:
- [idb documentation](https://github.com/jakearchibald/idb): promises, `tx.done`,
typed schemas, transaction lifetime and upgrade/blocked/blocking/terminated APIs.
- [Dexie design](https://dexie.org/docs/Tutorial/Design): queries, transactions,
versioning and asynchronous transaction limits.
- [IndexedDB standard](https://w3c.github.io/IndexedDB/): request errors,
transaction abort/commit, version changes and durability hints.
- [Storage standard](https://storage.spec.whatwg.org/): estimates and persistence
requests; [WebKit storage policy](https://webkit.org/blog/14403/updates-to-storage-policy/)
illustrates browser-controlled quotas/eviction. No fixed quota is promised.
- Registry records: [idb 8.0.4](https://registry.npmjs.org/idb/8.0.4),
[Dexie 4.4.6](https://registry.npmjs.org/dexie/4.4.6),
[fake-indexeddb 6.2.5](https://registry.npmjs.org/fake-indexeddb/6.2.5).
- [fake-indexeddb documentation](https://github.com/dumbmatter/fakeIndexedDB):
in-memory testing implementation, without disk persistence.
## Transaction and account policy
Use one versioned application database per origin with distinct history, crypto,
settings and metadata stores. Every account-owned key and index starts with the
canonical accountId; unscoped scans are forbidden in account APIs. AccountId is
an opaque application identity, not a password or a raw JID database name. Capture
account/generation before asynchronous work and validate it at application entry;
do not resolve an account from whichever context is active after awaiting.
History mutations and their archive checkpoint share one readwrite transaction.
Any coupled crypto mutation must use that same database transaction when required
by the future crypto contract. Separate stores allow this; separate databases
would not. Cache is disposable and must never be the only copy of crypto state.
Network/worker/crypto preparation finishes before starting a transaction. Await
only IDB requests within it; any other asynchronous work risks auto-commit.
Success is published only after `tx.done` resolves. Synchronous exceptions,
request failures and completion failures all produce a failed save; abort an
active transaction and observe completion before returning. Never swallow a
request error and then report success. External XMPP delivery is not part of the
local transaction: reconcile delivery separately rather than blindly resend.
Use strict durability hints for critical state where supported/verified, with
default durability explicitly recorded otherwise; neither is a hardware vault
or proof against device failure, eviction or user clearing.
## Schema upgrade and connection ownership
Use monotonically increasing integer versions, sequential oldVersion steps and
one versionchange transaction. A fresh database runs every needed step. Modify
existing stores via the upgrade transaction; do not recreate them accidentally.
Upgrade code is deterministic and local: no network, worker waits, secrets or
unbounded whole-history transformation. Large resumable transformations require
an independently designed recovery/checkpoint contract before implementation.
Each tab/worker owns its connection. On blocking/versionchange, stop accepting
new writes, let current work finish/abort, close the connection and request reload
to the supported schema. On blocked, show an upgrade-wait state with instructions
to close/reload other tabs; do not delete the database or claim readiness. A wait
deadline changes UI state, not the upgrade result. IndexedDB open cannot simply
be cancelled: a late success for a retired attempt must be closed and ignored.
On terminated, invalidate the handle and reopen under lifecycle control.
An aborted migration leaves the prior version/data available for investigation
and a corrected forward retry. No automatic wipe, schema downgrade or silent
rebuild of non-recoverable state. An older build receiving VersionError asks for
an update; release rollback must retain a compatible reader or ship a corrective
forward migration. Tests must cover fresh creation and each supported old version.
## Quota, eviction and key ownership
Estimates are advisory and race with other origin storage. Request persistent
storage through supported StorageManager APIs and report the actual granted
state; denial does not mean storage is unavailable. Quota/unknown disk failures
must stop the batch without advancing checkpoint. UI reports history not saved
locally and retains bounded pending work in memory under the later queue policy.
Retry is explicit/bounded after freeing disposable media/cache; never remove
crypto, trust state or unsynced history to make space automatically. Reload or
origin clearing may lose pending memory and local data; startup must detect missing
schema/account markers and request a real recovery path rather than imply success.
Browser testing still must verify native exhaustion, eviction and restart behavior.
Storage owns byte persistence and isolation, **not cryptographic key generation,
trust or unlock policy**. Crypto owns serialization/versioning of opaque state
and any wrapping/unlock material under its accepted ADR/contract. This task does
not authorize saving raw private keys. Passwords remain memory-only; no password,
unlock secret or reusable wrapping secret in localStorage/IndexedDB. Persistent
unlock needs its own accepted decision. Same-origin script access is a security
boundary: IndexedDB alone provides neither XSS resistance nor hardware backing.
Account removal must delete its records across all owned stores atomically,
invalidate in-flight context and release in-memory crypto; exact deletion and
suppression semantics remain S01/application work, not an implemented API here.
## Focused experiment and actual result
`experiments/0004-storage-design` uses exact idb 8.0.4 and fake-indexeddb 6.2.5,
locked HTTPS/SHA512 dependencies and the accepted Node/npm pins. Fresh-cache
`npm ci --ignore-scripts --no-audit --no-fund` and `npm run check` passed.
- Real fixture ConstraintError during v1→v2 unique-index migration aborts open;
v1 store/data survive, new store/index disappear. Corrected retry reaches v2,
is queryable and survives connection reopen in the same process.
- Explicit QuotaExceededError injection after successful history/checkpoint
requests returns failed save, aborts both mutations and preserves account B.
A clean retry commits both. This tests policy, not native quota generation.
- Holding v1 produces versionchange then blocked; upgrade has not executed.
Closing v1 allows v2 and preserves checkpoint. Opening v1 again fails VersionError.
These are synthetic API experiments, not production adapters. Browser inventory
was empty. Native disk quota, crash/process restart, browser multi-tab, eviction,
persistence grants and crypto unlock were not tested. No browser readiness or
application durability acceptance is implied. See README and task evidence for
commands and limits; preserved RECOVERY.md describes the historical checkpoint.
## License / browser constraints and consequences
idb's ISC notice is retained in the experiment; fake-indexeddb's Apache-2.0 text
is retained as a test-only dependency notice. Neither package declares runtime
dependencies in this lock graph. Installs disable lifecycle scripts and enforce
normal TLS; audit/provenance assessment was not performed. Future distributions
must retain notices for the actual bundled graph.
idb targets modern Chrome/Firefox/Safari/Edge and excludes IE. TypeScript types
do not polyfill IndexedDB, Proxy or storage capabilities. ADR 0001 syntax floors
are not a browser test matrix; S00-006 owns product support. If IndexedDB opening
fails (private mode, policy, permissions or security errors), expose unavailable
storage and fail saves honestly. No fake-indexeddb production fallback.
S01 must define exact keys/indexes, normalized account identifiers, save errors,
cancellation, crypto ownership and valid/invalid fixtures before adapter work.
Future tests must add account deletion/suppression, cancelled generations,
every supported migration and native browser quota/restart coverage. New query
requirements, browser incompatibility, unacceptable migration cost or changed
crypto atomicity requirements trigger a bounded ADR revision, never an implicit
wrapper/stack replacement.
+2 -1
View File
@@ -1,2 +1,3 @@
registry=https://registry.npmjs.org/
strict-ssl=true
strict-ssl=true
engine-strict=true
+41
View File
@@ -0,0 +1,41 @@
# Storage design experiment (S00-005)
Synthetic fixtures only. No app adapter, shared contract, secrets or real messages.
ADR: `docs/decisions/0004-storage-design.md` (proposed pending independent QA).
`RECOVERY.md` preserves the earlier interruption inventory; its missing-output
notes are historical, superseded by this task's code and evidence.
From this directory, using Node 24.21.0 and bundled npm 11.19.0:
```sh
npm ci --ignore-scripts --no-audit --no-fund --cache /tmp/luma-storage-review-cache --fetch-retries=0 --fetch-timeout=15000
npm run check
```
`check` refuses other Node/npm versions. Lockfile pins idb 8.0.4 (ISC) and
fake-indexeddb 6.2.5 (Apache-2.0), with HTTPS URLs/SHA512 integrity and no transitives.
`.npmrc` retains verified TLS. Runtime dependencies are isolated to this experiment.
Full license texts are in `licenses/`; production distributions must preserve
idb's notice. fake-indexeddb is a test fixture and must not enter production paths.
- `src/rollback.mjs`: actual unique-index ConstraintError, failed upgrade rollback,
complete schema/data assertions, corrected retry and same-process connection reopen.
- `src/quota-blocked.mjs`: explicitly injected quota error after successful requests,
multi-store abort/checkpoint invariance, account B preservation, retry/reopen;
held old connection, versionchange/blocked and release; stale-version refusal.
- `src/_probe.mjs`: preserved exploratory native-API fixture, outside check suite.
Each fixture uses its own synthetic database name and deletes it before/after.
The blocked scenario has a 3-second failure deadline. CI should impose an overall
process timeout as well. Exceptions/assertion failures cause nonzero exit;
PASS text is printed only after the corresponding assertions.
fake-indexeddb is in memory. Quota fault injection checks the policy response and
real fixture transaction abort, not a native request/commit QuotaExceededError.
Reopen is not process restart. No real browser was available (empty inventory).
Browser multi-tab, physical quota/disk failure, crash/restart, eviction and
StorageManager permission/persistence grants remain external integration checks.
Future browser testing should use a disposable isolated origin/profile, repeat
the schema and blocked scenarios on native IDB, then validate request/commit
quota failures and restart persistence without filling a user's normal origin.
No TLS, CORS or encryption workaround is required or authorized.
@@ -0,0 +1,209 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the
copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other
entities that control, are controlled by, or are under common control with
that entity. For the purposes of this definition, "control" means (i) the
power, direct or indirect, to cause the direction or management of such
entity, whether by contract or otherwise, or (ii) ownership of
fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation source,
and configuration files.
"Object" form shall mean any form resulting from mechanical transformation
or translation of a Source form, including but not limited to compiled
object code, generated documentation, and conversions to
other media types.
"Work" shall mean the work of authorship, whether in Source or Object
form, made available under the License, as indicated by a copyright notice
that is included in or attached to the work (an example is provided in the
Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form,
that is based on (or derived from) the Work and for which the editorial
revisions, annotations, elaborations, or other modifications represent,
as a whole, an original work of authorship. For the purposes of this
License, Derivative Works shall not include works that remain separable
from, or merely link (or bind by name) to the interfaces of, the Work and
Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original
version of the Work and any modifications or additions to that Work or
Derivative Works thereof, that is intentionally submitted to Licensor for
inclusion in the Work by the copyright owner or by an individual or
Legal Entity authorized to submit on behalf of the copyright owner.
For the purposes of this definition, "submitted" means any form of
electronic, verbal, or written communication sent to the Licensor or its
representatives, including but not limited to communication on electronic
mailing lists, source code control systems, and issue tracking systems
that are managed by, or on behalf of, the Licensor for the purpose of
discussing and improving the Work, but excluding communication that is
conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on
behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
royalty-free, irrevocable copyright license to reproduce, prepare
Derivative Works of, publicly display, publicly perform, sublicense,
and distribute the Work and such Derivative Works in
Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
royalty-free, irrevocable (except as stated in this section) patent
license to make, have made, use, offer to sell, sell, import, and
otherwise transfer the Work, where such license applies only to those
patent claims licensable by such Contributor that are necessarily
infringed by their Contribution(s) alone or by combination of their
Contribution(s) with the Work to which such Contribution(s) was submitted.
If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or
contributory patent infringement, then any patent licenses granted to
You under this License for that Work shall terminate as of the date such
litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works
thereof in any medium, with or without modifications, and in Source or
Object form, provided that You meet the following conditions:
1. You must give any other recipients of the Work or Derivative Works a
copy of this License; and
2. You must cause any modified files to carry prominent notices stating
that You changed the files; and
3. You must retain, in the Source form of any Derivative Works that You
distribute, all copyright, patent, trademark, and attribution notices from
the Source form of the Work, excluding those notices that do not pertain
to any part of the Derivative Works; and
4. If the Work includes a "NOTICE" text file as part of its distribution,
then any Derivative Works that You distribute must include a readable copy
of the attribution notices contained within such NOTICE file, excluding
those notices that do not pertain to any part of the Derivative Works,
in at least one of the following places: within a NOTICE text file
distributed as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or, within a
display generated by the Derivative Works, if and wherever such
third-party notices normally appear. The contents of the NOTICE file are
for informational purposes only and do not modify the License.
You may add Your own attribution notices within Derivative Works that You
distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and may
provide additional or different license terms and conditions for use,
reproduction, or distribution of Your modifications, or for any such
Derivative Works as a whole, provided Your use, reproduction, and
distribution of the Work otherwise complies with the conditions
stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally
submitted for inclusion in the Work by You to the Licensor shall be under
the terms and conditions of this License, without any additional
terms or conditions. Notwithstanding the above, nothing herein shall
supersede or modify the terms of any separate license agreement you may
have executed with Licensor regarding such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor
provides the Work (and each Contributor provides its Contributions)
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied, including, without limitation, any warranties
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any risks
associated with Your exercise of permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort
(including negligence), contract, or otherwise, unless required by
applicable law (such as deliberate and grossly negligent acts) or agreed
to in writing, shall any Contributor be liable to You for damages,
including any direct, indirect, special, incidental, or consequential
damages of any character arising as a result of this License or out of
the use or inability to use the Work (including but not limited to damages
for loss of goodwill, work stoppage, computer failure or malfunction,
or any and all other commercial damages or losses), even if such
Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose
to offer, and charge a fee for, acceptance of support, warranty,
indemnity, or other liability obligations and/or rights consistent with
this License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf of any
other Contributor, and only if You agree to indemnify, defend, and hold
each Contributor harmless for any liability incurred by, or claims
asserted against, such Contributor by reason of your accepting any such
warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets "[]" replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included
on the same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2017 Jeremy Scheff
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing
permissions and limitations under the License.
@@ -0,0 +1,6 @@
ISC License (ISC)
Copyright (c) 2016, Jake Archibald <jaffathecake@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+8 -1
View File
@@ -8,7 +8,8 @@
"name": "0004-storage-design",
"version": "0.0.0",
"dependencies": {
"fake-indexeddb": "6.2.5"
"fake-indexeddb": "6.2.5",
"idb": "8.0.4"
},
"engines": {
"node": "24.21.0",
@@ -23,6 +24,12 @@
"engines": {
"node": ">=18"
}
},
"node_modules/idb": {
"version": "8.0.4",
"resolved": "https://registry.npmjs.org/idb/-/idb-8.0.4.tgz",
"integrity": "sha512-jd0ITCrN+Zah4J7R/Z2jnR3W7A4BXDAjmo62MwWuSjxCiueUAf7X5rbodEdidWzeknwXHmLpdZkoiiCppNi30Q==",
"license": "ISC"
}
}
}
+8 -4
View File
@@ -3,14 +3,18 @@
"version": "0.0.0",
"private": true,
"type": "module",
"engines": { "node": "24.21.0", "npm": "11.19.0" },
"engines": {
"node": "24.21.0",
"npm": "11.19.0"
},
"packageManager": "npm@11.19.0",
"scripts": {
"check:rollback": "node src/rollback.mjs",
"check:quota": "node src/quota-blocked.mjs",
"check": "npm run check:rollback && npm run check:quota"
"check": "node src/check-runtime.mjs && npm run check:rollback && npm run check:quota"
},
"dependencies": {
"fake-indexeddb": "6.2.5"
"fake-indexeddb": "6.2.5",
"idb": "8.0.4"
}
}
}
@@ -0,0 +1,3 @@
import assert from 'node:assert/strict';
assert.equal(process.version, 'v24.21.0');
assert.match(process.env.npm_config_user_agent ?? '', /^npm\/11\.19\.0 /);
@@ -0,0 +1,69 @@
import 'fake-indexeddb/auto';
import assert from 'node:assert/strict';
import { openDB, deleteDB } from 'idb';
const name = 'luma-design-quota-blocked';
await deleteDB(name);
let db = await openDB(name, 1, { upgrade(db) {
for (const store of ['history', 'checkpoints', 'settings', 'crypto']) db.createObjectStore(store);
} });
// Illustrative composite keys, not an application contract.
await db.put('history', { text: 'Synthetic other account' }, ['B', 'm1']);
await db.put('checkpoints', 'before', 'A');
await db.put('settings', 'B-setting', ['B', 'theme']);
await db.put('crypto', 'B-opaque-fixture-not-key-material', ['B', 'state']);
// Explicit quota fault injection: fake-indexeddb has no real disk quota.
async function saveBatch(injectFailure) {
const tx = db.transaction(['history', 'checkpoints'], 'readwrite');
const completion = tx.done;
completion.catch(() => {});
try {
await tx.objectStore('history').put({ text: 'Synthetic pending' }, ['A', 'm1']);
await tx.objectStore('checkpoints').put('after', 'A');
if (injectFailure) throw new DOMException('Synthetic quota injection', 'QuotaExceededError');
await completion;
return { saved: true };
} catch (error) {
try { tx.abort(); } catch { /* Engine may have already aborted. */ }
await completion.catch(() => {});
return { saved: false, reason: error.name };
}
}
assert.deepEqual(await saveBatch(true), { saved: false, reason: 'QuotaExceededError' });
assert.equal(await db.get('history', ['A', 'm1']), undefined);
assert.equal(await db.get('checkpoints', 'A'), 'before');
assert.deepEqual(await db.get('history', ['B', 'm1']), { text: 'Synthetic other account' });
assert.equal(await db.get('settings', ['B', 'theme']), 'B-setting');
assert.equal(await db.get('crypto', ['B', 'state']), 'B-opaque-fixture-not-key-material');
assert.deepEqual(await saveBatch(false), { saved: true });
db.close();
db = await openDB(name, 1);
assert.equal(await db.get('checkpoints', 'A'), 'after');
assert.deepEqual(await db.get('history', ['A', 'm1']), { text: 'Synthetic pending' });
let versionChange = false;
let upgraded = false;
db.addEventListener('versionchange', () => { versionChange = true; });
let signalBlocked;
const blocked = new Promise(resolve => { signalBlocked = resolve; });
const pending = openDB(name, 2, {
blocked() { signalBlocked(); },
upgrade(db) { upgraded = true; db.createObjectStore('v2Marker'); },
});
const timer = setTimeout(() => { throw new Error('blocked event timeout'); }, 3000);
await blocked;
assert.equal(versionChange, true);
assert.equal(upgraded, false);
assert.equal(db.version, 1);
db.close();
const next = await pending;
clearTimeout(timer);
assert.equal(upgraded, true);
assert.equal(next.version, 2);
assert.equal(await next.get('checkpoints', 'A'), 'after');
next.close();
await assert.rejects(openDB(name, 1), { name: 'VersionError' });
await deleteDB(name);
console.log('PASS quota policy (injected): no saved success or checkpoint advance on abort; account isolation; retry/reopen');
console.log('PASS blocked upgrade: versionchange then blocked; close releases upgrade; stale version refused');
+45 -107
View File
@@ -1,108 +1,46 @@
import "fake-indexeddb/auto";
import assert from "node:assert/strict";
import 'fake-indexeddb/auto';
import assert from 'node:assert/strict';
import { openDB, deleteDB } from 'idb';
// Bounded storage experiment (S00-005, focused check "Rollback experiment").
// Uses fake-indexeddb 6.2.5 (in-memory, pure-JS IndexedDB implementation) to exercise
// the transaction/schema-upgrade rollback guarantees that a Web storage layer relies
// on for STORE-001 (transactional saves or verifiable equivalent recovery).
// This is an API-semantics probe, not a browser-durability claim.
const DB = "rollback-probe";
function open(version, upgrade) {
return new Promise((resolve, reject) => {
const req = indexedDB.open(DB, version);
const events = { upgraded: false, blocked: false };
req.onupgradeneeded = () => {
events.upgraded = true;
if (upgrade) upgrade(req.result);
};
req.onsuccess = () => resolve({ db: req.result, events });
req.onerror = () => reject(new Error(`open(v${version}): ${req.error?.name}`));
req.onblocked = () => { events.blocked = true; };
});
}
function getAll(db, store) {
return new Promise((resolve, reject) => {
const tx = db.transaction(store, "readonly");
tx.objectStore(store).getAll().onsuccess = (e) => resolve(e.target.result);
tx.onerror = () => reject(tx.error);
});
}
async function seedV1() {
const { db } = await open(1, (db) => {
db.createObjectStore("accounts", { keyPath: "accountId" });
});
db.close();
// write a durable per-account record (configuration, non-secret fixture)
const w = await open(1);
await new Promise((resolve, reject) => {
const tx = w.db.transaction("accounts", "readwrite");
tx.objectStore("accounts").add({ accountId: "A1", displayName: "Alice" });
tx.oncomplete = resolve;
tx.onerror = () => reject(tx.error);
});
w.db.close();
}
// Scenario 1 (rollback): upgrade v1 -> v2 that fails mid-way because a data migration
// violates a new unique index inside the versionchange transaction. The whole upgrade
// must abort and revert: schema version stays at v1, the new index/store is absent,
// and pre-existing v1 data is untouched.
async function failedUpgradeRollsBack() {
const req = indexedDB.open(DB, 2);
let aborted = true;
req.onupgradeneeded = () => {
const db = req.result;
const accounts = db.createObjectStore("accounts", { keyPath: "accountId" });
accounts.createIndex("displayName", "displayName", { unique: true });
// Both rows share the same unique displayName -> the second write fails and
// aborts the versionchange transaction (organic failure, not a manual abort).
accounts.add({ accountId: "A1", displayName: "Shared" });
accounts.add({ accountId: "A2", displayName: "Shared" });
};
req.onsuccess = () => { aborted = false; req.result.close(); };
req.onerror = () => { /* default abort */ };
await new Promise((resolve) => { req.onsuccess = resolve; req.onerror = resolve; });
assert.equal(aborted, true, "failing data migration must abort the upgrade (no fake success)");
// Schema version must remain at v1 after the abort.
const meta = await indexedDB.databases().then((l) => l.find((d) => d.name === DB));
assert.equal(meta.version, 1, "failed upgrade must keep persisted schema version at v1");
const { db } = await open(1);
assert.ok(db.objectStoreNames.contains("accounts"), "v1 accounts store survives");
const rows = await getAll(db, "accounts");
assert.equal(rows.length, 1, "no partial migration rows persisted");
assert.equal(rows[0].accountId, "A1", "pre-existing v1 data intact after rollback");
db.close();
}
// Scenario 2 (retry after rollback): after a clean rollback a corrected migration can be
// retried and commits fully to v2 without a stale schema or lost data.
async function retryAfterRollbackSucceeds() {
const { db, events } = await open(2, (db) => {
const accounts = db.createObjectStore("accounts", { keyPath: "accountId" });
accounts.createIndex("displayName", "displayName", { unique: true });
accounts.add({ accountId: "A1", displayName: "Alice" });
accounts.add({ accountId: "A2", displayName: "Bob" });
});
assert.equal(events.upgraded, true, "retry upgrade runs");
assert.equal(db.version, 2, "retry commits to v2");
const rows = await getAll(db, "accounts");
assert.equal(rows.length, 2, "both accounts migrated");
db.close();
}
async function main() {
await seedV1();
await failedUpgradeRollsBack();
await retryAfterRollbackSucceeds();
console.log("rollback.mjs PASS: failed v1->v2 upgrade rolled back atomically (schema v1 kept, no partial data); corrected retry committed cleanly to v2.");
}
await main();
// Synthetic API semantics; reopening is not a disk/process restart.
const name = 'luma-design-rollback';
await deleteDB(name);
let db = await openDB(name, 1, { upgrade(db) {
db.createObjectStore('accounts', { keyPath: 'accountId' });
} });
await db.put('accounts', { accountId: 'A1', displayName: 'Fixture One' });
db.close();
let constraint;
await assert.rejects(openDB(name, 2, { upgrade(db, old, next, tx) {
assert.equal(old, 1);
db.createObjectStore('migrationMarker');
const accounts = tx.objectStore('accounts');
accounts.createIndex('displayName', 'displayName', { unique: true });
accounts.put({ accountId: 'A1', displayName: 'Duplicate' }).catch(() => {});
accounts.add({ accountId: 'A2', displayName: 'Duplicate' }).catch(error => { constraint = error.name; });
// Observe promise rejections without suppressing native request error/abort.
tx.done.catch(() => {});
} }), { name: 'AbortError' });
assert.equal(constraint, 'ConstraintError');
db = await openDB(name, 1);
assert.equal(db.version, 1);
assert.deepEqual([...db.objectStoreNames], ['accounts']);
assert.deepEqual([...db.transaction('accounts').store.indexNames], []);
assert.deepEqual(await db.getAll('accounts'), [{ accountId: 'A1', displayName: 'Fixture One' }]);
db.close();
db = await openDB(name, 2, { upgrade(db, old, next, tx) {
db.createObjectStore('migrationMarker');
const accounts = tx.objectStore('accounts');
accounts.createIndex('displayName', 'displayName', { unique: true });
accounts.add({ accountId: 'A2', displayName: 'Fixture Two' }).catch(() => {});
tx.done.catch(() => {});
} });
assert.equal(db.version, 2);
assert.equal((await db.getAll('accounts')).length, 2);
assert.equal((await db.getFromIndex('accounts', 'displayName', 'Fixture Two')).accountId, 'A2');
db.close();
db = await openDB(name, 2);
assert.equal((await db.getAll('accounts')).length, 2);
db.close();
await deleteDB(name);
console.log('PASS rollback: ConstraintError; v1 schema/data restored; corrected v2 retry and reopen');
+2 -2
View File
@@ -1,6 +1,6 @@
# Матрица задач
Generated; state revision **115**. Canonical status: state/tasks.json.
Generated; state revision **117**. Canonical status: state/tasks.json.
| ID | Этап | Оператор | Reviewer | Статус | Owner | Зависимости | Задача |
| --- | --- | --- | --- | --- | --- | --- | --- |
@@ -8,7 +8,7 @@ Generated; state revision **115**. Canonical status: state/tasks.json.
| [S00-002](tasks/S00-002.md) | S00 | orchestrator | security | done | auto-orchestrator-68a05c587e33 | S00-001, S00-011, S00-012 | Выбрать framework и build runtime |
| [S00-003](tasks/S00-003.md) | S00 | protocol | qa | done | auto-protocol-f474114f0168 | S00-001, S00-002, S00-017, S00-018, S00-019, S00-020 | Проверить XMPP WSS/auth библиотеку |
| [S00-004](tasks/S00-004.md) | S00 | crypto | security | blocked | auto-crypto-fe1c81c17ded | S00-001, S00-002, S00-021, S00-022 | Проверить browser OMEMO backend |
| [S00-005](tasks/S00-005.md) | S00 | storage | qa | todo | | S00-002, S00-023 | Выбрать IndexedDB wrapper и migration policy |
| [S00-005](tasks/S00-005.md) | S00 | storage | qa | review | auto-storage-0ce544ac4b40 | S00-002, S00-023 | Выбрать IndexedDB wrapper и migration policy |
| [S00-006](tasks/S00-006.md) | S00 | orchestrator | security | todo | | S00-002 | Зафиксировать browser/reference matrix |
| [S00-007](tasks/S00-007.md) | S00 | security | orchestrator | todo | | S00-004, S00-005 | Утвердить password и crypto unlock модель |
| [S00-008](tasks/S00-008.md) | S00 | ci-cd | qa | todo | | S00-003, S00-004 | Описать WSS/upload/TURN/push topology |
+1 -1
View File
@@ -10,7 +10,7 @@
- [S00-002](../tasks/S00-002.md): Выбрать framework и build runtime — orchestrator; done.
- [S00-003](../tasks/S00-003.md): Проверить XMPP WSS/auth библиотеку — protocol; done.
- [S00-004](../tasks/S00-004.md): Проверить browser OMEMO backend — crypto; blocked.
- [S00-005](../tasks/S00-005.md): Выбрать IndexedDB wrapper и migration policy — storage; todo.
- [S00-005](../tasks/S00-005.md): Выбрать IndexedDB wrapper и migration policy — storage; review.
- [S00-006](../tasks/S00-006.md): Зафиксировать browser/reference matrix — orchestrator; todo.
- [S00-007](../tasks/S00-007.md): Утвердить password и crypto unlock модель — security; todo.
- [S00-008](../tasks/S00-008.md): Описать WSS/upload/TURN/push topology — ci-cd; todo.
+1 -1
View File
@@ -3,7 +3,7 @@ S00-001,S00,orchestrator,security,done,auto-orchestrator-48aab142ecde,,Утве
S00-002,S00,orchestrator,security,done,auto-orchestrator-68a05c587e33,"S00-001, S00-011, S00-012",Выбрать framework и build runtime
S00-003,S00,protocol,qa,done,auto-protocol-f474114f0168,"S00-001, S00-002, S00-017, S00-018, S00-019, S00-020",Проверить XMPP WSS/auth библиотеку
S00-004,S00,crypto,security,blocked,auto-crypto-fe1c81c17ded,"S00-001, S00-002, S00-021, S00-022",Проверить browser OMEMO backend
S00-005,S00,storage,qa,todo,,"S00-002, S00-023",Выбрать IndexedDB wrapper и migration policy
S00-005,S00,storage,qa,review,auto-storage-0ce544ac4b40,"S00-002, S00-023",Выбрать IndexedDB wrapper и migration policy
S00-006,S00,orchestrator,security,todo,,S00-002,Зафиксировать browser/reference matrix
S00-007,S00,security,orchestrator,todo,,"S00-004, S00-005",Утвердить password и crypto unlock модель
S00-008,S00,ci-cd,qa,todo,,"S00-003, S00-004",Описать WSS/upload/TURN/push topology
1 id stage operator reviewer status owner depends_on title
3 S00-002 S00 orchestrator security done auto-orchestrator-68a05c587e33 S00-001, S00-011, S00-012 Выбрать framework и build runtime
4 S00-003 S00 protocol qa done auto-protocol-f474114f0168 S00-001, S00-002, S00-017, S00-018, S00-019, S00-020 Проверить XMPP WSS/auth библиотеку
5 S00-004 S00 crypto security blocked auto-crypto-fe1c81c17ded S00-001, S00-002, S00-021, S00-022 Проверить browser OMEMO backend
6 S00-005 S00 storage qa todo review auto-storage-0ce544ac4b40 S00-002, S00-023 Выбрать IndexedDB wrapper и migration policy
7 S00-006 S00 orchestrator security todo S00-002 Зафиксировать browser/reference matrix
8 S00-007 S00 security orchestrator todo S00-004, S00-005 Утвердить password и crypto unlock модель
9 S00-008 S00 ci-cd qa todo S00-003, S00-004 Описать WSS/upload/TURN/push topology
@@ -0,0 +1,4 @@
Select idb and verify transactional storage failure policies
Changes: Propose ADR 0004 comparing native IndexedDB, idb and Dexie; select idb 8.0.4 with account, transaction, quota, upgrade and key ownership policy. Repair rollback and add injected quota/blocked upgrade checks, exact wrapper lock, runtime guard, license texts and reproduction notes. Preserve historical recovery artifacts.
Validation: Fresh-cache npm ci and npm run check passed on Node 24.21.0/npm 11.19.0; manifest, HTTPS/SHA512 and license checks passed. make check passed 72 tooling tests; tasks.py validate and git diff --check passed. Native browser quota, disk durability and process restart were not tested; ADR remains proposed for independent QA.
@@ -0,0 +1,90 @@
# S00-005 executor evidence
Executor: auto-storage-0ce544ac4b40 (storage), 2026-10-15.
Result: proposed ADR 0004 and bounded storage experiments, pending independent QA.
Input: master/startup/role/workflow documents, required TESTING and ADR registry,
assigned resume/show/packet, original handoff, exact STORE-001/STORE-004 in
specs/tz_clear.md, accepted ADR 0001, direct S00-002/S00-023 executor/review evidence
and handoffs, preserved RECOVERY.md and unfinished experiment files.
No repeat claim, new task, subagent or model launch. No ancestor AGENTS.md found
by explicit parent-path inspection. Persistence contract is listed as future S01
work in the registry and is not present; this research needs no shared contract.
## Actual changes
- ADR compares native IndexedDB, idb 8.0.4 and Dexie 4.4.6; selects idb, sets
account isolation, transaction/completion, quota, migration, connection and key
ownership policy. Remains proposed. No production implementation claim.
- Isolated manifest/lock pins idb alongside preserved fake-indexeddb 6.2.5;
retained HTTPS/TLS and added strict engines + exact runtime check. Package license
texts copied from the installed unmodified packages into scoped licenses/.
- Replaced defective rollback with actual ConstraintError migration, schema/index/
data restoration assertions, corrected retry and same-process reopen.
- Added explicit injected quota-failure policy/atomic abort/checkpoint/account
preservation and real fixture blocked/versionchange/release/VersionError checks.
- README explains reproduction and limits. Historical RECOVERY.md and exploratory
_probe.mjs remain unchanged. No application module, shared interface, immutable
specification, plan definition or system/Git configuration changed.
## Commands and observed results
All successful npm commands used
`PATH=/tmp/luma-approved-toolchain/node-v24.21.0-linux-x64/bin:$PATH`.
Existing approved isolated runtime reused; no archive download/checksum claimed.
| Command/check | Exit | Observed result |
| --- | --- | --- |
| `python3 scripts/tasks.py resume --agent auto-storage-0ce544ac4b40`, `show S00-005`, `packet S00-005 --agent auto-storage-0ce544ac4b40` | 0 each | Correct assigned task, ready reviewed dependencies; scope read |
| `npm view idb version license engines dependencies --json --cache /tmp/luma-storage-cache --fetch-retries=0 --fetch-timeout=15000` | 0 | idb 8.0.4 ISC |
| `npm view dexie version license engines --json --cache /tmp/luma-storage-cache-dexie --fetch-retries=0 --fetch-timeout=15000` | 0 | Dexie 4.4.6 Apache-2.0; not installed |
| From experiment: `npm install --ignore-scripts --no-audit --no-fund --cache /tmp/luma-storage-cache --fetch-retries=0 --fetch-timeout=15000` | 0 | Added idb and updated isolated lock |
| From root: `npm --prefix experiments/0004-storage-design run check` | 0 | Exact runtime guard; rollback, injected quota policy, blocked upgrade assertions passed |
| `npm --prefix experiments/0004-storage-design ci --ignore-scripts --no-audit --no-fund --cache /tmp/luma-storage-clean-0ce544ac4b40 --fetch-retries=0 --fetch-timeout=15000` | 0 | Fresh-cache locked clean install: 2 packages |
| Same `npm --prefix ... run check` after clean install | 0 | All focused assertions passed again |
| Inline Python manifest/lock/license/integrity checks | 0 | 2 packages, no transitives; exact manifest agreement, HTTPS/SHA512, ISC/Apache-2.0 installed texts retained |
| Inline Python subprocess runs pinned node `src/check-runtime.mjs` without npm context | 0 wrapper | Child exit 1 expected and asserted; refuses absent pinned npm context |
| `make check > /tmp/luma-S00-005-check.log 2>&1` | 0 | Foundation validation and tooling tests passed; counts below |
| `git diff --check`, scoped `git diff`/`git status --short --untracked-files=all` | 0 | Only allowed experiment/ADR and workflow metadata; no tracked whitespace issues |
Primary sources opened through web tool: idb upstream README (transactions,
completion, lifecycle/typed API), Dexie design, IndexedDB and Storage standards,
WebKit storage policy, fake-indexeddb upstream README. Exact links/date in ADR.
Registry web-page fetches for latest idb/Dexie returned internal error; successful
normal-TLS npm registry metadata and locked package inspection supplied exact pins.
No TLS bypass, secret or production transport involved.
One setup error: npm install was initially invoked from project root instead of
the experiment. npm resolved an ancestor prefix and was denied writing
/home/tola/package-lock.json (EROFS, exit 226). No outside file was created or
permissions changed. Correct experiment-directory invocation succeeded. Initial
apply_patch attempted delete/add on the same rollback path and was rejected
without applying; the subsequent scoped file rewrite succeeded. Guessed future
persistence contract and optional experiment .gitignore reads returned missing;
their absence is not missing required input. Root .gitignore already excludes
node_modules and logs.
## Acceptance evidence and limitations
Rollback observes actual ConstraintError and AbortError, exact v1 data, absence
of migrated store/index, successful v2 retry/query and connection reopen. Quota
injection occurs after successful history/checkpoint requests and verifies saved
false, no history or checkpoint advancement, account B history/settings/opaque
crypto fixture preservation, followed by successful retry. Blocked upgrade is
observed before upgrade executes; closing the old connection allows v2 and stale
v1 fails. These execute the selected idb wrapper against fake-indexeddb.
Cua browser inventory returned apps=[] and browsers=[]. No native browser test
ran. In-memory reopen is not process/crash restart. Injected QuotaExceededError
does not prove browser quota generation at request/commit; physical disk failure,
eviction, browser multi-tab behavior, StorageManager grants, account deletion/
suppression and real crypto state are not verified. ADR/README preserve these
external and downstream checks. fake-indexeddb is explicitly test-only and no
production fallback was added. No vulnerability/provenance audit or app readiness
claim. Independent QA must reproduce focused checks and assess the policy/limits.
Coordinator owns Git and next process; executor stops immediately after submit.
Final foundation result: 296 tasks, 22 stages, 221 requirements, 211 allocated Web
requirements, revision 116; 72 tests passed in 18.889s. Separate
`python3 scripts/tasks.py validate` returned exit 0 with the same counts.
Lockfile SHA256: c6c416a92b1a3d10e3fb83bcdbbc803114adbd1dd24e06f5dceebb4b59f9ea7b.
+28 -5
View File
@@ -1,9 +1,32 @@
# S00-005 handoff for independent QA
Executor: auto-storage-0ce544ac4b40 (storage), 2026-10-15.
Outcome: proposed ADR 0004 selects idb 8.0.4 and defines transaction, quota,
migration/connection and crypto key ownership policy. Scoped experiment now
executes rollback, explicit quota-failure policy and blocked upgrade scenarios.
Historical interrupted work was resumed only after independently reviewed S00-023;
RECOVERY.md remains a historical inventory, not current test status.
# Blocked handoff
QA input: docs/decisions/0004-storage-design.md, experiment README, exact lock/
license texts and src checks; full executor evidence at
state/evidence/S00-005-auto-storage-0ce544ac4b40.md. Verify source scope and
executor message, reproduce fresh-cache npm ci and npm run check on accepted
Node 24.21.0/npm 11.19.0. Linux runtime used here:
/tmp/luma-approved-toolchain/node-v24.21.0-linux-x64/bin.
The wrapper lock digest is c6c416a92b1a3d10e3fb83bcdbbc803114adbd1dd24e06f5dceebb4b59f9ea7b.
Original: S00-005; reporter: auto-storage-88c3286c6641; resolution: S00-023.
Actual results: fresh-cache install and selected-wrapper fixture checks exit 0;
make check exit 0 (296 tasks, 72 tooling tests). Foundation checks are not app
readiness. Rollback now causes actual unique-index ConstraintError, validates
schema/data restoration, retry and same-process reopen. Injected quota failure
aborts history/checkpoint together and preserves account B. Held old connection
produces versionchange/blocked, closes to release v2, and stale v1 is refused.
Previous runner session was interrupted before submit/escalate; processes stopped. User now explicitly requests resuming development. Preserve partial artifacts, verify them in a fresh bounded remediation, and return original to a new executor only after independent review.
Next: complete and review the remediation; only a fresh session may continue.
Limits: browser inventory empty. Quota is an explicit injected error; no native
quota exhaustion, disk durability, process restart, eviction, real multi-tab,
persistence grants, deletion/suppression or crypto-unlock test was run. Fixtures
are synthetic and test-only. S01 contracts remain future work; no app schema/
port/adapter was introduced. ADR remains proposed until independent acceptance.
If QA accepts, record ADR acceptance metadata within its allowed scope and
separate review evidence, then approve via CLI. Coordinator alone commits and
launches another fresh session. Executor exits immediately after submit.
+30 -6
View File
@@ -1,6 +1,6 @@
{
"schema_version": 1,
"revision": 115,
"revision": 117,
"tasks": {
"S00-001": {
"status": "done",
@@ -64,17 +64,18 @@
"resumed_after_blocker": true
},
"S00-005": {
"status": "todo",
"owner": null,
"started_at": "2026-10-15T09:15:46+00:00",
"status": "review",
"owner": "auto-storage-0ce544ac4b40",
"started_at": "2026-10-15T11:26:11+00:00",
"reason": null,
"updated_at": "2026-10-15T11:09:33+00:00",
"updated_at": "2026-10-15T11:33:09+00:00",
"blocked_by": [],
"resume_status": "in_progress",
"blocker_report": "state/blockers/S00-023.md",
"handoff": "state/handoffs/S00-005.md",
"previous_owner": "auto-storage-88c3286c6641",
"resumed_after_blocker": true
"resumed_after_blocker": true,
"evidence": "state/evidence/S00-005-auto-storage-0ce544ac4b40.md"
},
"S00-006": {
"status": "todo",
@@ -2940,6 +2941,29 @@
"to": "done",
"reason": null,
"evidence": "state/evidence/S00-003-review.md"
},
{
"revision": 116,
"at": "2026-10-15T11:26:11+00:00",
"action": "claim",
"task": "S00-005",
"agent": "auto-storage-0ce544ac4b40",
"role": "storage",
"from": "todo",
"to": "in_progress",
"reason": null
},
{
"revision": 117,
"at": "2026-10-15T11:33:09+00:00",
"action": "submit",
"task": "S00-005",
"agent": "auto-storage-0ce544ac4b40",
"role": null,
"from": "in_progress",
"to": "review",
"reason": null,
"evidence": "state/evidence/S00-005-auto-storage-0ce544ac4b40.md"
}
],
"retired_agents": [