@qvac/core 0.11.3 → 0.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -13,6 +13,34 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.11.4] - 2026-10-30
17
+
18
+ ### Changed
19
+
20
+ - A `mesh write` or `mesh drain` stall now keeps reporting while it lasts (#649). Each `… still pending`
21
+ line carries `reports` (1, 2, 3 …), and the wait doubles between reports. It also names:
22
+ - `fastForwarding`: the head a fast-forward is booting onto, with how much of that core this
23
+ device and its peers hold, or `null`.
24
+ - `peerLength` and `peerHeld` on every `missing` core: how far the furthest connected peer
25
+ knows that core, and how much of it that peer holds from block 0.
26
+ - `writers` on a mesh still joining: each writer it knows, with the same holdings.
27
+ - The logs now name the build and what an open did to an older mesh (#650):
28
+ - `core opening` is the first line of a launch. It names the app's `version`, `build` and
29
+ `channel`, and the mesh `schema` this core applies. A mesh's own `opening` line names the
30
+ `schema` too.
31
+ - `migrations ran` follows each pass on open. It lists the steps that wrote, each step's `ms`,
32
+ and the step that threw as `failed`. A pass still going after 15 s logs
33
+ `migrations still running` with its current step, again after 30 s, 60 s, and so on.
34
+ - `copied chats into chat-chunks` and `recorded the files the mesh already held` give each
35
+ backfill's count and `ms`.
36
+
37
+ ### Fixed
38
+
39
+ - The assistant no longer logs `saveDeviceCapabilities failed` while the account mesh is still
40
+ joining. Core refuses the report with `MESH_STILL_JOINING` until this device is a writer, and the
41
+ assistant already reports again once the account turns writable, so the refusal was never a
42
+ failure. (#648)
43
+
16
44
  ## [0.11.3] - 2026-10-28
17
45
 
18
46
  ### Added
@@ -2088,7 +2116,8 @@ Published under the `release-0.1` dist-tag.
2088
2116
  await assistant.ready()
2089
2117
  ```
2090
2118
 
2091
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.3...HEAD
2119
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.4...HEAD
2120
+ [0.11.4]: https://github.com/tetherto/qvac-core/compare/v0.11.3...v0.11.4
2092
2121
  [0.11.3]: https://github.com/tetherto/qvac-core/compare/v0.11.2...v0.11.3
2093
2122
  [0.11.2]: https://github.com/tetherto/qvac-core/compare/v0.11.1...v0.11.2
2094
2123
  [0.11.1]: https://github.com/tetherto/qvac-core/compare/v0.11.0...v0.11.1
@@ -700,7 +700,7 @@ export class QvacAssistant extends ReadyResource {
700
700
  this._lastCapabilities.set(meshId, key);
701
701
  }
702
702
  catch (err) {
703
- if (isCoreError(err, 'MESH_NOT_FOUND')) {
703
+ if (isCoreError(err, 'MESH_NOT_FOUND') || isCoreError(err, 'MESH_STILL_JOINING')) {
704
704
  return;
705
705
  }
706
706
  this._log?.error('assistant', 'saveDeviceCapabilities failed', err);
@@ -45,6 +45,7 @@ export interface MeshOptions {
45
45
  slowWriteMs?: number;
46
46
  slowDrainMs?: number;
47
47
  }
48
+ export declare const SCHEMA_VERSION: number;
48
49
  export declare function meshPublicKeyFromSeed(seed: Buffer): Buffer;
49
50
  export interface TrustScope {
50
51
  readonly ourMemberId: Buffer | null;
@@ -178,6 +179,8 @@ export declare class Mesh extends ReadyResource {
178
179
  private _watchStall;
179
180
  private _endStall;
180
181
  private _reportStall;
182
+ private _fastForwardHeld;
183
+ private _writersHeld;
181
184
  private _coresNotHeld;
182
185
  private _coreHeld;
183
186
  batch(): MeshBatch;
@@ -8,7 +8,7 @@ import crypto from 'hypercore-crypto';
8
8
  import ReadyResource from 'ready-resource';
9
9
  import { Files } from './files/index.js';
10
10
  import MeshDefinition from '../../spec/mesh/hyperdb/index.js';
11
- import { Router, encode } from '../../spec/mesh/hyperdispatch/index.js';
11
+ import { Router, encode, version } from '../../spec/mesh/hyperdispatch/index.js';
12
12
  import { syncChanges } from './sync/index.js';
13
13
  import { ViewUpdates } from './sync/view-updates.js';
14
14
  import { buildDefaultSeed, isOwnKickedRow, isOwnRevokedRow } from './helpers/index.js';
@@ -25,6 +25,7 @@ import { errorMessage, isRecord } from '../guards.js';
25
25
  import { CoreError } from '../errors.js';
26
26
  import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS, MESH_NAMES } from './collections.js';
27
27
  const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('qvac-assistant/mesh', 3);
28
+ export const SCHEMA_VERSION = version;
28
29
  const SLOW_WRITE_MS = 5000;
29
30
  const SLOW_DRAIN_MS = 15_000;
30
31
  export function meshPublicKeyFromSeed(seed) {
@@ -264,6 +265,7 @@ export class Mesh extends ReadyResource {
264
265
  async _open() {
265
266
  this._openedAt = Date.now();
266
267
  this._log?.info(this._scope, 'opening', {
268
+ schema: SCHEMA_VERSION,
267
269
  creator: this._key === null,
268
270
  compute: this._compute,
269
271
  bootFrom: this._bootFrom?.length ?? null,
@@ -461,25 +463,33 @@ export class Mesh extends ReadyResource {
461
463
  }
462
464
  async _watchStall(pending, watch) {
463
465
  const started = Date.now();
464
- let reported = false;
465
- const timer = setTimeout(() => {
466
- if (this._stallReported) {
467
- return;
468
- }
469
- this._stallReported = true;
470
- reported = true;
471
- this._reportStall(watch, started).catch(noop);
472
- }, watch.ms);
466
+ const clock = { reports: 0, timer: null };
467
+ const report = (wait) => {
468
+ clock.timer = setTimeout(() => {
469
+ if (!this.closing) {
470
+ report(wait * 2);
471
+ }
472
+ if (clock.reports === 0 && this._stallReported) {
473
+ return;
474
+ }
475
+ this._stallReported = true;
476
+ clock.reports++;
477
+ this._reportStall(watch, { started, reports: clock.reports }).catch(noop);
478
+ }, wait);
479
+ };
480
+ report(watch.ms);
473
481
  try {
474
482
  await pending;
475
- this._endStall(watch, { reported, started, failed: false });
483
+ this._endStall(watch, { reported: clock.reports > 0, started, failed: false });
476
484
  }
477
485
  catch (err) {
478
- this._endStall(watch, { reported, started, failed: true, err });
486
+ this._endStall(watch, { reported: clock.reports > 0, started, failed: true, err });
479
487
  throw err;
480
488
  }
481
489
  finally {
482
- clearTimeout(timer);
490
+ if (clock.timer) {
491
+ clearTimeout(clock.timer);
492
+ }
483
493
  }
484
494
  }
485
495
  _endStall({ what, op }, { reported, started, failed, err }) {
@@ -495,23 +505,39 @@ export class Mesh extends ReadyResource {
495
505
  this._log?.info(this._scope, `${what} settled`, { op, ms });
496
506
  }
497
507
  }
498
- async _reportStall({ what, op }, started) {
499
- const { stats, system } = this.autobee;
508
+ async _reportStall({ what, op }, { started, reports }) {
509
+ const { stats, system, writable } = this.autobee;
500
510
  const missing = await this._coresNotHeld([system.bee, this.autobee.bee]).catch(noop);
511
+ const fastForwarding = await this._fastForwardHeld().catch(noop);
512
+ const writers = writable ? undefined : await this._writersHeld().catch(noop);
501
513
  this._log?.warn(this._scope, `${what} still pending`, {
502
514
  op,
515
+ reports,
503
516
  afterMs: Date.now() - started,
504
- writable: this.autobee.writable,
517
+ writable,
505
518
  interrupted: !!this.autobee.interrupted,
506
519
  drains: stats.drains,
507
520
  applies: stats.applies,
508
521
  appends: stats.appends,
509
522
  fastForwards: stats.fastForwards,
523
+ fastForwarding,
510
524
  localLength: this.autobee.local.length,
511
525
  missing,
526
+ writers,
512
527
  blindPeers: this.blindPeerStats()
513
528
  });
514
529
  }
530
+ async _fastForwardHeld() {
531
+ const ff = this.autobee.fastForwarding;
532
+ if (!ff) {
533
+ return null;
534
+ }
535
+ return { to: ff.head.length, ...(await this._coreHeld(ff.head.key)) };
536
+ }
537
+ async _writersHeld() {
538
+ const writers = [...this.autobee.activeWriters];
539
+ return Promise.all(writers.map((writer) => this._coreHeld(writer.core.key)));
540
+ }
515
541
  async _coresNotHeld(views) {
516
542
  const keys = new Map();
517
543
  for (const { context } of views) {
@@ -526,11 +552,14 @@ export class Mesh extends ReadyResource {
526
552
  const core = this._store.get({ key, active: false });
527
553
  try {
528
554
  await core.ready();
555
+ const reach = core.peers.map(remoteReach);
529
556
  return {
530
557
  key: b4a.toHex(key).slice(0, 8),
531
558
  length: core.length,
532
559
  held: core.contiguousLength,
533
- peers: core.peers.length
560
+ peers: core.peers.length,
561
+ peerLength: Math.max(0, ...reach.map((peer) => peer.length)),
562
+ peerHeld: Math.max(0, ...reach.map((peer) => peer.held))
534
563
  };
535
564
  }
536
565
  finally {
@@ -951,6 +980,15 @@ export class MeshBatch {
951
980
  }
952
981
  }
953
982
  function noop() { }
983
+ function remoteReach(peer) {
984
+ if (!isRecord(peer)) {
985
+ return { length: 0, held: 0 };
986
+ }
987
+ return {
988
+ length: typeof peer.remoteLength === 'number' ? peer.remoteLength : 0,
989
+ held: typeof peer.remoteContiguousLength === 'number' ? peer.remoteContiguousLength : 0
990
+ };
991
+ }
954
992
  function viewCoreOf(head) {
955
993
  return isRecord(head) && b4a.isBuffer(head.key) ? b4a.toHex(head.key).slice(0, 8) : null;
956
994
  }
@@ -1,2 +1,2 @@
1
1
  import type { Mesh } from '../mesh.ts';
2
- export declare function backfillFileIndex(mesh: Mesh): Promise<void>;
2
+ export declare function backfillFileIndex(mesh: Mesh): Promise<number>;
@@ -3,26 +3,30 @@ const BATCH = 256;
3
3
  export async function backfillFileIndex(mesh) {
4
4
  const index = mesh.fileIndex;
5
5
  if (!index) {
6
- return;
6
+ return 0;
7
7
  }
8
8
  const snapshot = mesh.view.snapshot();
9
+ let recorded = 0;
9
10
  try {
10
11
  let batch = [];
11
12
  for await (const chunk of attachmentChunks(snapshot)) {
12
13
  if (mesh.closing)
13
- return;
14
+ return recorded;
14
15
  batch.push(chunk);
15
16
  if (batch.length < BATCH) {
16
17
  continue;
17
18
  }
18
19
  await index.record(batch);
20
+ recorded += batch.length;
19
21
  batch = [];
20
22
  }
21
23
  if (batch.length > 0) {
22
24
  await index.record(batch);
25
+ recorded += batch.length;
23
26
  }
24
27
  }
25
28
  finally {
26
29
  await snapshot.close();
27
30
  }
31
+ return recorded;
28
32
  }
@@ -4,5 +4,6 @@ import { type MembershipMigrationContext } from './membership.ts';
4
4
  export type MigrationContext = MembershipMigrationContext & AgentCatalogMigrationContext;
5
5
  export interface RunMigrationsOptions {
6
6
  readonly catalog?: boolean;
7
+ readonly slowMs?: number;
7
8
  }
8
- export declare function runMigrations(mesh: Mesh, context: MigrationContext, { catalog }?: RunMigrationsOptions): Promise<boolean>;
9
+ export declare function runMigrations(mesh: Mesh, context: MigrationContext, { catalog, slowMs }?: RunMigrationsOptions): Promise<boolean>;
@@ -1,15 +1,72 @@
1
+ import b4a from 'b4a';
1
2
  import { migrateAgentCatalog } from './agent-catalog.js';
2
3
  import { migrateAgentToolsScope } from './agent-tools-scope.js';
3
4
  import { migrateMembership } from './membership.js';
4
5
  import { sealDeviceRows } from './seal.js';
5
6
  import { reindexAgents } from './agent-indexes.js';
6
7
  import { reindexDevices } from './device-indexes.js';
7
- export async function runMigrations(mesh, context, { catalog = true } = {}) {
8
- const devices = await reindexDevices(mesh);
9
- const membership = await migrateMembership(mesh, context);
10
- const agents = catalog && (await migrateAgentCatalog(mesh, context));
11
- const seal = await sealDeviceRows(mesh, context);
12
- const indexed = await reindexAgents(mesh);
13
- const tools = await migrateAgentToolsScope(mesh);
14
- return devices || membership || agents || seal || indexed || tools;
8
+ const SLOW_MIGRATIONS_MS = 15_000;
9
+ export async function runMigrations(mesh, context, { catalog = true, slowMs = SLOW_MIGRATIONS_MS } = {}) {
10
+ const steps = [
11
+ { name: 'reindex-devices', migrate: () => reindexDevices(mesh) },
12
+ { name: 'membership', migrate: () => migrateMembership(mesh, context) },
13
+ ...(catalog
14
+ ? [{ name: 'agent-catalog', migrate: () => migrateAgentCatalog(mesh, context) }]
15
+ : []),
16
+ { name: 'seal', migrate: () => sealDeviceRows(mesh, context) },
17
+ { name: 'reindex-agents', migrate: () => reindexAgents(mesh) },
18
+ { name: 'agent-tools-scope', migrate: () => migrateAgentToolsScope(mesh) }
19
+ ];
20
+ return (await runLogged(mesh, steps, { log: context.log, wait: slowMs })).length > 0;
21
+ }
22
+ async function runLogged(mesh, steps, report) {
23
+ const run = {
24
+ mesh: b4a.toHex(mesh.key).slice(0, 8),
25
+ started: Date.now(),
26
+ step: null,
27
+ timer: null,
28
+ wrote: [],
29
+ ms: {}
30
+ };
31
+ reportWhileSlow(mesh, run, report);
32
+ try {
33
+ await runSteps(steps, run);
34
+ }
35
+ finally {
36
+ if (run.timer) {
37
+ clearTimeout(run.timer);
38
+ }
39
+ report.log?.info(['p2p', 'mesh'], 'migrations ran', {
40
+ mesh: run.mesh,
41
+ ms: Date.now() - run.started,
42
+ wrote: run.wrote,
43
+ steps: run.ms,
44
+ failed: run.step
45
+ });
46
+ }
47
+ return run.wrote;
48
+ }
49
+ async function runSteps(steps, run) {
50
+ for (const { name, migrate } of steps) {
51
+ run.step = name;
52
+ const at = Date.now();
53
+ if (await migrate()) {
54
+ run.wrote.push(name);
55
+ }
56
+ run.ms[name] = Date.now() - at;
57
+ }
58
+ run.step = null;
59
+ }
60
+ function reportWhileSlow(mesh, run, { log, wait }) {
61
+ run.timer = setTimeout(() => {
62
+ if (mesh.closing) {
63
+ return;
64
+ }
65
+ log?.warn(['p2p', 'mesh'], 'migrations still running', {
66
+ mesh: run.mesh,
67
+ step: run.step,
68
+ afterMs: Date.now() - run.started
69
+ });
70
+ reportWhileSlow(mesh, run, { log, wait: wait * 2 });
71
+ }, wait);
15
72
  }
@@ -52,7 +52,7 @@ import { forwardToDevices, servedToSiblings } from './api/device-routes.js';
52
52
  import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
53
53
  import { updateRequired } from './core/min-version.js';
54
54
  import { PendingDepartures } from './core/departures.js';
55
- import { Mesh } from './core/mesh.js';
55
+ import { Mesh, SCHEMA_VERSION } from './core/mesh.js';
56
56
  import { raceResource } from './race-resource.js';
57
57
  import { createSystemInfoSampler } from './core/system-info.js';
58
58
  import { settleOnClose } from '@qvac/harness/rpc';
@@ -345,6 +345,12 @@ export class Core extends ReadyResource {
345
345
  return [...new Set(ids)].sort();
346
346
  }
347
347
  async _open() {
348
+ this._log?.info('lifecycle', 'core opening', {
349
+ app: this._app?.version ?? null,
350
+ build: this._app?.build ?? null,
351
+ channel: this._app?.channel ?? null,
352
+ schema: SCHEMA_VERSION
353
+ });
348
354
  this._runBootOffline().catch(noop);
349
355
  this._runBootOnline().catch(noop);
350
356
  await this._offlineBoot.ready();
@@ -2611,9 +2617,15 @@ export class Core extends ReadyResource {
2611
2617
  if (await this.local.files.backfilled(mesh.key)) {
2612
2618
  return;
2613
2619
  }
2614
- await backfillFileIndex(mesh);
2620
+ const started = Date.now();
2621
+ const chunks = await backfillFileIndex(mesh);
2615
2622
  if (!mesh.closing) {
2616
2623
  await this.local.files.markBackfilled(mesh.key);
2624
+ this._log?.info(['files'], 'recorded the files the mesh already held', {
2625
+ mesh: b4a.toHex(mesh.key).slice(0, 8),
2626
+ chunks,
2627
+ ms: Date.now() - started
2628
+ });
2617
2629
  }
2618
2630
  }
2619
2631
  catch (err) {
@@ -2629,7 +2641,13 @@ export class Core extends ReadyResource {
2629
2641
  try {
2630
2642
  await mesh.waitForWritable();
2631
2643
  await mesh.autobee.update();
2632
- await backfillChatChunks(mesh);
2644
+ const started = Date.now();
2645
+ const copied = await backfillChatChunks(mesh);
2646
+ this._log?.info(['p2p', 'mesh'], 'copied chats into chat-chunks', {
2647
+ mesh: b4a.toHex(mesh.key).slice(0, 8),
2648
+ copied,
2649
+ ms: Date.now() - started
2650
+ });
2633
2651
  }
2634
2652
  catch (err) {
2635
2653
  if (!mesh.closing) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/core",
3
- "version": "0.11.3",
3
+ "version": "0.11.4",
4
4
  "type": "module",
5
5
  "description": "Peer-to-peer AI across your devices",
6
6
  "engines": {