@narumitw/pi-sync-daemon 0.5.1 → 0.6.1
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 +15 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +128 -16
- package/dist/index.d.ts +1 -1
- package/docs/architecture.md +12 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @narumitw/pi-sync-daemon
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 25eef0a: Update the runtime libraries for AgentFS shell execution, Langfuse trace export, Starship pattern matching, subagent ignore rules, and sync daemon XML parsing and glob matching.
|
|
8
|
+
|
|
9
|
+
## 0.6.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d96f85d: Retry lost file-queue release acknowledgements on the same daemon without
|
|
14
|
+
replaying transfers. Keep brief retries quiet and show a recovery status for
|
|
15
|
+
longer waits. The daemon client exposes an optional queue-release delivery
|
|
16
|
+
observer without changing the IPC protocol.
|
|
17
|
+
|
|
3
18
|
## 0.5.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -22,12 +22,20 @@ export declare function findDaemon(root: string): Promise<{
|
|
|
22
22
|
} | undefined>;
|
|
23
23
|
/** Gracefully stop an existing compatible owner without creating a new service. */
|
|
24
24
|
export declare function stopDaemon(root: string): Promise<boolean>;
|
|
25
|
+
export interface QueueReleaseDelivery {
|
|
26
|
+
id: string;
|
|
27
|
+
job: string;
|
|
28
|
+
state: "retrying" | "finished" | "unconfirmed";
|
|
29
|
+
foreground: boolean;
|
|
30
|
+
}
|
|
25
31
|
export interface ConnectionOptions {
|
|
26
32
|
callback(callback: Callback, signal: AbortSignal): Promise<unknown>;
|
|
27
33
|
event?(event: ClientEvent): void;
|
|
28
34
|
error?(error: unknown): void;
|
|
29
35
|
/** Each current background observation after admission, including repeated states. */
|
|
30
36
|
contact?(state: ContactState): void;
|
|
37
|
+
/** Observes local delivery only. Finished does not establish a job's outcome. */
|
|
38
|
+
queueRelease?(event: QueueReleaseDelivery): void;
|
|
31
39
|
}
|
|
32
40
|
export declare class DaemonConnection {
|
|
33
41
|
readonly paths: RuntimePaths;
|
|
@@ -52,6 +60,7 @@ export declare class DaemonConnection {
|
|
|
52
60
|
private reportedError;
|
|
53
61
|
private commits;
|
|
54
62
|
private completedCallbacks;
|
|
63
|
+
private completedReleases;
|
|
55
64
|
private pausing;
|
|
56
65
|
private disposing;
|
|
57
66
|
private polling;
|
|
@@ -71,6 +80,8 @@ export declare class DaemonConnection {
|
|
|
71
80
|
run(operation: string, payload: unknown, signal?: AbortSignal, onCommit?: () => void): Promise<unknown>;
|
|
72
81
|
private publishContact;
|
|
73
82
|
private consume;
|
|
83
|
+
private reportRelease;
|
|
84
|
+
private deliverRelease;
|
|
74
85
|
private performCallback;
|
|
75
86
|
private wait;
|
|
76
87
|
private reportError;
|
package/dist/client.js
CHANGED
|
@@ -323,6 +323,11 @@ export async function stopDaemon(root) {
|
|
|
323
323
|
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
+
const MAX_COMPLETED_CALLBACKS = 4096;
|
|
327
|
+
const RELEASE_ATTEMPT_MS = 2_000;
|
|
328
|
+
const RELEASE_BUDGET_MS = 25_000;
|
|
329
|
+
const RELEASE_MAX_ATTEMPTS = 20;
|
|
330
|
+
const TRANSIENT_RELEASE_ERRORS = new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ENOENT", "ETIMEDOUT", "EAGAIN"]);
|
|
326
331
|
export class DaemonConnection {
|
|
327
332
|
paths;
|
|
328
333
|
identity;
|
|
@@ -341,11 +346,15 @@ export class DaemonConnection {
|
|
|
341
346
|
lifecycleRevision = 0;
|
|
342
347
|
resuming;
|
|
343
348
|
resumeUncertain = false;
|
|
344
|
-
pendingJobs =
|
|
349
|
+
pendingJobs = new Set();
|
|
345
350
|
uncertain = false;
|
|
346
351
|
reportedError = false;
|
|
347
352
|
commits = new Map();
|
|
348
353
|
completedCallbacks = new Set();
|
|
354
|
+
// Keep drain answers deduplicated even after the lifetime callback ledger fills.
|
|
355
|
+
// The daemon limits each peer to 64 pending callbacks. A newer snapshot retires
|
|
356
|
+
// releases it no longer lists, and older snapshots cannot add them back.
|
|
357
|
+
completedReleases = new Set();
|
|
349
358
|
pausing;
|
|
350
359
|
disposing;
|
|
351
360
|
polling;
|
|
@@ -366,7 +375,7 @@ export class DaemonConnection {
|
|
|
366
375
|
}
|
|
367
376
|
/** Original submitted jobs must finish (or be reconciled) before repairing contact. */
|
|
368
377
|
get hasPendingWork() {
|
|
369
|
-
return this.pendingJobs > 0 || this.uncertain;
|
|
378
|
+
return this.pendingJobs.size > 0 || this.uncertain;
|
|
370
379
|
}
|
|
371
380
|
async attach(signal) {
|
|
372
381
|
if (this.closed ||
|
|
@@ -520,8 +529,8 @@ export class DaemonConnection {
|
|
|
520
529
|
this.contactState === "inactive")
|
|
521
530
|
throw new Error("Daemon client is unavailable; confirm contact and drain work before submitting.");
|
|
522
531
|
signal?.throwIfAborted();
|
|
523
|
-
this.pendingJobs++;
|
|
524
532
|
const id = `${operationPrefix(this.identity)}${randomUUID()}`;
|
|
533
|
+
this.pendingJobs.add(id);
|
|
525
534
|
const abort = () => {
|
|
526
535
|
void requestDaemon(this.paths, this.identity, "cancel", { id, client: this.facts.id }, this.controller.signal).catch(() => { });
|
|
527
536
|
};
|
|
@@ -567,7 +576,7 @@ export class DaemonConnection {
|
|
|
567
576
|
throw new Error("Operation outcome is uncertain; reload to reconnect and reconcile, never replay the write.", { cause: error });
|
|
568
577
|
}
|
|
569
578
|
}
|
|
570
|
-
}).finally(() => this.pendingJobs
|
|
579
|
+
}).finally(() => this.pendingJobs.delete(id));
|
|
571
580
|
}
|
|
572
581
|
publishContact(contact) {
|
|
573
582
|
this.contactRevision++;
|
|
@@ -596,18 +605,44 @@ export class DaemonConnection {
|
|
|
596
605
|
}
|
|
597
606
|
this.options.event?.(event);
|
|
598
607
|
}
|
|
599
|
-
|
|
608
|
+
const latest = reply.cursor >= this.cursor;
|
|
600
609
|
const present = new Set(reply.callbacks.map((callback) => callback.id));
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
610
|
+
if (reply.cursor > this.cursor) {
|
|
611
|
+
for (const id of this.completedReleases)
|
|
612
|
+
if (!present.has(id))
|
|
613
|
+
this.completedReleases.delete(id);
|
|
614
|
+
this.cursor = reply.cursor;
|
|
615
|
+
}
|
|
616
|
+
for (const [id, pending] of this.callbacks) {
|
|
617
|
+
if (pending.releaseCursor !== undefined) {
|
|
618
|
+
// A job poll and the background poll can arrive out of order.
|
|
619
|
+
if (!latest || reply.cursor <= pending.releaseCursor)
|
|
620
|
+
continue;
|
|
621
|
+
if (present.has(id)) {
|
|
622
|
+
pending.releaseCursor = reply.cursor;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
else if (present.has(id))
|
|
627
|
+
continue;
|
|
628
|
+
pending.controller.abort(new DOMException("Callback is no longer current", "AbortError"));
|
|
629
|
+
}
|
|
604
630
|
for (const callback of reply.callbacks) {
|
|
605
631
|
if (this.callbacks.has(callback.id) || this.completedCallbacks.has(callback.id))
|
|
606
632
|
continue;
|
|
607
|
-
|
|
633
|
+
const release = callback.kind === "queue-release";
|
|
634
|
+
if (release && (!latest || this.completedReleases.has(callback.id)))
|
|
635
|
+
continue;
|
|
636
|
+
if (this.completedCallbacks.size + this.callbacks.size >= MAX_COMPLETED_CALLBACKS)
|
|
608
637
|
this.uncertain = true;
|
|
609
638
|
const controller = new AbortController();
|
|
610
|
-
this.
|
|
639
|
+
const foreground = this.pendingJobs.has(callback.job);
|
|
640
|
+
this.callbacks.set(callback.id, {
|
|
641
|
+
controller,
|
|
642
|
+
kind: callback.kind,
|
|
643
|
+
job: callback.job,
|
|
644
|
+
...(release && { releaseCursor: reply.cursor }),
|
|
645
|
+
});
|
|
611
646
|
const task = (async () => {
|
|
612
647
|
let value;
|
|
613
648
|
let failed = false;
|
|
@@ -619,19 +654,34 @@ export class DaemonConnection {
|
|
|
619
654
|
catch {
|
|
620
655
|
failed = true;
|
|
621
656
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
657
|
+
if (release) {
|
|
658
|
+
if (!failed && value === true) {
|
|
659
|
+
await this.deliverRelease(callback, foreground, controller.signal);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
failed = true;
|
|
663
|
+
}
|
|
664
|
+
try {
|
|
665
|
+
await requestDaemon(this.paths, this.identity, "answer", {
|
|
666
|
+
client: this.facts.id,
|
|
667
|
+
id: callback.id,
|
|
668
|
+
...(failed ? { error: "Client callback cancelled or failed." } : { value }),
|
|
669
|
+
}, this.callbackIO.signal);
|
|
670
|
+
}
|
|
671
|
+
finally {
|
|
672
|
+
if (release)
|
|
673
|
+
this.reportRelease(callback, foreground, "unconfirmed");
|
|
674
|
+
}
|
|
627
675
|
})()
|
|
628
676
|
.catch((error) => {
|
|
629
677
|
if (!this.closed && !controller.signal.aborted)
|
|
630
678
|
this.reportError(error);
|
|
631
679
|
})
|
|
632
680
|
.finally(() => {
|
|
633
|
-
if (this.completedCallbacks.size <
|
|
681
|
+
if (this.completedCallbacks.size < MAX_COMPLETED_CALLBACKS)
|
|
634
682
|
this.completedCallbacks.add(callback.id);
|
|
683
|
+
else if (release && !controller.signal.aborted)
|
|
684
|
+
this.completedReleases.add(callback.id);
|
|
635
685
|
this.callbacks.delete(callback.id);
|
|
636
686
|
this.callbackTasks.delete(task);
|
|
637
687
|
});
|
|
@@ -639,6 +689,68 @@ export class DaemonConnection {
|
|
|
639
689
|
}
|
|
640
690
|
return contact;
|
|
641
691
|
}
|
|
692
|
+
reportRelease(callback, foreground, state) {
|
|
693
|
+
if (this.callbackIO.signal.aborted)
|
|
694
|
+
return;
|
|
695
|
+
try {
|
|
696
|
+
this.options.queueRelease?.({ id: callback.id, job: callback.job, foreground, state });
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
// Presentation must not own a queue or a callback task.
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
async deliverRelease(callback, foreground, pending) {
|
|
703
|
+
const signal = AbortSignal.any([pending, this.callbackIO.signal]);
|
|
704
|
+
const deadline = performance.now() + RELEASE_BUDGET_MS;
|
|
705
|
+
let retrying = false;
|
|
706
|
+
let state = "unconfirmed";
|
|
707
|
+
try {
|
|
708
|
+
for (let attempt = 0; attempt < RELEASE_MAX_ATTEMPTS; attempt++) {
|
|
709
|
+
const remaining = Math.floor(deadline - performance.now());
|
|
710
|
+
if (remaining <= 0 || signal.aborted)
|
|
711
|
+
break;
|
|
712
|
+
const controller = new AbortController();
|
|
713
|
+
const timer = setTimeout(() => controller.abort(), Math.min(remaining, RELEASE_ATTEMPT_MS));
|
|
714
|
+
timer.unref?.();
|
|
715
|
+
try {
|
|
716
|
+
await requestDaemon(this.paths, this.identity, "answer", { client: this.facts.id, id: callback.id, value: true }, AbortSignal.any([signal, controller.signal]));
|
|
717
|
+
state = "finished";
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
if (signal.aborted)
|
|
722
|
+
break;
|
|
723
|
+
if (error instanceof DaemonError) {
|
|
724
|
+
// The v1 server uses this reply for absent as well as foreign callbacks.
|
|
725
|
+
// Do not infer whether the original release succeeded.
|
|
726
|
+
if (error.message === "Stale or foreign callback response.")
|
|
727
|
+
state = "finished";
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (!controller.signal.aborted &&
|
|
731
|
+
(!(error instanceof Error) || !TRANSIENT_RELEASE_ERRORS.has(error.code ?? "")))
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
finally {
|
|
735
|
+
clearTimeout(timer);
|
|
736
|
+
}
|
|
737
|
+
if (!retrying) {
|
|
738
|
+
retrying = true;
|
|
739
|
+
this.reportRelease(callback, foreground, "retrying");
|
|
740
|
+
}
|
|
741
|
+
const wait = Math.min(100 * 2 ** attempt, 2_000, deadline - performance.now());
|
|
742
|
+
if (wait <= 0 || attempt + 1 >= RELEASE_MAX_ATTEMPTS)
|
|
743
|
+
break;
|
|
744
|
+
await delay(wait, undefined, { signal, ref: false }).catch(() => { });
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
finally {
|
|
748
|
+
if (pending.aborted && !this.callbackIO.signal.aborted)
|
|
749
|
+
state = "finished";
|
|
750
|
+
if (retrying || state === "unconfirmed")
|
|
751
|
+
this.reportRelease(callback, foreground, state);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
642
754
|
async performCallback(callback, signal) {
|
|
643
755
|
const reference = callback.review;
|
|
644
756
|
if (!reference)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ConnectionOptions } from "./client.js";
|
|
1
|
+
export type { ConnectionOptions, QueueReleaseDelivery } from "./client.js";
|
|
2
2
|
export { DaemonConnection, DaemonError, ensureDaemon, findDaemon, requestDaemon, stopDaemon, waitForDaemonExit, } from "./client.js";
|
|
3
3
|
export type { DocumentView } from "./document.js";
|
|
4
4
|
export { documentFingerprint } from "./document.js";
|
package/docs/architecture.md
CHANGED
|
@@ -169,6 +169,18 @@ Acquire target queues in deterministic client-ID and canonical-target order. Eac
|
|
|
169
169
|
|
|
170
170
|
Batch reservations cover the transaction, not only each rename. `Execution.withParticipants()` fences attach publication from the peer snapshot through every grant, nested write, and acknowledged release. Nested reservations share that fence instead of reacquiring it. An attach queued behind an apply cannot finish startup until the reservation ends; the next batch includes that client. Cancelled waiters cannot publish later, and shutdown drains admission. Attach has no idle request timeout: a legitimate long apply must not let startup escape the fence. Transport disconnection cancels queued admission, and the Pi adapter pauses or disposes its partial connection without waiting for attach to finish. Other local requests retain their timeout. Monitoring hooks run outside the fence because they can await a queued background reservation.
|
|
171
171
|
|
|
172
|
+
When Pi successfully releases a queue, `DaemonConnection` can resend the same
|
|
173
|
+
`answer` after a transient local transport failure. It does not rerun the
|
|
174
|
+
release callback, replay the job, or switch owners. The original daemon
|
|
175
|
+
queue deadline and admission fence stay in force. A newer poll that no longer
|
|
176
|
+
lists the callback, or a stale-answer rejection, ends delivery without
|
|
177
|
+
proving that the job succeeded. Explicit release failures are not retried.
|
|
178
|
+
If the connection reaches its callback history limit, it blocks new work but
|
|
179
|
+
still drains pending queue releases. It keeps their completed IDs only until
|
|
180
|
+
a newer daemon snapshot no longer lists them.
|
|
181
|
+
The optional local `queueRelease` observer reports delivery activity only;
|
|
182
|
+
there is no v1 wire change.
|
|
183
|
+
|
|
172
184
|
Nested writes retain the transaction's queue ownership. Validate paths and canonical parents before reservation and recheck session protection and preimages after every await that can change them. The daemon's own Pi queue alone is insufficient.
|
|
173
185
|
|
|
174
186
|
A queue grant coordinates access; it does not authorize a filesystem write. The engine owns destination selection, transfer review, path preflight, and session protection. A reviewed session destination can be outside the agent directory and every participant's current session root. Each client must reserve those bounded absolute canonical targets without imposing a second current-root policy. Otherwise a directional root transition or a peer with a different session root can block an otherwise valid transfer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-sync-daemon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A local synchronization daemon with a versioned client API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@earendil-works/pi-ai": "^1.5.2",
|
|
39
39
|
"@earendil-works/pi-coding-agent": "^1.5.2",
|
|
40
40
|
"@earendil-works/pi-tui": "^1.5.2",
|
|
41
|
-
"fast-xml-parser": "^5.12.
|
|
42
|
-
"minimatch": "^11.0.
|
|
41
|
+
"fast-xml-parser": "^5.12.1",
|
|
42
|
+
"minimatch": "^11.0.9",
|
|
43
43
|
"proper-lockfile": "^4.1.2",
|
|
44
44
|
"semver": "^7.8.6"
|
|
45
45
|
},
|