Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/capy/wave-b-pr4-iface2' into capy/wave-b-pr4-embed2
garrytan413e3e48a778
diff --cc src/core/page-embedding-lease.tsindex cee7f201cc,55f95a0850..18504645a9--- a/src/core/page-embedding-lease.ts+++ b/src/core/page-embedding-lease.ts@@@ -30,31 -24,16 +30,34 @@@ export const PAGE_EMBEDDING_LEASE_TTL_Mconst LEASE_REFRESH_MS = 30_000;const LEASE_WAIT_MAX_MS = 1_000;-/** Test seam: called each time a path finds a page's lease held by another path, before it waits. */-export const pageEmbeddingLeaseProbe: { contended?: (pageId: number) => void } = {};+/**+ * Test seams: `contended` runs each time a path finds a page's lease held by another path, before it waits;+ * `waitBoundMs` replaces the default wait bound (one TTL).+ */+export const pageEmbeddingLeaseProbe: { contended?: (pageId: number) => void; waitBoundMs?: number } = {};+ /** Every page embedding lease id starts with this; the writer admin fingerprint leaves these rows out (admin-intent.ts). */+ export const PAGE_EMBEDDING_LEASE_PREFIX = 'embed-page:';+export function pageEmbeddingLeaseId(pageId: number): string {- return `embed-page:${pageId}`;+ return `${PAGE_EMBEDDING_LEASE_PREFIX}${pageId}`;}+/**+ * A page's embedding lease. `busy`: another path held it through the whole wait, nothing was taken and the+ * caller leaves the page to that path. Otherwise `assertHeld(tx)` renews it inside the install transaction and+ * throws `lock_busy` when the renewal matches no row (it expired and was taken or deleted), so nothing installs.+ */+export type PageEmbeddingLease = AsyncDisposable & ({ busy: true } | { busy: false; assertHeld(tx: Pick<BrainEngine, 'executeRaw'>): Promise<void> });++/** The retryable error for a page whose embedding lease another path holds (`lost`: this holder's lease was taken over). */+export function pageEmbeddingLeaseUnavailable(pageId: number, lost: boolean): OperationError {+ return opError('lock_busy', lost ? 'This page\'s embedding lease was lost before the install.' : 'Another path is embedding this page.',+ lost ? `The embedding lease of page ${pageId} expired and was taken or reclaimed by another path, so this attempt installed no vectors; that path or the next embed run embeds the page.`+ : `Another path held the embedding lease of page ${pageId} through the whole wait, so this attempt sent nothing to the provider; that path embeds the page, and a retry embeds only what it leaves.`,+ { fix: readFix('Shows the gbrain_cycle_locks rows, embed-page leases included, with holder and expiry, read-only.', { argv: ['gbrain', 'status', '--section', 'locks', '--json'] }) });+}+function pause(ms: number, signal?: AbortSignal): Promise<void> {return new Promise(resolve => {const done = () => { clearTimeout(timer); signal?.removeEventListener('abort', done); resolve(); };