@indigoai-us/hq-cloud 6.18.109 → 6.18.111

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.
Files changed (152) hide show
  1. package/dist/bin/area-ledger-migration.d.ts.map +1 -1
  2. package/dist/bin/area-ledger-migration.js +5 -3
  3. package/dist/bin/area-ledger-migration.js.map +1 -1
  4. package/dist/bin/backup-prune-runner.js +2 -2
  5. package/dist/bin/backup-prune-runner.js.map +1 -1
  6. package/dist/bin/runner-output-guard.d.ts +39 -0
  7. package/dist/bin/runner-output-guard.d.ts.map +1 -0
  8. package/dist/bin/runner-output-guard.js +104 -0
  9. package/dist/bin/runner-output-guard.js.map +1 -0
  10. package/dist/bin/sync-runner-company.d.ts +20 -0
  11. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  12. package/dist/bin/sync-runner-company.js +134 -6
  13. package/dist/bin/sync-runner-company.js.map +1 -1
  14. package/dist/bin/sync-runner.d.ts +42 -1
  15. package/dist/bin/sync-runner.d.ts.map +1 -1
  16. package/dist/bin/sync-runner.js +37 -3
  17. package/dist/bin/sync-runner.js.map +1 -1
  18. package/dist/cli/conflict.d.ts +30 -1
  19. package/dist/cli/conflict.d.ts.map +1 -1
  20. package/dist/cli/conflict.js +69 -3
  21. package/dist/cli/conflict.js.map +1 -1
  22. package/dist/cli/reconcile-skip-reason.d.ts +13 -3
  23. package/dist/cli/reconcile-skip-reason.d.ts.map +1 -1
  24. package/dist/cli/reconcile-skip-reason.js +18 -0
  25. package/dist/cli/reconcile-skip-reason.js.map +1 -1
  26. package/dist/cli/reindex.d.ts.map +1 -1
  27. package/dist/cli/reindex.js +231 -44
  28. package/dist/cli/reindex.js.map +1 -1
  29. package/dist/cli/rescue-core.d.ts +98 -2
  30. package/dist/cli/rescue-core.d.ts.map +1 -1
  31. package/dist/cli/rescue-core.js +501 -76
  32. package/dist/cli/rescue-core.js.map +1 -1
  33. package/dist/cli/rescue-hq-registrations.d.ts +45 -0
  34. package/dist/cli/rescue-hq-registrations.d.ts.map +1 -0
  35. package/dist/cli/rescue-hq-registrations.js +252 -0
  36. package/dist/cli/rescue-hq-registrations.js.map +1 -0
  37. package/dist/cli/rescue.d.ts +8 -0
  38. package/dist/cli/rescue.d.ts.map +1 -1
  39. package/dist/cli/rescue.js +64 -17
  40. package/dist/cli/rescue.js.map +1 -1
  41. package/dist/cli/share.d.ts +35 -8
  42. package/dist/cli/share.d.ts.map +1 -1
  43. package/dist/cli/share.js +491 -32
  44. package/dist/cli/share.js.map +1 -1
  45. package/dist/cli/sync.d.ts +70 -5
  46. package/dist/cli/sync.d.ts.map +1 -1
  47. package/dist/cli/sync.js +445 -79
  48. package/dist/cli/sync.js.map +1 -1
  49. package/dist/cognito-auth.d.ts +10 -0
  50. package/dist/cognito-auth.d.ts.map +1 -1
  51. package/dist/cognito-auth.js +162 -1
  52. package/dist/cognito-auth.js.map +1 -1
  53. package/dist/ignore.d.ts.map +1 -1
  54. package/dist/ignore.js +43 -21
  55. package/dist/ignore.js.map +1 -1
  56. package/dist/index.d.ts +3 -3
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +2 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/journal-row-store.d.ts +3 -0
  61. package/dist/journal-row-store.d.ts.map +1 -1
  62. package/dist/journal-row-store.js +21 -0
  63. package/dist/journal-row-store.js.map +1 -1
  64. package/dist/journal-snapshot-decoder.js +2 -0
  65. package/dist/journal-snapshot-decoder.js.map +1 -1
  66. package/dist/journal-snapshot-v4.d.ts.map +1 -1
  67. package/dist/journal-snapshot-v4.js +6 -1
  68. package/dist/journal-snapshot-v4.js.map +1 -1
  69. package/dist/journal.d.ts +1 -1
  70. package/dist/journal.d.ts.map +1 -1
  71. package/dist/journal.js +20 -20
  72. package/dist/journal.js.map +1 -1
  73. package/dist/lib/append-log-merge.d.ts +43 -0
  74. package/dist/lib/append-log-merge.d.ts.map +1 -0
  75. package/dist/lib/append-log-merge.js +424 -0
  76. package/dist/lib/append-log-merge.js.map +1 -0
  77. package/dist/lib/same-path-upload-lock.d.ts +27 -1
  78. package/dist/lib/same-path-upload-lock.d.ts.map +1 -1
  79. package/dist/lib/same-path-upload-lock.js +32 -1
  80. package/dist/lib/same-path-upload-lock.js.map +1 -1
  81. package/dist/object-io.d.ts +36 -1
  82. package/dist/object-io.d.ts.map +1 -1
  83. package/dist/object-io.js +97 -13
  84. package/dist/object-io.js.map +1 -1
  85. package/dist/operation-lock.d.ts +27 -1
  86. package/dist/operation-lock.d.ts.map +1 -1
  87. package/dist/operation-lock.js +94 -8
  88. package/dist/operation-lock.js.map +1 -1
  89. package/dist/outposts/client.d.ts +19 -6
  90. package/dist/outposts/client.d.ts.map +1 -1
  91. package/dist/outposts/client.js +16 -5
  92. package/dist/outposts/client.js.map +1 -1
  93. package/dist/outposts/command.d.ts +2 -1
  94. package/dist/outposts/command.d.ts.map +1 -1
  95. package/dist/outposts/command.js +81 -13
  96. package/dist/outposts/command.js.map +1 -1
  97. package/dist/outposts/self-deploy.d.ts.map +1 -1
  98. package/dist/outposts/self-deploy.js +3 -0
  99. package/dist/outposts/self-deploy.js.map +1 -1
  100. package/dist/private-folder-transport.d.ts +0 -2
  101. package/dist/private-folder-transport.d.ts.map +1 -1
  102. package/dist/private-folder-transport.js +17 -16
  103. package/dist/private-folder-transport.js.map +1 -1
  104. package/dist/push-identity-fence.d.ts +116 -3
  105. package/dist/push-identity-fence.d.ts.map +1 -1
  106. package/dist/push-identity-fence.js +625 -62
  107. package/dist/push-identity-fence.js.map +1 -1
  108. package/dist/qmd-reindex.d.ts.map +1 -1
  109. package/dist/qmd-reindex.js +3 -2
  110. package/dist/qmd-reindex.js.map +1 -1
  111. package/dist/s3.d.ts +30 -9
  112. package/dist/s3.d.ts.map +1 -1
  113. package/dist/s3.js +110 -82
  114. package/dist/s3.js.map +1 -1
  115. package/dist/session-log-retention.d.ts +86 -0
  116. package/dist/session-log-retention.d.ts.map +1 -1
  117. package/dist/session-log-retention.js +127 -19
  118. package/dist/session-log-retention.js.map +1 -1
  119. package/dist/sync/area-ledger-migration.d.ts +17 -0
  120. package/dist/sync/area-ledger-migration.d.ts.map +1 -1
  121. package/dist/sync/area-ledger-migration.js +37 -3
  122. package/dist/sync/area-ledger-migration.js.map +1 -1
  123. package/dist/sync/scattered-delete-burst.d.ts +61 -0
  124. package/dist/sync/scattered-delete-burst.d.ts.map +1 -0
  125. package/dist/sync/scattered-delete-burst.js +111 -0
  126. package/dist/sync/scattered-delete-burst.js.map +1 -0
  127. package/dist/sync/unattended-delete-hold.d.ts +102 -0
  128. package/dist/sync/unattended-delete-hold.d.ts.map +1 -0
  129. package/dist/sync/unattended-delete-hold.js +164 -0
  130. package/dist/sync/unattended-delete-hold.js.map +1 -0
  131. package/dist/sync-core.d.ts +5 -6
  132. package/dist/sync-core.d.ts.map +1 -1
  133. package/dist/sync-core.js +5 -6
  134. package/dist/sync-core.js.map +1 -1
  135. package/dist/types.d.ts +13 -2
  136. package/dist/types.d.ts.map +1 -1
  137. package/dist/vault-client.d.ts +6 -0
  138. package/dist/vault-client.d.ts.map +1 -1
  139. package/dist/vault-client.js +53 -8
  140. package/dist/vault-client.js.map +1 -1
  141. package/dist/vault-key-grammar.d.ts +44 -0
  142. package/dist/vault-key-grammar.d.ts.map +1 -0
  143. package/dist/vault-key-grammar.js +158 -0
  144. package/dist/vault-key-grammar.js.map +1 -0
  145. package/dist/watcher.d.ts.map +1 -1
  146. package/dist/watcher.js +4 -1
  147. package/dist/watcher.js.map +1 -1
  148. package/dist/windows-extended-path.d.ts +22 -0
  149. package/dist/windows-extended-path.d.ts.map +1 -0
  150. package/dist/windows-extended-path.js +55 -0
  151. package/dist/windows-extended-path.js.map +1 -0
  152. package/package.json +1 -1
package/dist/cli/share.js CHANGED
@@ -22,18 +22,22 @@ import { noteSwallowedError } from "../best-effort-error.js";
22
22
  import { appendSyncDecision } from "../sync-decision-log.js";
23
23
  import { readPendingConflictNotices, recordConflictParked } from "../conflict-notices.js";
24
24
  import { localPathForVaultKey, vaultKeyForLocalPath } from "../local-path-codec.js";
25
+ import { detectScatteredDeleteBurst } from "../sync/scattered-delete-burst.js";
26
+ import { clearUnattendedHeldRow, describeRemoteCreator, markUnattendedHeldRow, resolveUnattendedDeleteHold, unattendedMayDelete, UNREADABLE_CREATOR, } from "../sync/unattended-delete-hold.js";
25
27
  import { uploadFile, uploadSymlink, toPosixKey, headRemoteFile, readVerifiedRemoteSymlinkTarget, deleteRemoteFile, downloadFile, primeObjectTransport, primeUploads, publishedContentHash, setUploadContentHash, WindowsSymlinkPrivilegeError, WINDOWS_SYMLINK_PRIVILEGE_REMEDY, WindowsRenameBlockedError, WINDOWS_RENAME_BLOCKED_REMEDY, renameOrRaiseWindowsBlocked, } from "../s3.js";
26
28
  import * as crypto from "crypto";
27
- import { bindObjectIOToContext, PresignObjectIO, RateLimitedError, resolveObjectIO, S3SdkObjectIO, isPresignDeletedNewer, } from "../object-io.js";
29
+ import { bindObjectIOToContext, PresignKeyRefusedError, PresignObjectIO, RateLimitedError, resolveObjectIO, S3SdkObjectIO, isPresignDeletedNewer, } from "../object-io.js";
28
30
  import { primePrivateFolderUpload } from "../private-folder-transport.js";
29
31
  import { getJournalPath, isUnderAnyRoot, readJournalForPass, bindPersonalVaultJournalToIdentity, readJournalReadOnly, readJournalScoped, readQuarantinedJournalPaths, writeJournal, setJournalSnapshotQuarantineListener, hashFile, hashSymlinkTarget, journalRows, journalEntryMatchesStat, journalFingerprintMatchesStat, dropJournalDecodeWindow, timestampsTooCoarseToTrust, updateEntry, PrematureJournalEntryError, removeEntry, isTombstone, normalizeEtag, PERSONAL_VAULT_JOURNAL_SLUG, migratePersonalVaultJournal, migrateToV2, configureRejectedDeltaRecovery, getJournalRecoveryMarker, getStateDir, personalVaultHasOtherIdentityState, readPersonalVaultOwnerUid, } from "../journal.js";
30
- import { admitPushIdentity, machineIdentitySwitchRecorded, notePushIdentityHeld, noteCompanyRebind, } from "../push-identity-fence.js";
32
+ import { admitPushIdentity, corruptPushIdentityHold, holdIsProvenDifferentPerson, recordSignedInPerson, machineIdentitySwitchRecorded, notePushIdentityHeld, noteCompanyRebind, pushIdentityHoldMessage, releaseUnprovenPushIdentityHold, signedInPersonalUid, signedInPersonMappingState, } from "../push-identity-fence.js";
31
33
  import { createIgnoreExplainer, createIgnoreFilter, hasControlCharacters, isExpectedIgnore, isHqGeneratedIndexFile, isMachineLocalRuntimePath, isPathExcludedFromSync, isSecretFolderPath, isSecretPatternIgnore, isWithinSizeLimit, } from "../ignore.js";
34
+ import { formatSizeLimitSkipLine } from "../session-log-retention.js";
35
+ import { classifyPresignKey } from "../vault-key-grammar.js";
32
36
  import { wrapFilterWithPersonalVaultDefaults, } from "../personal-vault-exclusions.js";
33
37
  import { claimNeverSyncedLocalNotices, formatSecretsNotSyncedLine, isNeverSyncedVaultPath, isSecretBearingVaultPath, isSkipSecretPathsEnabled, isWalRejectedDeltaRecoveryEnabled, } from "../sync/secret-path-policy.js";
34
38
  import { getActiveFullPassDecodeWindow, getActiveFullPassUnitSize, } from "../sync/full-pass-caps.js";
35
39
  import { isGeneratedCoreMirrorKey, isPersonalVaultDeletionExcluded, isSessionLogDeletionKey, purgeExcludedPersonalVaultJournalEntries, } from "../personal-vault.js";
36
- import { pickWinner, resolveConflict, usesVersionAwareWinner } from "./conflict.js";
40
+ import { COMPANY_MANIFEST_KEY, countManifestCompanies, countManifestCompaniesAt, pickWinner, resolveConflict, usesVersionAwareWinner, } from "./conflict.js";
37
41
  import { createHumanSkipLineLog, formatReconcileSkipLine, isUpToDateSkipReason, } from "./reconcile-skip-reason.js";
38
42
  import { fetchFileTombstones, } from "./tombstones.js";
39
43
  import { compileScopeMatcher, } from "../prefix-coalesce.js";
@@ -41,6 +45,7 @@ import { hasRemoteChanged, isAccessDenied, resolveActiveCompany, resolveTransfer
41
45
  import { buildConflictBackupPath, CONFLICT_BACKUPS_DIR, buildConflictId, buildConflictProbePath, readShortMachineId, } from "../lib/conflict-file.js";
42
46
  import { appendConflictEntry, findReusableConflictBackup } from "../lib/conflict-index.js";
43
47
  import { appendIfUnchanged, isAppendOnlyPath, mergeAppendOnly } from "../lib/append-only-merge.js";
48
+ import { isAppendLogPath, mergeAppendLog, writeAppendLogMerge } from "../lib/append-log-merge.js";
44
49
  import { isBoardJsonPath, mergeBoardJson, replaceIfUnchanged } from "../lib/board-merge.js";
45
50
  import { findLandedUpload, findUploadIntent, followLandedUploads, recordUploadIntent, SamePathUploadHold, samePathUploadKey, SamePathUploadSupersededError, settleUploadIntent, } from "../lib/same-path-upload-lock.js";
46
51
  import { isCloudAuthoritative, isLocallyIneligibleForPush } from "../lib/cloud-authoritative.js";
@@ -49,7 +54,7 @@ import { isOntologyEntityKey, ONTOLOGY_MULTI_WRITER_FLAG, resolveOntologyEntityP
49
54
  import { entityIsFreshForCreate, outboxAllowsEntityPush, readOntologyOutbox, } from "../lib/ontology-outbox.js";
50
55
  import { resolveSkillRegisterLandedBytes } from "../lib/skill-register-landed-bytes.js";
51
56
  import { resolvePersonalConnectorSettingsSync } from "../lib/personal-connector-settings-sync.js";
52
- import { planLimitRefusalFromError, VaultAuthError, VaultClient, VaultClientError, VaultConflictError, VaultPermissionDeniedError, } from "../vault-client.js";
57
+ import { planLimitRefusalFromError, VaultAuthError, VaultClient, pickCanonicalPersonEntity, VaultClientError, VaultConflictError, VaultPermissionDeniedError, } from "../vault-client.js";
53
58
  import { formatPlanLimitNotice } from "../plan-limit.js";
54
59
  import { PlanLimitPauseStore, planLimitPauseNow, PLAN_LIMIT_PAUSE_RETRY_MS, } from "../plan-limit-pause.js";
55
60
  import { describeError } from "../lib/describe-error.js";
@@ -1254,6 +1259,16 @@ async function runShareOnce(options, run) {
1254
1259
  `${run.writeForbiddenSet.size} refused in total, kept local-only`,
1255
1260
  });
1256
1261
  }
1262
+ if (run.deleteForbiddenSet.size > REFUSED_STALE_PATH_CAP) {
1263
+ const more = run.deleteForbiddenSet.size - REFUSED_STALE_PATH_CAP;
1264
+ run.emit({
1265
+ type: "error",
1266
+ diagnostic: true,
1267
+ path: "(delete-forbidden)",
1268
+ message: `${more} more deletes did not reach the cloud: the vault refused them (no write access, server delete denied: FILES_PRESIGN_FORBIDDEN); ` +
1269
+ `${run.deleteForbiddenSet.size} refused in total, cloud copies remain and the deletes retry next sync`,
1270
+ });
1271
+ }
1257
1272
  finalizeShareJournal(run);
1258
1273
  throwUploadWorkerErrors(uploadResult.workerErrors, run.emit);
1259
1274
  // A reconcile cursor is an all-or-nothing boundary for this bounded apply
@@ -1317,6 +1332,38 @@ const REFUSED_STALE_PATH_CAP = 50;
1317
1332
  * refused to mint a PUT URL with FILES_PRESIGN_FORBIDDEN (see object-io.ts
1318
1333
  * isSkipWithLogDenialCode). Its message carries "server put denied: <code>".
1319
1334
  */
1335
+ /**
1336
+ * Does this context's object traffic go through the presign server? Building
1337
+ * the transport can throw (a direct-S3 context with no credentials); that
1338
+ * answers "no", which keeps the push's pre-presign key checks.
1339
+ */
1340
+ function usesPresignTransport(ctx) {
1341
+ try {
1342
+ return resolveObjectIO(ctx) instanceof PresignObjectIO;
1343
+ }
1344
+ catch {
1345
+ return false;
1346
+ }
1347
+ }
1348
+ /** Company vaults are `cmp_*`; every other uid is a personal scope. */
1349
+ function presignKeyScope(ctx) {
1350
+ return ctx.uid.startsWith("cmp_") ? "company" : "personal";
1351
+ }
1352
+ /**
1353
+ * The presign server refuses this key's spelling, so a delete can never
1354
+ * succeed. Direct-S3 contexts keep the key: that transport stores it.
1355
+ */
1356
+ function presignDeleteKeyRefused(ctx, key) {
1357
+ return usesPresignTransport(ctx) && classifyPresignKey(key, presignKeyScope(ctx)) !== null;
1358
+ }
1359
+ function emitInvalidScopedKeySkip(run, path, errorCode) {
1360
+ run.emit({
1361
+ type: "skip-invalid-scoped-key",
1362
+ path,
1363
+ errorCode,
1364
+ ...(errorCode === "INVALID_KEY_BACKSLASH" ? { reason: "backslash-key" } : {}),
1365
+ });
1366
+ }
1320
1367
  export function isPresignWriteForbidden(err) {
1321
1368
  const message = err instanceof Error ? err.message : String(err);
1322
1369
  return /server put denied: FILES_PRESIGN_FORBIDDEN\b/.test(message);
@@ -1330,6 +1377,28 @@ function isDirectS3AccessDenied(err) {
1330
1377
  shaped.Code === "AccessDenied" ||
1331
1378
  shaped.$metadata?.httpStatusCode === 403;
1332
1379
  }
1380
+ /**
1381
+ * Record `sub` against the caller's own personal vault uid, from the person
1382
+ * list route and the same canonical pick the sync runner uses to choose its
1383
+ * personal target. hq-pro answers that route with the entities owned by the
1384
+ * caller's token (listEntitiesByOwner(callerUid)), or the caller's own agent
1385
+ * entity for a machine identity, so another person's entity is never returned
1386
+ * to an admin. Only a `prs_` person uid is recorded. Any failure records
1387
+ * nothing, which leaves the pusher unproven (fenced). `onError` receives a
1388
+ * short, token-free description of the swallowed failure for diagnostics.
1389
+ */
1390
+ export async function recordCallerPersonalUid(client, stateDir, sub, onError) {
1391
+ try {
1392
+ const pick = pickCanonicalPersonEntity(await client.entity.listByType("person"));
1393
+ if (pick?.uid.startsWith("prs_"))
1394
+ recordSignedInPerson(stateDir, sub, pick.uid);
1395
+ }
1396
+ catch (err) {
1397
+ // Unproven pusher: stay fenced. Report only the error class, never its
1398
+ // message, which could carry request details.
1399
+ onError?.(`person lookup failed (${err instanceof Error ? err.name : typeof err}); pusher stays held`);
1400
+ }
1401
+ }
1333
1402
  async function createPushRunContext(options) {
1334
1403
  const { paths, company, message, onConflict, vaultConfig, entityContext, hqRoot, propagateDeletes } = options;
1335
1404
  // Personal vault is a bulk tree, not `hq share <file>`. Default skip-unchanged
@@ -1559,16 +1628,48 @@ async function createPushRunContext(options) {
1559
1628
  const personalScope = options.personalMode === true || ctx.uid.startsWith("prs_");
1560
1629
  const pushIdentityUid = personalScope ? ctx.uid : signedInSub;
1561
1630
  const otherIdentityEvidence = personalVaultHasOtherIdentityState();
1631
+ // feedback_a3d39586: a hand-run push of a company scope never ran the sync
1632
+ // runner's sign-in step, so this sub may have no person record. Record it the
1633
+ // way the runner does (the caller's own person entity), before the fence is
1634
+ // checked. A failed lookup records nothing and the scope stays fenced.
1635
+ if (!personalScope && signedInSub && vaultConfig && signedInPersonMappingState(getStateDir(), signedInSub) === "none") {
1636
+ // Only a truly missing mapping is recorded; a corrupt or unreadable file
1637
+ // is left alone and the pusher stays fenced.
1638
+ await recordCallerPersonalUid(new VaultClient(vaultConfig), getStateDir(), signedInSub, (message) => {
1639
+ if (process.env.HQ_DEBUG)
1640
+ console.debug(`[push-identity] ${message}`);
1641
+ });
1642
+ }
1643
+ const personalOwnerUid = readPersonalVaultOwnerUid();
1644
+ const personalUid = personalScope ? ctx.uid : signedInPersonalUid(getStateDir(), signedInSub);
1645
+ if (pushIdentityUid &&
1646
+ !holdIsProvenDifferentPerson(getStateDir(), {
1647
+ otherIdentityEvidence,
1648
+ machineOwnerUid: personalOwnerUid,
1649
+ personalUid,
1650
+ sub: signedInSub,
1651
+ })) {
1652
+ const identities = [personalUid, signedInSub, pushIdentityUid].filter((identity) => typeof identity === "string" && identity.length > 0);
1653
+ const healed = releaseUnprovenPushIdentityHold(getStateDir(), identities);
1654
+ if (healed.released.length > 0) {
1655
+ console.log(`Released held uploads (${healed.released.join(", ")}): the signed-in person matches this computer's history.`);
1656
+ }
1657
+ else if (healed.clearedMarker) {
1658
+ console.log("Cleared a false sign-in switch on this computer: the signed-in person matches this computer's history.");
1659
+ }
1660
+ }
1562
1661
  const pushIdentityFence = pushIdentityUid
1563
1662
  ? admitPushIdentity(getStateDir(), journalSlug, pushIdentityUid, {
1564
1663
  ...(signedInSub ? { sub: signedInSub } : {}),
1565
1664
  otherIdentityEvidence,
1566
1665
  personalScope,
1567
- personalOwnerUid: readPersonalVaultOwnerUid(),
1666
+ personalOwnerUid,
1568
1667
  })
1569
- : machineIdentitySwitchRecorded(getStateDir()) || otherIdentityEvidence
1570
- ? { uid: "", sinceMs: Date.now() }
1571
- : undefined;
1668
+ : corruptPushIdentityHold(getStateDir(), journalSlug)
1669
+ ? { uid: "", sinceMs: Date.now(), reason: "corrupt-identity" }
1670
+ : machineIdentitySwitchRecorded(getStateDir()) || otherIdentityEvidence || personalOwnerUid !== null
1671
+ ? { uid: "", sinceMs: Date.now() }
1672
+ : undefined;
1572
1673
  const quarantinedPaths = readQuarantinedJournalPaths(journalSlug);
1573
1674
  const flagConfig = vaultConfig ?? privateFolderVaultConfig;
1574
1675
  const symlinkTargetRefusal = flagConfig
@@ -1646,6 +1747,7 @@ async function createPushRunContext(options) {
1646
1747
  scopeExcludedSet,
1647
1748
  uploadFailedSet: new Set(),
1648
1749
  writeForbiddenSet: new Set(),
1750
+ deleteForbiddenSet: new Set(),
1649
1751
  ignoreExcludedSet,
1650
1752
  ignoreExcludedTotal,
1651
1753
  ignoreExcludedLayers,
@@ -2385,14 +2487,30 @@ async function buildSharePlans(run) {
2385
2487
  // Finder icon files are normally already gone by here — createIgnoreFilter
2386
2488
  // drops them during the walk. This stays as the general guard for any other
2387
2489
  // control-char path, and as defense for callers that bypass the walker.
2490
+ //
2491
+ // feedback_65ee9e51: the same rule covers every key the presign server
2492
+ // refuses on spelling (hq-pro toKeyItem: a `*`, a backslash, a double
2493
+ // slash, a `.` or `..` component, or one of those after URI decoding).
2494
+ // That is the presign transport, and a private folder on the direct-S3
2495
+ // path, which is written through presign. Such a key can never be read or
2496
+ // written through presign, so planning it only reaches a refusal. Skip it
2497
+ // here with the same event. Other direct-S3 keys are stored (uploadFile
2498
+ // turns a backslash into a separator), so they keep the control-char check
2499
+ // only.
2500
+ const presignTransport = usesPresignTransport(run.ctx);
2501
+ const keyScope = presignKeyScope(run.ctx);
2388
2502
  const controlCharFiltered = collected.filter((entry) => {
2389
- if (!hasControlCharacters(entry.relativePath))
2503
+ const presignGrammar = presignTransport ||
2504
+ (run.privateFolderTransport !== undefined &&
2505
+ run.privateFolderMatcher.coversPath(entry.relativePath));
2506
+ const errorCode = hasControlCharacters(entry.relativePath)
2507
+ ? "INVALID_KEY_CONTROL_CHARS"
2508
+ : presignGrammar
2509
+ ? classifyPresignKey(entry.relativePath, keyScope)?.code
2510
+ : undefined;
2511
+ if (errorCode === undefined)
2390
2512
  return true;
2391
- run.emit({
2392
- type: "skip-invalid-scoped-key",
2393
- path: entry.relativePath,
2394
- errorCode: "INVALID_KEY_CONTROL_CHARS",
2395
- });
2513
+ emitInvalidScopedKeySkip(run, entry.relativePath, errorCode);
2396
2514
  return false;
2397
2515
  }).filter((entry) => !isLocalCopyOfLibraryAsset(run.journal, entry));
2398
2516
  // `companies/` is an ordinary directory name below a company vault root.
@@ -2454,7 +2572,11 @@ async function buildSharePlans(run) {
2454
2572
  });
2455
2573
  const recoveryHoldActive = run.holdRemoteDeletes || getJournalRecoveryMarker(run.journalSlug) !== undefined;
2456
2574
  const deletePlan = run.propagateDeletes === true
2457
- ? await computeDeletePlan(run.journal, run.syncRoot, deleteScopeRoots, run.shouldSync, run.propagateDeletePolicy, run.ctx, run.options.personalMode !== true, run.skipSecretPaths, run.quarantinedPaths, recoveryHoldActive, run.scopedJournal ? () => readJournalReadOnly(run.journalSlug) : undefined)
2575
+ ? await computeDeletePlan(run.journal, run.syncRoot, deleteScopeRoots, run.shouldSync, run.propagateDeletePolicy, run.ctx, run.options.personalMode !== true, run.skipSecretPaths, run.quarantinedPaths, recoveryHoldActive, run.scopedJournal ? () => readJournalReadOnly(run.journalSlug) : undefined, new Set(pushPlan.items.flatMap((item) => item.action === "upload" && item.kind === "file" ? [item.localHash] : [])), await resolveUnattendedDeleteHold({
2576
+ personalMode: run.options.personalMode === true,
2577
+ knownSubs: [run.options.author?.userSub, run.options.signedInSub],
2578
+ ...(run.vaultConfig ? { authToken: run.vaultConfig.authToken } : {}),
2579
+ }))
2458
2580
  : { toDelete: [], toTombstone: [], refusedStale: [] };
2459
2581
  for (const warning of deletePlan.brokenLinkSkipped ?? []) {
2460
2582
  if (rememberLinkWarning(run.linkWarnings, warning))
@@ -2530,6 +2652,9 @@ async function buildSharePlans(run) {
2530
2652
  inScope: deletePlan.bulkAsymmetry.inScope,
2531
2653
  ratio: deletePlan.bulkAsymmetry.ratio,
2532
2654
  samplePaths: deletePlan.bulkAsymmetry.samplePaths,
2655
+ ...(deletePlan.bulkAsymmetry.trigger
2656
+ ? { trigger: deletePlan.bulkAsymmetry.trigger, folders: deletePlan.bulkAsymmetry.folders }
2657
+ : {}),
2533
2658
  });
2534
2659
  }
2535
2660
  if (massDeleteGuard) {
@@ -2585,10 +2710,19 @@ function holdFilesFromBeforeIdentitySwitch(run, entries) {
2585
2710
  held.push(entry.relativePath);
2586
2711
  }
2587
2712
  notePushIdentityHeld(getStateDir(), run.journalSlug, held.length, held);
2713
+ const sample = held.slice(0, 20);
2714
+ const corrupt = run.pushIdentityFence?.reason === "corrupt-identity";
2588
2715
  run.emit({
2589
2716
  type: "identity-switch-push-held",
2590
2717
  count: held.length,
2591
- ...(run.companyRebindHold ? { reason: "company-rebind" } : {}),
2718
+ ...(run.companyRebindHold
2719
+ ? { reason: "company-rebind" }
2720
+ : {
2721
+ samplePaths: sample,
2722
+ message: pushIdentityHoldMessage(held.length, sample, corrupt ? "corrupt-identity" : undefined),
2723
+ action: "hq sync release-held",
2724
+ ...(corrupt ? { reason: "corrupt-identity" } : {}),
2725
+ }),
2592
2726
  });
2593
2727
  return [];
2594
2728
  }
@@ -3378,7 +3512,47 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3378
3512
  // still at that etag, silently promoting the divergent local to write
3379
3513
  // authority. Route through conflict (keep/abort/overwrite) instead.
3380
3514
  const divergentLocalHonesty = !!journalEntry?.localDiverges;
3381
- const twoSidedChange = (localChanged && remoteChanged) || isFreshCollision || divergentLocalHonesty;
3515
+ // A blank companies manifest (the hq-core template) never uploads over a
3516
+ // cloud manifest that lists companies. It goes through conflict handling
3517
+ // instead, where the populated cloud copy keeps the name and the blank
3518
+ // local body is parked as the conflict backup (feedback_09af2875). An
3519
+ // explicit `--on-conflict overwrite` or `publish-local` is consent to
3520
+ // publish the local body, so it uploads as before; that is how a person
3521
+ // empties the list on purpose.
3522
+ let blankManifestOverPopulated = false;
3523
+ // The probe that read the cloud manifest, handed to the conflict branch
3524
+ // so it does not fetch the same body a second time.
3525
+ let manifestGateProbe;
3526
+ if (!((localChanged && remoteChanged) || isFreshCollision || divergentLocalHonesty) &&
3527
+ run.options.personalMode === true &&
3528
+ run.onConflict !== "overwrite" &&
3529
+ run.onConflict !== "publish-local" &&
3530
+ item.kind === "file" &&
3531
+ relativePath === COMPANY_MANIFEST_KEY &&
3532
+ countManifestCompaniesAt(absolutePath) === 0) {
3533
+ const manifestProbe = await probeRemoteForWinner(run, item, remoteMeta.lastModified, remoteChangedSinceJournal, remoteMeta.etag, !journalEntry);
3534
+ const remoteBody = manifestProbe.peekBody();
3535
+ if (remoteBody === undefined) {
3536
+ // The cloud manifest could not be read, so the upload cannot be shown
3537
+ // to keep its company list. Leave both sides and report the path as
3538
+ // failed, so a cloud read that keeps failing is not a quiet skip.
3539
+ manifestProbe.discard();
3540
+ hadUploadFailure = true;
3541
+ run.uploadFailedSet.add(relativePath);
3542
+ counters.filesSkipped++;
3543
+ emitPushSkip(run, relativePath, "remote_body_unreadable");
3544
+ return;
3545
+ }
3546
+ blankManifestOverPopulated = (countManifestCompanies(remoteBody) ?? 0) > 0;
3547
+ if (blankManifestOverPopulated) {
3548
+ manifestGateProbe = manifestProbe;
3549
+ process.stderr.write("hq-cloud: not uploading a blank companies/manifest.yaml over the cloud copy that lists companies; resolving as a conflict\n");
3550
+ }
3551
+ else {
3552
+ manifestProbe.discard();
3553
+ }
3554
+ }
3555
+ const twoSidedChange = (localChanged && remoteChanged) || isFreshCollision || divergentLocalHonesty || blankManifestOverPopulated;
3382
3556
  // A company board is merged by entry id against the cloud copy before
3383
3557
  // every upload, not only on a two-sided change: a local board that lost
3384
3558
  // entries (recreated fresh, or written from a stale copy) must never
@@ -3425,6 +3599,7 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3425
3599
  // conflict on a client-owned file, or a flag-gated ontology entity.
3426
3600
  conflictPaths.push(relativePath);
3427
3601
  if (cloudWinsEntity) {
3602
+ manifestGateProbe?.discard();
3428
3603
  // The cloud body wins whatever the conflict strategy. The local body
3429
3604
  // is set aside out of the tree, like any adopted conflict.
3430
3605
  run.emit({ type: "conflict", path: relativePath, direction: "push", resolution: "keep" });
@@ -3441,10 +3616,11 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3441
3616
  let winnerProbe;
3442
3617
  let resolution;
3443
3618
  if (versionAware) {
3444
- winnerProbe = await probeRemoteForWinner(run, item, remoteMeta.lastModified, remoteChangedSinceJournal, remoteMeta.etag, !journalEntry);
3619
+ winnerProbe = manifestGateProbe ?? await probeRemoteForWinner(run, item, remoteMeta.lastModified, remoteChangedSinceJournal, remoteMeta.etag, !journalEntry);
3445
3620
  resolution = "keep";
3446
3621
  }
3447
3622
  else {
3623
+ manifestGateProbe?.discard();
3448
3624
  resolution = await resolveConflictSerialized({
3449
3625
  path: relativePath,
3450
3626
  localHash,
@@ -3460,10 +3636,12 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3460
3636
  decision &&
3461
3637
  winnerProbe &&
3462
3638
  item.kind === "file" &&
3463
- (isAppendOnlyPath(relativePath) || isBoardJsonPath(relativePath))) {
3639
+ (isAppendOnlyPath(relativePath) || isBoardJsonPath(relativePath) || isAppendLogPath(relativePath))) {
3464
3640
  const outcome = isBoardJsonPath(relativePath)
3465
3641
  ? mergeAppendOnlyPushConflict(run, item, winnerProbe, normalizeEtag(remoteMeta.etag), mergeBoardJson, replaceIfUnchanged)
3466
- : mergeAppendOnlyPushConflict(run, item, winnerProbe, normalizeEtag(remoteMeta.etag));
3642
+ : isAppendOnlyPath(relativePath)
3643
+ ? mergeAppendOnlyPushConflict(run, item, winnerProbe, normalizeEtag(remoteMeta.etag))
3644
+ : mergeAppendLogPushConflict(run, item, winnerProbe, normalizeEtag(remoteMeta.etag));
3467
3645
  recordPushMerge(run, item, outcome, {
3468
3646
  remoteEtag: normalizeEtag(remoteMeta.etag),
3469
3647
  remoteSha256: winnerProbe.remoteContentHash() ?? null,
@@ -3692,8 +3870,9 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3692
3870
  };
3693
3871
  const primePrivateFolder = (io) => primePrivateFolderUpload({
3694
3872
  io,
3695
- ctx: run.ctx,
3696
- key: relativePath,
3873
+ // Same POSIX key primeUploads and uploadFile cache under. A Windows
3874
+ // separator must not miss the primed PUT.
3875
+ key: toPosixKey(relativePath),
3697
3876
  localPath: absolutePath,
3698
3877
  contentHash: localHash,
3699
3878
  author: run.options.author,
@@ -3939,6 +4118,14 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3939
4118
  throw err;
3940
4119
  if (emitPlanLimitSkip(err, relativePath))
3941
4120
  return;
4121
+ // Spelling refusal from the presign PUT (including the private-folder
4122
+ // fallback). Same quiet skip as the pre-filter: no upload failure, and
4123
+ // the journal row is left as it was. Before isAccessDenied: this error
4124
+ // is named Forbidden.
4125
+ if (err instanceof PresignKeyRefusedError) {
4126
+ emitInvalidScopedKeySkip(run, relativePath, err.presignCode);
4127
+ return;
4128
+ }
3942
4129
  if (isPreconditionFailed(err)) {
3943
4130
  conflictPaths.push(relativePath);
3944
4131
  if (cloudWinsEntity) {
@@ -3996,8 +4183,13 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
3996
4183
  // pre-flight merge is merged again, never parked. Every outcome
3997
4184
  // leaves the journal on the old version, so the next pass merges
3998
4185
  // or publishes under a fresh fence.
3999
- if (decision && latest?.etag && item.kind === "file" && isAppendOnlyPath(relativePath)) {
4000
- const outcome = mergeAppendOnlyPushConflict(run, item, probe, normalizeEtag(latest.etag));
4186
+ if (decision &&
4187
+ latest?.etag &&
4188
+ item.kind === "file" &&
4189
+ (isAppendOnlyPath(relativePath) || isAppendLogPath(relativePath))) {
4190
+ const outcome = isAppendOnlyPath(relativePath)
4191
+ ? mergeAppendOnlyPushConflict(run, item, probe, normalizeEtag(latest.etag))
4192
+ : mergeAppendLogPushConflict(run, item, probe, normalizeEtag(latest.etag));
4001
4193
  if (outcome !== "not-mergeable") {
4002
4194
  const conflictIndex = conflictPaths.lastIndexOf(relativePath);
4003
4195
  if (conflictIndex >= 0)
@@ -4091,6 +4283,10 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
4091
4283
  emitPushSkip(run, relativePath, "held_for_next_pass");
4092
4284
  return;
4093
4285
  }
4286
+ if (retryErr instanceof PresignKeyRefusedError) {
4287
+ emitInvalidScopedKeySkip(run, relativePath, retryErr.presignCode);
4288
+ return;
4289
+ }
4094
4290
  hadUploadFailure = true;
4095
4291
  run.uploadFailedSet.add(relativePath);
4096
4292
  run.emit({
@@ -4202,6 +4398,10 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
4202
4398
  counters.filesSkippedConflict++;
4203
4399
  return;
4204
4400
  }
4401
+ if (retryErr instanceof PresignKeyRefusedError) {
4402
+ emitInvalidScopedKeySkip(run, relativePath, retryErr.presignCode);
4403
+ return;
4404
+ }
4205
4405
  hadUploadFailure = true;
4206
4406
  run.uploadFailedSet.add(relativePath);
4207
4407
  run.emit({
@@ -4543,7 +4743,7 @@ function adoptOwnUploadIntent(run, item, remoteMeta) {
4543
4743
  if (row?.remoteEtag !== undefined && normalizeEtag(row.remoteEtag) === remoteEtag)
4544
4744
  return false;
4545
4745
  const rowWrittenAt = row ? Date.parse(row.syncedAt) : Number.NaN;
4546
- const intent = findUploadIntent(run.journalSlug, item.relativePath, remoteHash, Number.isFinite(rowWrittenAt) ? rowWrittenAt : undefined);
4746
+ const intent = findUploadIntent(run.journalSlug, item.relativePath, remoteHash, Number.isFinite(rowWrittenAt) ? rowWrittenAt : undefined, remoteMeta.lastModified && !remoteMeta.lastModifiedUnknown ? remoteMeta.lastModified.getTime() : null);
4547
4747
  if (!intent)
4548
4748
  return false;
4549
4749
  try {
@@ -4737,6 +4937,7 @@ async function probeRemoteForWinner(run, item, remoteMtime, remoteChangedSinceJo
4737
4937
  remoteChangedSinceJournal,
4738
4938
  noJournalBaseline,
4739
4939
  path: item.relativePath,
4940
+ personalVault: run.options.personalMode === true,
4740
4941
  });
4741
4942
  }
4742
4943
  }
@@ -4938,7 +5139,11 @@ function mergeAppendOnlyPushConflict(run, item, probe, remoteEtag, merge = merge
4938
5139
  run.emit({
4939
5140
  type: "error",
4940
5141
  path: item.relativePath,
4941
- message: `${isBoardJsonPath(item.relativePath) ? "could not merge the cloud board entries into the local board" : "could not add the cloud's lines to the local file"}: ${describeError(error)}`,
5142
+ message: `${isBoardJsonPath(item.relativePath)
5143
+ ? "could not merge the cloud board entries into the local board"
5144
+ : isAppendOnlyPath(item.relativePath)
5145
+ ? "could not add the cloud's lines to the local file"
5146
+ : "could not merge the cloud's log entries into the local file"}: ${describeError(error)}`,
4942
5147
  });
4943
5148
  return "write-failed";
4944
5149
  }
@@ -4959,6 +5164,16 @@ function mergeAppendOnlyPushConflict(run, item, probe, remoteEtag, merge = merge
4959
5164
  checkpointShareJournal(run);
4960
5165
  return "took-remote";
4961
5166
  }
5167
+ /**
5168
+ * {@link mergeAppendOnlyPushConflict} for a markdown or text log: entries are
5169
+ * merged only when both sides appended to the body this machine last synced
5170
+ * (the journal hash), so a side that edited or deleted text still takes the
5171
+ * ordinary conflict rule and parks the losing body (feedback_5f5f3ee1).
5172
+ */
5173
+ function mergeAppendLogPushConflict(run, item, probe, remoteEtag) {
5174
+ const baseHash = journalRows(run.journal).get(item.relativePath)?.hash ?? null;
5175
+ return mergeAppendOnlyPushConflict(run, item, probe, remoteEtag, (localBody, remoteBody) => mergeAppendLog(localBody, remoteBody, baseHash, item.relativePath), writeAppendLogMerge);
5176
+ }
4962
5177
  async function adoptRemoteOnPush(run, item, remoteHash, decision, probe) {
4963
5178
  let localMovedAside = false;
4964
5179
  let remoteAdopted = false;
@@ -5294,6 +5509,20 @@ async function executeDeletes(run, deletePlan, decommissionPlan, counters, files
5294
5509
  isRetryableIdentityRefusal(err)) {
5295
5510
  throw err;
5296
5511
  }
5512
+ // The delete presign refused the key's spelling. It can never be
5513
+ // deleted through presign. Scope-exclude it: no error, journal row
5514
+ // stays. Before the transient/error branches, and before Forbidden
5515
+ // handling (this error is named Forbidden).
5516
+ if (err instanceof PresignKeyRefusedError) {
5517
+ run.scopeExcludedSet.add(relativePath);
5518
+ pathResults.push({
5519
+ path: relativePath,
5520
+ status: "refused",
5521
+ operation: "delete",
5522
+ reason: "scope-excluded",
5523
+ });
5524
+ continue;
5525
+ }
5297
5526
  // VaultAccessRole explicitly denies s3:DeleteObject on
5298
5527
  // `…/workspace/.session-logs/**` (IAM `*` is unanchored). Treat that
5299
5528
  // per-key 403 as scope-excluded so it cannot mark the company
@@ -5310,6 +5539,36 @@ async function executeDeletes(run, deletePlan, decommissionPlan, counters, files
5310
5539
  });
5311
5540
  continue;
5312
5541
  }
5542
+ // FILE_ACL miss on delete (`FILES_PRESIGN_FORBIDDEN`) is a per-key
5543
+ // denial, not a run-level fault. A hard error event marked the whole
5544
+ // company `errored` after a few uploads (feedback_8a0ab4db). Skip and
5545
+ // continue; journal row stays. IAM AccessDenied on ordinary files still
5546
+ // errors. Report it the way a refused upload is reported: a diagnostic
5547
+ // per-path event (keeps the company `complete`) for the first
5548
+ // REFUSED_STALE_PATH_CAP paths and one summary for the rest, not the
5549
+ // silent scope-excluded count (feedback_682e9187). The user must be
5550
+ // able to see that the delete did not reach the cloud.
5551
+ if (isAccessDenied(err) &&
5552
+ err instanceof Error &&
5553
+ err.message.includes("FILES_PRESIGN_FORBIDDEN")) {
5554
+ run.deleteForbiddenSet.add(relativePath);
5555
+ if (run.deleteForbiddenSet.size <= REFUSED_STALE_PATH_CAP) {
5556
+ run.emit({
5557
+ type: "error",
5558
+ diagnostic: true,
5559
+ path: relativePath,
5560
+ message: `delete did not reach the cloud: the vault refused it (no write access, server delete denied: FILES_PRESIGN_FORBIDDEN); ` +
5561
+ `the cloud copy remains and the delete retries next sync`,
5562
+ });
5563
+ }
5564
+ pathResults.push({
5565
+ path: relativePath,
5566
+ status: "refused",
5567
+ operation: "delete",
5568
+ reason: "scope-excluded",
5569
+ });
5570
+ continue;
5571
+ }
5313
5572
  // Same deferral contract as a rate-limited PUT: the journal row stays
5314
5573
  // so the next pass retries, and a diagnostic error must not mark the
5315
5574
  // company `errored`. pathResults stays `refused`/`transfer-error` so
@@ -5416,9 +5675,21 @@ async function executeDeletes(run, deletePlan, decommissionPlan, counters, files
5416
5675
  });
5417
5676
  }
5418
5677
  const decommissionedSet = decommissionPlan.length > 0 ? new Set(decommissionPlan) : null;
5678
+ for (const key of deletePlan.clearUnattendedHeld ?? [])
5679
+ clearUnattendedHeldRow(run.journal, key);
5419
5680
  for (const refused of deletePlan.refusedStale) {
5420
5681
  if (decommissionedSet && decommissionedSet.has(refused.key))
5421
5682
  continue;
5683
+ if (refused.reason === "unattended-foreign-creator") {
5684
+ markUnattendedHeldRow(run.journal, refused.key, refused.createdBy, refused.createdBySub);
5685
+ }
5686
+ else if (refused.reason === "unattended-creator-unread" && refused.creatorReadDenied) {
5687
+ // A denied creator read will not change by itself. Mark the row like a
5688
+ // foreign-creator hold so the next pull restores the file and a later
5689
+ // push (interactive included) keeps holding the delete. A transient
5690
+ // failure stays unmarked: held for this pass, checked again next sync.
5691
+ markUnattendedHeldRow(run.journal, refused.key, UNREADABLE_CREATOR, undefined);
5692
+ }
5422
5693
  counters.filesRefusedStale++;
5423
5694
  if (filesRefusedStalePaths.length < REFUSED_STALE_PATH_CAP) {
5424
5695
  filesRefusedStalePaths.push(refused.key);
@@ -5429,6 +5700,8 @@ async function executeDeletes(run, deletePlan, decommissionPlan, counters, files
5429
5700
  journalEtag: refused.journalEtag,
5430
5701
  remoteEtag: refused.remoteEtag,
5431
5702
  reason: refused.reason,
5703
+ ...(refused.createdBy !== undefined ? { createdBy: refused.createdBy } : {}),
5704
+ ...(refused.creatorReadDenied ? { creatorReadDenied: true } : {}),
5432
5705
  });
5433
5706
  pathResults.push({
5434
5707
  path: refused.key,
@@ -5960,6 +6233,18 @@ function defaultConsoleLogger(event, humanSkipLines) {
5960
6233
  console.error(` ⚠ cloud-placeholder, kept on remote: ${event.path} ` +
5961
6234
  `(a .hqcloud placeholder stands in for this file, so it was not deleted)`);
5962
6235
  }
6236
+ else if (event.reason === "unattended-foreign-creator") {
6237
+ console.error(` ⚠ unattended run held a delete, kept on remote: ${event.path} ` +
6238
+ `(created by ${event.createdBy ?? "another member"}; an unattended sync never deletes a file another member created, delete it from an interactive session if that is intended)`);
6239
+ }
6240
+ else if (event.reason === "unattended-creator-unread" && event.creatorReadDenied) {
6241
+ console.error(` ⚠ unattended run held a delete, kept on remote: ${event.path} ` +
6242
+ `(this account cannot read who created it; an unattended sync deletes only a file it can show this account created, delete it from an interactive session if that is intended)`);
6243
+ }
6244
+ else if (event.reason === "unattended-creator-unread") {
6245
+ console.error(` ⚠ unattended run held a delete, kept on remote: ${event.path} ` +
6246
+ `(could not read who created it; the next sync checks again)`);
6247
+ }
5963
6248
  else if (event.reason === "state-rebuilt-deletes-held") {
5964
6249
  console.error(` ⚠ state-rebuilt-deletes-held, kept on remote: ${event.path} (complete a full authoritative sync pass to release the hold)`);
5965
6250
  }
@@ -5983,6 +6268,12 @@ function defaultConsoleLogger(event, humanSkipLines) {
5983
6268
  console.error(` ⚠ stale-etag, kept on remote: ${event.path} (journal=${event.journalEtag}, remote=${event.remoteEtag})`);
5984
6269
  }
5985
6270
  }
6271
+ else if (event.type === "delete-refused-bulk-asymmetry" && event.trigger === "scattered-deletes") {
6272
+ console.error(` ⚠ scattered-delete circuit-breaker tripped: ${event.candidates} files are missing from folders that still exist, across ${event.folders ?? "several"} top-level folders.\n` +
6273
+ ` Refusing to propagate deletes — this looks like the tree was rolled back to an older copy rather than an intentional cleanup. The pull in this sync downloads the files again.\n` +
6274
+ ` Sample refused paths: ${event.samplePaths.slice(0, 5).join(", ")}${event.samplePaths.length > 5 ? ", …" : ""}\n` +
6275
+ ` To proceed anyway: re-run with HQ_SYNC_DELETE_BULK_OVERRIDE=1 (or propagateDeletePolicy:"all").`);
6276
+ }
5986
6277
  else if (event.type === "delete-refused-bulk-asymmetry") {
5987
6278
  const pct = (event.ratio * 100).toFixed(1);
5988
6279
  console.error(` ⚠ bulk-asymmetry circuit-breaker tripped: ${event.candidates}/${event.inScope} in-scope journal entries (${pct}%) are missing locally.\n` +
@@ -6013,6 +6304,18 @@ function defaultConsoleLogger(event, humanSkipLines) {
6013
6304
  else if (event.type === "skip-archived-session-log") {
6014
6305
  console.log(` - ${event.path} skipped — the cloud copy of this session log is archived`);
6015
6306
  }
6307
+ else if (event.type === "skip-size-limit") {
6308
+ // The push leg is where this event is emitted, so without this branch a
6309
+ // file over the sync cap was skipped with no output at all. A session log
6310
+ // over the cap keeps growing locally while its vault copy goes stale.
6311
+ // The same files are over the cap on every pass, so the per-run log caps
6312
+ // these lines and prints one "and N more" summary at flush.
6313
+ const line = formatSizeLimitSkipLine(event.path, event.bytes);
6314
+ if (humanSkipLines)
6315
+ humanSkipLines.noteSizeLimit(line);
6316
+ else
6317
+ console.warn(line);
6318
+ }
6016
6319
  else if (event.type === "ignore-excluded") {
6017
6320
  // The "not silent" surface: an ignore rule dropped content that doesn't
6018
6321
  // look like expected build/VCS/cache noise, so it never reached the vault.
@@ -6934,7 +7237,15 @@ export async function computeDeletePlan(journal, syncRoot, scopeRoots, shouldSyn
6934
7237
  companyScoped = true, skipSecretPaths = false, excludedPaths = new Set(), holdRemoteDeletes = false,
6935
7238
  // Scoped (watcher) pushes only: reads the whole journal so the breaker's
6936
7239
  // denominator matches a full pass. Called only when the scoped ratio trips.
6937
- bulkBaselineJournal) {
7240
+ bulkBaselineJournal,
7241
+ // Hashes of files this same push uploads. A missing row whose bytes are
7242
+ // among them (or on another live journal row) was moved or renamed, so the
7243
+ // scattered-delete breaker skips it.
7244
+ liveContentHashes,
7245
+ // feedback_65ee9e51: set for unattended runs (see
7246
+ // ../sync/unattended-delete-hold.ts). Every remote delete is then checked
7247
+ // against the HEAD `created-by-sub` and held unless the caller created it.
7248
+ unattendedDeleteHold) {
6938
7249
  const plan = { toDelete: [], toTombstone: [], refusedStale: [] };
6939
7250
  if (scopeRoots.length === 0)
6940
7251
  return plan;
@@ -7063,6 +7374,41 @@ bulkBaselineJournal) {
7063
7374
  continue;
7064
7375
  }
7065
7376
  }
7377
+ // feedback_65ee9e51: a delete an unattended push already held stays held
7378
+ // (any run) until the pull restores the file, and is kept out of both
7379
+ // breakers. A file back on disk loses the marker and syncs normally.
7380
+ if (entry.unattendedHeldBy !== undefined) {
7381
+ // A path the ignore rules now exclude is never deleted or restored, so
7382
+ // drop its marker instead of reporting the hold on every push.
7383
+ const nowIgnored = !presentLocally && isPathExcludedFromSync(shouldSync, localPath);
7384
+ if (presentLocally || nowIgnored) {
7385
+ (plan.clearUnattendedHeld ??= []).push(relativeKey);
7386
+ if (nowIgnored)
7387
+ continue;
7388
+ }
7389
+ else {
7390
+ inScopeJournalEntries--;
7391
+ // A row held because its creator HEAD was denied keeps reporting as
7392
+ // such, so the console line stays accurate; the executor re-marks it.
7393
+ plan.refusedStale.push(entry.unattendedHeldBy === UNREADABLE_CREATOR
7394
+ ? {
7395
+ key: relativeKey,
7396
+ journalEtag: entry.remoteEtag ?? "<not-checked>",
7397
+ remoteEtag: "<not-checked>",
7398
+ reason: "unattended-creator-unread",
7399
+ creatorReadDenied: true,
7400
+ }
7401
+ : {
7402
+ key: relativeKey,
7403
+ journalEtag: entry.remoteEtag ?? "<not-checked>",
7404
+ remoteEtag: "<not-checked>",
7405
+ reason: "unattended-foreign-creator",
7406
+ createdBy: entry.unattendedHeldBy,
7407
+ ...(entry.createdBySub ? { createdBySub: entry.createdBySub } : {}),
7408
+ });
7409
+ continue;
7410
+ }
7411
+ }
7066
7412
  if (holdRemoteDeletes && !presentLocally) {
7067
7413
  plan.refusedStale.push({
7068
7414
  key: relativeKey,
@@ -7095,6 +7441,14 @@ bulkBaselineJournal) {
7095
7441
  if (!presentLocally && hasLocalOriginalForMissingPlaceholder(localPath)) {
7096
7442
  continue;
7097
7443
  }
7444
+ // feedback_65ee9e51: the presign server refuses this key's spelling on
7445
+ // every op, so a delete can never succeed. Drop it before toDelete,
7446
+ // headCandidates, and the unattended HEAD. Not deleted, not tombstoned,
7447
+ // not a breaker candidate. The journal row stays.
7448
+ if (presignDeleteKeyRefused(ctx, relativeKey)) {
7449
+ inScopeJournalEntries--;
7450
+ continue;
7451
+ }
7098
7452
  // Reindex's legacy Knowledge migration is a representation transition,
7099
7453
  // not a user-content deletion: the exact key changed from a symlink object
7100
7454
  // to a real directory whose children are uploaded separately. The normal
@@ -7348,7 +7702,17 @@ bulkBaselineJournal) {
7348
7702
  }
7349
7703
  inScopeJournalEntries = Math.max(inScopeJournalEntries, baseline);
7350
7704
  }
7351
- if (bulkGuardApplies && bulkRatioTrips()) {
7705
+ // Scattered-delete breaker (feedback_65089095, ../sync/scattered-delete-burst.ts).
7706
+ // Runs only when the ratio breaker did not trip, before any HEAD, under the
7707
+ // same bypasses. The pull leg applies the same rule, so it downloads these
7708
+ // files back instead of tombstoning them.
7709
+ const scattered = policy !== "all" && !isBulkAsymmetryOverride() && !(bulkGuardApplies && bulkRatioTrips())
7710
+ ? detectScatteredDeleteBurst([
7711
+ ...plan.toDelete.map((item) => item.key),
7712
+ ...headCandidates.flatMap((c) => (c.materializedKnowledgeDir ? [] : [c.key])),
7713
+ ], journal, syncRoot, liveContentHashes, { countLocalDeleteTombstones: true })
7714
+ : undefined;
7715
+ if ((bulkGuardApplies && bulkRatioTrips()) || scattered) {
7352
7716
  // Move every staged candidate (both already-bucketed toDelete from
7353
7717
  // owned-only and queued headCandidates from currency-gated) into
7354
7718
  // refusedStale with reason "bulk-asymmetry", and re-label the intent-less
@@ -7384,11 +7748,15 @@ bulkBaselineJournal) {
7384
7748
  // label. #227 dropped this line, so a tripped breaker stopped nothing it
7385
7749
  // had not already refused for another reason.
7386
7750
  plan.toDelete = [];
7751
+ // A scattered trip reports only the files that tripped it (not moves or
7752
+ // files in deleted folders it also holds), sampled from those files.
7753
+ const candidates = scattered ? scattered.keys.length : bulkCandidatePicks;
7387
7754
  plan.bulkAsymmetry = {
7388
- candidates: bulkCandidatePicks,
7755
+ candidates,
7389
7756
  inScope: inScopeJournalEntries,
7390
- ratio: bulkCandidatePicks / inScopeJournalEntries,
7391
- samplePaths,
7757
+ ratio: inScopeJournalEntries > 0 ? candidates / inScopeJournalEntries : 1,
7758
+ samplePaths: scattered ? scattered.samplePaths : samplePaths,
7759
+ ...(scattered ? { trigger: "scattered-deletes", folders: scattered.areas } : {}),
7392
7760
  };
7393
7761
  // Litter still drains even when the breaker trips — see `litterToDelete`
7394
7762
  // declaration. The breaker protects against corrupt-mirror mass-deletes
@@ -7408,7 +7776,92 @@ bulkBaselineJournal) {
7408
7776
  // Warm the GET presigns the HEAD pass reuses so a large candidate set doesn't
7409
7777
  // mint one presign per HEAD and trip the presign breaker. Mirrors the
7410
7778
  // new-files + tombstone HEAD-pass pre-primes.
7411
- await primeObjectTransport(ctx, "get", headCandidates.map((c) => c.key));
7779
+ // Unattended hold: `owned-only` and `all` put deletes straight into
7780
+ // `toDelete` without a HEAD. Take them out and send them through a HEAD
7781
+ // too, so the creator check below sees every remote delete.
7782
+ const unheadedDeletes = unattendedDeleteHold ? plan.toDelete : [];
7783
+ if (unattendedDeleteHold)
7784
+ plan.toDelete = [];
7785
+ await primeObjectTransport(ctx, "get", [...headCandidates.map((c) => c.key), ...unheadedDeletes.map((item) => item.key)]);
7786
+ const holdForeignDelete = (key, journalEtag, remote) => {
7787
+ if (!unattendedDeleteHold || unattendedMayDelete(unattendedDeleteHold, remote.metadata)) {
7788
+ return false;
7789
+ }
7790
+ plan.refusedStale.push({
7791
+ key,
7792
+ journalEtag,
7793
+ remoteEtag: normalizeEtag(remote.etag),
7794
+ reason: "unattended-foreign-creator",
7795
+ createdBy: describeRemoteCreator(remote.metadata),
7796
+ ...(remote.metadata?.["created-by-sub"]
7797
+ ? { createdBySub: remote.metadata["created-by-sub"] }
7798
+ : {}),
7799
+ });
7800
+ return true;
7801
+ };
7802
+ for (let i = 0; i < unheadedDeletes.length; i += DELETE_PLAN_HEAD_CONCURRENCY) {
7803
+ const chunk = unheadedDeletes.slice(i, i + DELETE_PLAN_HEAD_CONCURRENCY);
7804
+ const results = await Promise.all(chunk.map(async (item) => {
7805
+ try {
7806
+ return {
7807
+ item,
7808
+ remote: await headRemoteFile(ctx, item.key),
7809
+ unread: false,
7810
+ denied: false,
7811
+ scopeExcluded: false,
7812
+ };
7813
+ }
7814
+ catch (err) {
7815
+ // A session-level auth refusal is a run-level fact, as at every other
7816
+ // HEAD site: propagate it so the pass aborts once instead of holding
7817
+ // every delete on a dead session.
7818
+ if (isRunLevelRegistrarFailure(err))
7819
+ throw err;
7820
+ // A spelling refusal is permanent and is not "unreadable". Skip this
7821
+ // pass the way the currency-gated HEAD does: no refusedStale entry,
7822
+ // no creatorReadDenied, and the key is not deleted.
7823
+ if (err instanceof PresignKeyRefusedError) {
7824
+ return { item, remote: null, unread: false, denied: false, scopeExcluded: true };
7825
+ }
7826
+ // These policies never HEADed before the hold, so a failed HEAD must
7827
+ // not fail the push. Any failure, a denial (403) included, leaves
7828
+ // the creator unknown, and an unattended run deletes only a file it
7829
+ // can show the caller created: hold this key. A transient failure is
7830
+ // held for this pass only. A denial will not change by itself, so it
7831
+ // is reported as such and the executor marks the row, which makes
7832
+ // the next pull restore the file and later pushes keep the hold.
7833
+ return {
7834
+ item,
7835
+ remote: null,
7836
+ unread: true,
7837
+ denied: isAccessDenied(err),
7838
+ scopeExcluded: false,
7839
+ };
7840
+ }
7841
+ }));
7842
+ for (const { item, remote, unread, denied, scopeExcluded } of results) {
7843
+ if (scopeExcluded)
7844
+ continue;
7845
+ const journalEtag = journalRows(journal).get(item.key)?.remoteEtag ?? "<not-checked>";
7846
+ if (unread) {
7847
+ plan.refusedStale.push({
7848
+ key: item.key,
7849
+ journalEtag,
7850
+ remoteEtag: "<not-checked>",
7851
+ reason: "unattended-creator-unread",
7852
+ ...(denied ? { creatorReadDenied: true } : {}),
7853
+ });
7854
+ continue;
7855
+ }
7856
+ if (remote === null) {
7857
+ plan.toTombstone.push(item.key);
7858
+ continue;
7859
+ }
7860
+ if (holdForeignDelete(item.key, journalEtag, remote))
7861
+ continue;
7862
+ plan.toDelete.push(item);
7863
+ }
7864
+ }
7412
7865
  for (let i = 0; i < headCandidates.length; i += DELETE_PLAN_HEAD_CONCURRENCY) {
7413
7866
  const chunk = headCandidates.slice(i, i + DELETE_PLAN_HEAD_CONCURRENCY);
7414
7867
  const results = await Promise.all(chunk.map(async (c) => {
@@ -7450,6 +7903,12 @@ bulkBaselineJournal) {
7450
7903
  continue;
7451
7904
  }
7452
7905
  }
7906
+ // A verified Knowledge marker is a representation change, not a
7907
+ // content delete (its children are uploaded), so it is not held.
7908
+ if (!candidate.materializedKnowledgeDir &&
7909
+ holdForeignDelete(candidate.key, candidate.journalEtag, remote)) {
7910
+ continue;
7911
+ }
7453
7912
  plan.toDelete.push({
7454
7913
  key: candidate.key,
7455
7914
  intentVersion: candidate.intentVersion,