Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop legacy-stripped peer pushes from re-firing the same rejected request every cycle (#3928)
[._.]/ Adam Eivyf85d9bb48798
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 2bc8c2451b..bafd61c9dd 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -67,3 +67,4 @@- The Vite dev server example in `docs/PM2.md` no longer tells you to point PM2 at `node_modules/.bin/vite`. PM2 resolves a relative `script` against its own working directory rather than the app's `cwd`, and the `.bin` entry itself varies by platform and package manager (symlink, `.cmd`/`.ps1` wrapper, generated shell script), none of which the Node interpreter launches uniformly — so a config copy-pasted from the doc crashed on startup. Both the standalone snippet and the complete monorepo example now use the absolute `path.join(__dirname, 'client', 'node_modules', 'vite', 'bin', 'vite.js')` form that PortOS's own `portos-ui` app has always used, with a note explaining why.- A failed URL import in the SongBook importer no longer leaves the form looking untouched. The error had only a transient toast behind it, so once it faded the URL still sat in the input with no preview, no explanation, and a Save button that answered with the unrelated "Nothing to save — paste or fetch a tab first". The From URL tab now keeps an inline alert under the input naming the failure with a Retry button next to it, clears that alert as soon as the URL is edited, and drops any previously fetched draft (and the title/artist it auto-filled) so a failed fetch can't leave the earlier song previewed under a URL that never loaded. The disabled Save button now says why it's disabled instead of waiting for the click. A result that lands after the URL has been edited (or after the user has left the tab) is discarded rather than written under whatever is on screen now.- The Digital Twin confidence gauge is now announced to screen readers. The circular SVG ring and the per-dimension bars beneath it were plain `<div>`s with a decorative SVG inside, so assistive tech either skipped them or read the loose "72%" text node with nothing to say what it measured. The overall gauge now carries `role="meter"` with `aria-label="Digital Twin overall confidence"`, the min/max/now values, and an `aria-valuetext` pairing the percentage with its Strong/Moderate/Needs Work band; each dimension bar carries the same meter semantics under its own dimension label, and the ring SVG is marked `aria-hidden` so its geometry isn't read twice.+- Pushing a series or music video project to a peer running an older PortOS no longer fires the same rejected request every sync cycle forever. When the older peer's strict schema rejects a newer bundled key (`manuscriptReview`, `reverseOutline`, `linkedTrack`), the sender strips it and retries — and deliberately withholds `lastPushedHash` so the stripped doc is re-sent once that peer upgrades. With nothing else recorded, the next cycle had no way to tell a settled record from a new edit, so every 60-second tick re-ran the same 400-plus-retry pair for content that had not moved. A second water-mark (`lastPushedLegacyHash`) now records what was actually delivered in stripped form, so an unchanged record short-circuits; any real edit still moves the hash and re-attempts the full push, and the `peer:online` re-probe still pushes unconditionally, which is where the stripped key finally lands after an upgrade. A pending doc the *receiver* reported (its bundled merge threw) is left un-water-marked, since that one is transient and must genuinely retry.diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex 43cf0fd2ca..64de0f14f8 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -230,6 +230,14 @@ export async function subscribePeer({ peerId, recordKind, recordId }, opts = {})updatedAt: now,lastPushedAt: null,lastPushedHash: null,+ // #3928: full-payload hash of the last push that landed ONLY after we+ // stripped a top-level key an older peer's strict schema rejects+ // (`manuscriptReview` / `reverseOutline` / `linkedTrack`).+ // `lastPushedHash` stays withheld in that case so the stripped key is+ // re-sent once the peer upgrades; this second water-mark keeps an+ // unchanged record from re-running the 400 + stripped-retry pair on+ // every sync cycle. See peerSyncPush.js `pushRecordToPeer`.+ lastPushedLegacyHash: null,// Per-(peer,record) confirmed-delivery water-mark (ms epoch). Set ONLY// when a push to this peer for THIS record lands successfully (the// receiver returned 2xx). Distinct from the per-peer tombstone ackdiff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.jsindex 8e96b465ff..52375b36e1 100644--- a/server/services/sharing/peerSync.test.js+++ b/server/services/sharing/peerSync.test.js@@ -4081,6 +4081,147 @@ describe('peerSync', () => {expect(refreshed.lastPushedHash).toBeFalsy();});+ // #3928 — the legacy-stripped water-mark. Withholding `lastPushedHash`+ // (the two tests above) is what keeps the stripped key deliverable, but+ // on its own it made EVERY subsequent cycle re-run the 400 ++ // stripped-retry pair forever. `lastPushedLegacyHash` records the full+ // payload hash we delivered in stripped form so an unchanged record+ // settles.+ const legacyRejectsKey = (key) => {+ const rejection = { ok: false, status: 400, json: async () => ({+ code: 'VALIDATION_ERROR',+ message: 'Validation failed',+ context: { details: [{ path: '', message: `Unrecognized key(s) in object: '${key}'` }] },+ }) };+ rejection.clone = () => rejection;+ return rejection;+ };+ const mockLegacyReviewPeer = () => {+ // A pre-feature peer: rejects `manuscriptReview` on every full push,+ // accepts the stripped retry.+ vi.mocked(peerFetch).mockImplementation(async (_url, init) => (+ JSON.parse(init.body).manuscriptReview+ ? legacyRejectsKey('manuscriptReview')+ : { ok: true, status: 200, json: async () => ({}) }+ ));+ };++ it('records lastPushedLegacyHash when a stripped retry lands on a legacy peer (#3928)', async () => {+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ });+ mockLegacyReviewPeer();+ const sub = await subscribePeer({+ peerId: 'peer-a', recordKind: 'series', recordId: 's1',+ }, { adoptedFromReverse: true });+ const result = await pushRecordToPeer(sub);+ expect(result.pushed).toBe(true);+ const refreshed = await findPeerSubscription('peer-a', 'series', 's1');+ // The review is still owed (hash withheld) but the delivered content+ // is water-marked so the next cycle can settle.+ expect(refreshed.lastPushedHash).toBeFalsy();+ expect(refreshed.lastPushedLegacyHash).toBe(result.hash);+ });++ it('short-circuits the next cycle as unchanged instead of re-running the 400 + retry pair (#3928)', async () => {+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ });+ mockLegacyReviewPeer();+ const sub = await subscribePeer({+ peerId: 'peer-a', recordKind: 'series', recordId: 's1',+ }, { adoptedFromReverse: true });+ await pushRecordToPeer(sub);+ expect(vi.mocked(peerFetch).mock.calls.length).toBe(2); // 400 + stripped retry+ // Next sync cycle, same content: zero HTTP.+ const second = await pushRecordToPeer(await findPeerSubscription('peer-a', 'series', 's1'));+ expect(second.pushed).toBe(false);+ expect(second.reason).toBe('unchanged-legacy-stripped');+ expect(vi.mocked(peerFetch).mock.calls.length).toBe(2);+ });++ it('re-pushes when the bundled review actually changes after a stripped push (#3928)', async () => {+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ });+ mockLegacyReviewPeer();+ const sub = await subscribePeer({+ peerId: 'peer-a', recordKind: 'series', recordId: 's1',+ }, { adoptedFromReverse: true });+ const first = await pushRecordToPeer(sub);+ const callsAfterFirst = vi.mocked(peerFetch).mock.calls.length;+ // The user resolves the comment — the review content moved, so the+ // water-mark must NOT hold the push back.+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'resolved', updatedAt: '2026-06-03T00:00:00Z' }],+ });+ const second = await pushRecordToPeer(await findPeerSubscription('peer-a', 'series', 's1'));+ expect(second.pushed).toBe(true);+ expect(second.hash).not.toBe(first.hash);+ expect(vi.mocked(peerFetch).mock.calls.length).toBe(callsAfterFirst + 2);+ const refreshed = await findPeerSubscription('peer-a', 'series', 's1');+ expect(refreshed.lastPushedLegacyHash).toBe(second.hash);+ });++ it('re-attempts the full push on a peer:online re-probe even when the legacy hash matches (#3928)', async () => {+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ });+ mockLegacyReviewPeer();+ const sub = await subscribePeer({+ peerId: 'peer-a', recordKind: 'series', recordId: 's1',+ }, { adoptedFromReverse: true });+ await pushRecordToPeer(sub);+ // The peer upgraded and came back online — it now accepts the review.+ vi.mocked(peerFetch).mockImplementation(async () => ({ ok: true, status: 200, json: async () => ({}) }));+ const upgraded = await pushRecordToPeer(+ await findPeerSubscription('peer-a', 'series', 's1'),+ { bypassSchemaCooldown: true },+ );+ expect(upgraded.pushed).toBe(true);+ const payload = JSON.parse(vi.mocked(peerFetch).mock.calls.at(-1)[1].body);+ expect(payload.manuscriptReview).toBeDefined();+ // Fully delivered → the normal hash takes over and the legacy+ // water-mark clears.+ const refreshed = await findPeerSubscription('peer-a', 'series', 's1');+ expect(refreshed.lastPushedHash).toBe(upgraded.hash);+ expect(refreshed.lastPushedLegacyHash).toBeFalsy();+ });++ it('does NOT record a legacy hash when the RECEIVER reported the bundled merge failed (#3928)', async () => {+ // `reviewSyncPending` from the receiver is a transient merge failure,+ // not a version gap — the next cycle must genuinely re-push.+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ });+ vi.mocked(peerFetch).mockResolvedValue({ ok: true, status: 200, json: async () => ({ reviewSyncPending: true }) });+ const sub = await subscribePeer({+ peerId: 'peer-a', recordKind: 'series', recordId: 's1',+ }, { adoptedFromReverse: true });+ await pushRecordToPeer(sub);+ const refreshed = await findPeerSubscription('peer-a', 'series', 's1');+ expect(refreshed.lastPushedHash).toBeFalsy();+ expect(refreshed.lastPushedLegacyHash).toBeFalsy();+ const second = await pushRecordToPeer(refreshed);+ expect(second.pushed).toBe(true);+ });+it('does NOT retry on a 400 whose validation error is unrelated to portosMeta', async () => {// The retry is keyed on the `portosMeta` mention in the validation// details — any other 400 (oversized field, unknown record key, etc.)diff --git a/server/services/sharing/peerSyncPush.js b/server/services/sharing/peerSyncPush.jsindex e9531dc89c..096f435df5 100644--- a/server/services/sharing/peerSyncPush.js+++ b/server/services/sharing/peerSyncPush.js@@ -226,6 +226,21 @@ export async function pushRecordToPeer(sub, options = {}) {if (sub.lastPushedHash && sub.lastPushedHash === hash) {return { pushed: false, reason: 'unchanged', hash };}+ // LEGACY-STRIPPED SHORT-CIRCUIT (#3928): the last push to this peer landed+ // only after we stripped a top-level key its older `.strict()` schema+ // rejects (`manuscriptReview` / `reverseOutline` / `linkedTrack`), so+ // `lastPushedHash` was deliberately withheld. Without a second water-mark+ // that withheld hash makes EVERY subsequent cycle re-run the same 400 ++ // stripped-retry pair forever — two HTTP round-trips per 60s sync for a+ // record whose content never moved. `lastPushedLegacyHash` records the FULL+ // payload hash we delivered in stripped form, so an unchanged record+ // short-circuits here. Any real content change moves `hash` and re-attempts+ // the full push; the `peer:online` re-probe (`bypassSchemaCooldown`) and+ // `forcePushRecord` still push unconditionally, which is the canonical+ // "did the peer upgrade?" point that finally delivers the stripped key.+ if (!options.bypassSchemaCooldown && sub.lastPushedLegacyHash && sub.lastPushedLegacyHash === hash) {+ return { pushed: false, reason: 'unchanged-legacy-stripped', hash };+ }const url = `${peerBaseUrl(peer)}/api/peer-sync/push`;// withAbortTimeout aborts after PUSH_TIMEOUT_MS so a hung peer can't keep the@@ -453,9 +468,24 @@ export async function pushRecordToPeer(sub, options = {}) {const trackBundleConfirmed = sub.recordKind === 'musicVideoProject'&& !trackSyncPending&& (!trackOwed || Boolean(payload.linkedTrack));+ // #3928: separate the two reasons a bundled doc is still pending. A+ // RECEIVER-reported pending (its bundled merge threw) is transient — the+ // next cycle must genuinely re-push, so it gets no water-mark. A+ // SENDER-side strip for a legacy peer is stable — the peer will reject the+ // key again until it upgrades, so record the full-payload hash in+ // `lastPushedLegacyHash` and let an unchanged record short-circuit above+ // instead of looping a 400 + retry pair every cycle. Missing assets/bodies+ // also stay un-water-marked: the receiver is still pulling and needs a+ // fresh manifest each cycle.+ const receiverReportedPending = body?.reviewSyncPending === true+ || body?.outlineSyncPending === true+ || body?.trackSyncPending === true;+ const strippedForLegacyPeer = reviewStrippedForLegacyPeer || outlineStrippedForLegacyPeer || trackStrippedForLegacyPeer;+ const legacyStrippedHash = (strippedForLegacyPeer && missingCount === 0 && !receiverReportedPending) ? hash : null;await persistPushSuccess(sub.id, (missingCount > 0 || reviewSyncPending || outlineSyncPending || trackSyncPending) ? null : hash, {confirmedAtMs: Date.now(),trackBundleConfirmed,+ legacyStrippedHash,});if (Number.isFinite(body?.ackedDeletesUpTo) && body.ackedDeletesUpTo > 0) {await ackDeletesUpTo(sub.peerId, body.ackedDeletesUpTo).catch(() => {});@@ -506,7 +536,7 @@ export async function pushRecordToPeer(sub, options = {}) {};}-async function persistPushSuccess(subId, hash, { confirmedAtMs = Date.now(), trackBundleConfirmed = false } = {}) {+async function persistPushSuccess(subId, hash, { confirmedAtMs = Date.now(), trackBundleConfirmed = false, legacyStrippedHash = null } = {}) {await withStateLock(async () => {const state = await readState();const sub = state.subscriptions.find((s) => s.id === subId);@@ -514,6 +544,11 @@ async function persistPushSuccess(subId, hash, { confirmedAtMs = Date.now(), traconst now = new Date().toISOString();sub.lastPushedAt = now;sub.lastPushedHash = hash;+ // #3928: the legacy-stripped water-mark. Set when this push only landed+ // with a newer top-level key stripped for an older peer; cleared on every+ // other successful push so a peer that has since upgraded (or a record+ // whose content moved) can never be held back by a stale entry.+ sub.lastPushedLegacyHash = isNonEmptyStr(legacyStrippedHash) ? legacyStrippedHash : null;sub.updatedAt = now;// Advance the per-record confirmed-delivery water-mark monotonically — an// out-of-order retry must not retract it (mirrors ackDeletesUpTo's