Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/gbra133-pr2b' into capy/one-shot-cli-writes

garrytan47b82efb1748
diff --cc src/cli/main.ts
index a2275a2dce,8b1142423a..51202d80e3
--- a/src/cli/main.ts
+++ b/src/cli/main.ts
@@@ -679,7 -680,7 +682,7 @@@ async function runSharedOperation(comma
if (op.scope === 'read') {
try {
rawResult = await withTimeout(
- withRequestIdentityMemo(() => op.handler(ctx, params)).catch(async (e: unknown) => { // large pages: a segmented page streams to stdout
- configSnapshot!.run(() => op.handler(ctx, params)).catch(async (e: unknown) => { // large pages: a segmented page streams to stdout
++ configSnapshot!.run(() => withRequestIdentityMemo(() => op.handler(ctx, params))).catch(async (e: unknown) => { // large pages: a segmented page streams to stdout
if (op.name === 'get_page' && await streamSegmentedGet(engine, params, e, writeStdoutFinal)) return SEGMENTED_STREAMED;
throw e;
}),
diff --cc src/core/config-snapshot.ts
index f90c547067,516a526334..70ef9256d8
--- a/src/core/config-snapshot.ts
+++ b/src/core/config-snapshot.ts
@@@ -101,20 -101,32 +101,35 @@@ function activeSnapshot(engine: object)
return store && !store.live && store.held.open && store.held.engine === engine ? store.held : undefined;
}
-/** Run `fn` with one config snapshot of `engine`; an enclosing snapshot of the same engine is reused. */
-export async function withRequestConfigSnapshot<T>(engine: BulkConfigReader, fn: () => Promise<T>): Promise<T> {
+/**
+ * Run `fn` with one config snapshot of `engine`; an enclosing snapshot of the same engine is reused. `seed` (GBRA-156) is
+ * a whole-table read this command already took (`commandStartupConfig`), which the snapshot answers from instead of reading again.
+ */
+export async function withRequestConfigSnapshot<T>(engine: BulkConfigReader, fn: () => Promise<T>, seed?: Record<string, string>): Promise<T> {
if (activeSnapshot(engine)) return fn();
- const held: RequestSnapshot = { engine, open: true, rows: seed ? Promise.resolve(new Map(Object.entries(seed))) : null };
- const snapshot = openRequestConfigSnapshot(engine);
++ const snapshot = openRequestConfigSnapshot(engine, seed);
try {
- return await requestSnapshot.run({ held, live: false }, fn);
+ return await snapshot.run(fn);
} finally {
- held.open = false;
+ snapshot.close();
}
}
+ /**
+ * One snapshot of `engine` shared by separate calls that cannot sit inside one
+ * callback (#7147: a CLI read builds its context, then runs the operation,
+ * each under its own timeout). Each `run(fn)` reads config the way
+ * `withRequestConfigSnapshot` does, all from the same snapshot; `close()`
+ * ends it, so later reads, and work a run left behind, read live.
+ */
-export function openRequestConfigSnapshot(engine: BulkConfigReader): { run<T>(fn: () => Promise<T>): Promise<T>; close(): void } {
- const held: RequestSnapshot = { engine, open: true, rows: null };
++export function openRequestConfigSnapshot(engine: BulkConfigReader, seed?: Record<string, string>): { run<T>(fn: () => Promise<T>): Promise<T>; close(): void } {
++ const held: RequestSnapshot = { engine, open: true, rows: seed ? Promise.resolve(new Map(Object.entries(seed))) : null };
+ return {
+ run: fn => activeSnapshot(engine) ? fn() : requestSnapshot.run({ held, live: false }, fn),
+ close: () => { held.open = false; },
+ };
+ }
+
/** Run `fn` reading config live (a write operation inside a request); the request's snapshot is retaken after it. */
export async function withoutRequestConfigSnapshot<T>(fn: () => Promise<T>): Promise<T> {
const store = requestSnapshot.getStore();
diff --cc src/core/db.ts
index a8d38b5c75,3a2527fe31..a6095327e5
--- a/src/core/db.ts
+++ b/src/core/db.ts
@@@ -1,6 -1,7 +1,7 @@@
import postgres from '#postgres'
-import { claimOwner } from './persistence/claim-phase.ts';
+import { claimOwner, isOneShotCommand } from './persistence/claim-phase.ts';
import { traceSqlOptions } from './sql-trace.ts';
+ import { warnPoolerPrepareOffOnce } from './pooler-notice.ts';
import { GBrainError, type EngineConfig } from './types.ts';
import { SCHEMA_SQL } from './schema-embedded.generated.ts';
import { applyPostgresForwardReferenceBootstrap } from './engine-sql/bootstrap.ts';