Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(atoms): connector email/meeting atom extraction is on by default; connector_pages=false opts out

garrytan7530e1d4a813
diff --git a/docs/architecture/key-files/core-cycle-continued.md b/docs/architecture/key-files/core-cycle-continued.md
index 7b072ca95f..205263d1d6 100644
--- a/docs/architecture/key-files/core-cycle-continued.md
+++ b/docs/architecture/key-files/core-cycle-continued.md
@@ -20,4 +20,4 @@ Synthesis, patterns, consolidation and connector atom gating.
- `src/core/cycle/concept-publication.ts` — managed `synthesize_concepts` publication: `publishManagedConcept` publishes through `publishMaintenancePage` (a concept with a recorded `source_path` republishes to its file unless a `db_only` tier covers it; new concepts are database-only), and `composeConceptRepublication` keeps an existing concept's facts/takes fences, timeline, tags and other frontmatter, holding the concept (`concept_preservation_hold`) when a fence is duplicated, unbalanced, unparseable or below the timeline sentinel. `addManagedProvenanceLinks` commits the concept-provenance edges inside a coordinated transaction. The phase keeps the private-first, provenance, then promotion order; revision races are deferred and holds reported in the phase details. Tests: `test/managed-writers-w3.test.ts`.
-- `src/core/cycle/connector-atoms.ts` — the connector atom opt-in (#5856). `CONNECTOR_ATOM_PAGES_KEY` (`cycle.extract_atoms.connector_pages`, default off; `connectorAtomPagesEnabled` accepts true/1/on/yes) gates `CONNECTOR_ATOM_PAGE_TYPES` (`email`, `meeting`) of sources whose `config.kind` is a connector kind (`CONNECTOR_SOURCE_KINDS`). `connectorAtomExclusionSql` returns the `pages p` predicate atom discovery and the backlog count append (empty when opted in), so no routine cycle, `dream --drain` or autopilot auto-drain sends connector mail or calendar bodies to the model until the user opts in. Other page types of a connector source and every checkout-backed page are unaffected. Tests: the `atom_drain_default_off` and `atom_drain_opted_in` cases of `test/helpers/managed-connector-job-contract.ts`, run by `test/managed-connector-job-contract.test.ts` and its Postgres twin `test/e2e/managed-connector-job-contract.test.ts`.
+- `src/core/cycle/connector-atoms.ts` — the connector atom setting (#5856). `CONNECTOR_ATOM_PAGES_KEY` (`cycle.extract_atoms.connector_pages`, on when unset; `connectorAtomPagesEnabled` treats only false/0/off/no as opted out) gates `CONNECTOR_ATOM_PAGE_TYPES` (`email`, `meeting`) of sources whose `config.kind` is a connector kind (`CONNECTOR_SOURCE_KINDS`). `connectorAtomExclusionSql` returns the `pages p` predicate atom discovery and the backlog count append (empty unless opted out), so the routine cycle, `dream --drain` and autopilot auto-drain extract connector mail and calendar pages under the auto-drain budget until the user opts out. Other page types of a connector source and every checkout-backed page are unaffected. Tests: `test/connector-atom-pages.test.ts`, `test/autopilot-auto-drain-dispatch.test.ts`, and the `atom_drain_default_on` / `atom_drain_opted_out` cases of `test/helpers/managed-connector-job-contract.ts`, run by `test/managed-connector-job-contract.test.ts` and its Postgres twin `test/e2e/managed-connector-job-contract.test.ts`.
diff --git a/docs/architecture/key-files/core-cycle.md b/docs/architecture/key-files/core-cycle.md
index e0c4e88e96..c4dd64d62b 100644
--- a/docs/architecture/key-files/core-cycle.md
+++ b/docs/architecture/key-files/core-cycle.md
@@ -17,7 +17,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/core/cycle/extract-atoms-drain.ts` — pure single-hold bounded drain for the silent lens-phase backlog. `runExtractAtomsDrain(deps, opts)` over injected deps (`withLock`, `runBatch`, `countRemaining`, `now`, optional `onBatch`) loops bounded batches under ONE lock hold, rediscovering eligibility each batch (idempotent NOT-EXISTS-on-`source_hash`; no cross-window cursor), until the backlog is empty or the window ends. Two stop signals: HARD (job `signal` + the lock's lease-loss signal + `deadlineAtMs`) reaches the chat call, the pacing pause and every backlog count; SOFT (hard + the window timer) is checked only between batches and items, so the item in flight finishes. Counts are cancellable and bounded (`countTimeoutMs`, capped by the remaining deadline). `stopped` is a `DrainStop` (`drained|window|deadline|lock_lost|aborted|no_progress|max_batches|provider_failure`); a hard stop skips `onBatch` and the recount and reports the last count as `remaining`, and the lease loss `withRefreshingLock` rethrows becomes `lock_lost` with the partial counters. Backs `gbrain dream --phase extract_atoms --drain` under the SAME `cycleLockIdFor(sourceId)` the routine cycle takes (a concurrent tick defers with `cycle_already_running`). `runExtractAtomsDrainForSource(engine, {sourceId, windowSeconds, brainDir?, maxBatches?, onBatch?, signal?, deadlineAtMs?})` owns the lock+batch+count wiring for all three callers — `dream --drain`, the `extract-atoms-drain` Minion handler, autopilot auto-drain. `sourceId: undefined` → legacy `gbrain-cycle` lock + `'default'`; a real id → `gbrain-cycle:<id>`. `LockUnavailableError` propagates. One `runExtractAtomsDrainForSource` call is one drain attempt: its batches share one `BudgetTracker` (the per-run `cycle.extract_atoms.budget_usd` cap is the attempt's cap) and one `MaintenanceWriteWait` (`persistence/maintenance-wait.ts`, bounded by `deadlineAtMs`). `structuralAtomRefusal` maps an `owner_unavailable`/`permission_denied` refusal from the atom session preflight to `STRUCTURAL_REFUSAL_PREFIX` text; the `extract-atoms-drain` Minion handler (`src/core/minions/handlers/extract-atoms-drain.ts`) throws it as `UnrecoverableError`, so the job dead-letters once with no model call and the auto-drain cap does not count it. `last_error` and the typed failure records pass through `sanitizeFailureText` (secret/DSN redaction, bounded). `formatDrainProviderFailure(result, {final?})` renders the handler's `provider_failure` throw; the handler throws `UnrecoverableError` on `deadline` or any failure at/past `deadlineAtMs`, the job's abort reason on `aborted`, and a retryable error on `lock_lost`. Tests: `test/extract-atoms-drain*.test.ts`.
-- `src/core/cycle/extract-atoms.ts` — the extract_atoms lens phase: mines eligible pages into `atoms/<date>/<stem>-<hash>` pages. Transcript input is paste-stripped before the cut (#5812); discovery skips self-captures (#5820). Discovery and the backlog count append `connectorAtomExclusionSql` (`connector-atoms.ts`), so connector `email`/`meeting` pages stay out until `cycle.extract_atoms.connector_pages` is on. A drain attempt passes `opts.attempt` (`budgetTracker`, `writeWait`) so its batches share one budget and one maintenance publish wait. Eligibility reads source-incarnation/page/full-hash-keyed derived scan state; scan and failure markers do not mutate canonical frontmatter. Managed extraction checks source-wide local authority and owner readiness before provider work, admits outputs plus a completion request together, and replays retained output without another model call. Managed atom files keep provisional source hashes; only the source-incarnation/page/full-hash durable completion receipt excludes an item from discovery and backlog counts. Unmanaged atom completion flips and their cardinality check share a transaction after provenance links persist, so a partial match rolls back and stays retryable. An undated source dates its atoms by the source page's creation date (`undated` for transcripts), never the run date. After an unmanaged item completes, `retireStaleAtoms` soft-deletes that source's atoms from earlier extractions (other or provisional `source_hash`) that this extraction did not re-produce. Hard `opts.signal` (chat call, pacing, checks before each item and commit) leaves no strike, receipt or rollup; soft `opts.stopSignal` stops before the next item.
+- `src/core/cycle/extract-atoms.ts` — the extract_atoms lens phase: mines eligible pages into `atoms/<date>/<stem>-<hash>` pages. Transcript input is paste-stripped before the cut (#5812); discovery skips self-captures (#5820). Discovery and the backlog count append `connectorAtomExclusionSql` (`connector-atoms.ts`), so connector `email`/`meeting` pages stay out only when `cycle.extract_atoms.connector_pages` is false. A drain attempt passes `opts.attempt` (`budgetTracker`, `writeWait`) so its batches share one budget and one maintenance publish wait. Eligibility reads source-incarnation/page/full-hash-keyed derived scan state; scan and failure markers do not mutate canonical frontmatter. Managed extraction checks source-wide local authority and owner readiness before provider work, admits outputs plus a completion request together, and replays retained output without another model call. Managed atom files keep provisional source hashes; only the source-incarnation/page/full-hash durable completion receipt excludes an item from discovery and backlog counts. Unmanaged atom completion flips and their cardinality check share a transaction after provenance links persist, so a partial match rolls back and stays retryable. An undated source dates its atoms by the source page's creation date (`undated` for transcripts), never the run date. After an unmanaged item completes, `retireStaleAtoms` soft-deletes that source's atoms from earlier extractions (other or provisional `source_hash`) that this extraction did not re-produce. Hard `opts.signal` (chat call, pacing, checks before each item and commit) leaves no strike, receipt or rollup; soft `opts.stopSignal` stops before the next item.
Managed completion admits revision-pinned `managed_atom_delete` children alongside replacement pages, removes canonical files through the page deletion path, and commits its checkpoint only after every publication and retirement commits.
Both paths prevent LLM-chosen titles that drift between extractions from piling up.
Atom identity: page-derived atoms fold the source-page slug into the slug hash (8 chars, NUL-separated) so two same-date pages emitting the same title get DISTINCT slugs; the source CONTENT hash is deliberately NOT folded (a reworded source still upserts rather than duping); transcript atoms keep the legacy title-only 6-char hash. `resolvePageAtomSlug` adopts a legacy-slug atom with a compatible binding in place on re-extraction (upgrade idempotency — no migration, no duplicate), while `assertAtomImportBinding` fail-closed refuses to reuse a slug bound to a DIFFERENT source locator. Both share `isCompatibleAtomBinding(frontmatter, sourcePageSlug)` — the ONE definition of compatible: bound to THIS source page, or carrying no `source_slug`/`source_path` at all (pre-binding-era adoption, not a clobber); a `source_path`-bound legacy transcript atom or a different `source_slug` is a different origin, and a non-atom page squatting on the slug is refused. `source_quote` is verified at extraction time against the exact `truncateUtf8` prompt prefix the model saw (`locateQuote` advances by full code points): located quotes persist original characters + [start,end) offsets + `source_quote_verified`; unlocatable quotes are dropped with the atom kept. Edges write before the completion flip; per-item drain failures stay typed (bounded, sanitized, reconcilable). Transcript items carry the same failure-count/tombstone machinery as pages, in the `extract_atoms_transcript_state` table (keyed `(source_id, file_path, content_hash)`, 16-char hash prefix, so an edit is a new row): `recordItemFailureCount` counts a transcript's malformed output or prompt-level provider block (`providerContentBlockReason`; never feeds the outage halt) toward `MAX_DETERMINISTIC_FAILURES`, a zero-yield transcript tombstones immediately (as pages do), and `tombstonedTranscriptsForHashes` is the batch read-side gate mirroring `atomsExistingForHashes` (fail-open on error). Reported as `tombstoned_transcripts` (paths), separate from the page-slug `tombstoned_for_failures`. Malformed managed output requires a newly approved protected-job retry identity; publication retry reuses retained output and original/current grants.
diff --git a/docs/fix-wave-notes/capy-gbra35-defaults-on.md b/docs/fix-wave-notes/capy-gbra35-defaults-on.md
new file mode 100644
index 0000000000..62ed69396d
--- /dev/null
+++ b/docs/fix-wave-notes/capy-gbra35-defaults-on.md
@@ -0,0 +1,13 @@
+# Fix-wave notes: capy/gbra35-defaults-on (GBRA-35)
+
+Contributor branch for the next fix wave. No migration, no VERSION or CHANGELOG edits.
+
+## CHANGELOG text
+
+- **Atom extraction covers Gmail and Calendar pages again, by default (#5856 follow-up).** v0.60.32.0 made atom extraction of connector `email`/`meeting` pages opt-in, which also stopped it on brains that already extracted them. It is on by default again, on every brain, still bounded by the per-attempt auto-drain budget and the structural-refusal and fair-dispatch fixes from v0.60.32.0. To keep connector mail and calendar text away from the `extract_atoms` model: `gbrain config set cycle.extract_atoms.connector_pages false` (`gbrain config unset cycle.extract_atoms.connector_pages` returns to the default). `gbrain config set autopilot.auto_drain.enabled false` still stops all automatic atom drains.
+
+## Evidence
+
+- `src/core/cycle/connector-atoms.ts`: unset means on; only `false`/`0`/`off`/`no` opt out.
+- With the source change reverted: `test/connector-atom-pages.test.ts` 1 pass / 1 fail, `test/autopilot-auto-drain-dispatch.test.ts` 2 / 4, `test/managed-connector-job-contract.test.ts` 14 / 1. With it: 2/2, 6/6, 15/15.
+- No stored `false` exists from v0.60.32.0 (the old default wrote no key), so no data migration is needed.
diff --git a/docs/guides/google-connect.md b/docs/guides/google-connect.md
index 0b1fabb395..4de6c77cbe 100644
--- a/docs/guides/google-connect.md
+++ b/docs/guides/google-connect.md
@@ -183,12 +183,11 @@ calendar pages."*
inbound, 72 h for your own question) is re-checked when the window ends,
even if no new mail arrives, and opens its loop then. See
[open loops](open-loops.md#quiet-threads-and-grace-holds).
-- **Atoms (opt-in).** Atom extraction skips Gmail threads and Calendar events
- until you opt in with `gbrain config set cycle.extract_atoms.connector_pages
- true`. After that, the text of each extracted email thread or calendar event
- is sent to the configured `extract_atoms` model under the daily auto-drain
- cap. `gbrain config set cycle.extract_atoms.connector_pages false` stops new
- extraction. Caps, the off switch and exactly what leaves the machine:
+- **Atoms (on by default).** Atom extraction covers Gmail threads and Calendar
+ events like other pages: the text of each extracted email thread or calendar
+ event is sent to the configured `extract_atoms` model under the daily
+ auto-drain cap. `gbrain config set cycle.extract_atoms.connector_pages false`
+ opts out and stops new extraction. Caps, the off switch and exactly what leaves the machine:
[spend controls](../operations/spend-controls.md#atom-extraction-auto-drain-cap-and-connector-pages).
`gbrain doctor`'s `orphan_ratio` reports orphaned email and meeting renders of
@@ -349,9 +348,9 @@ upstream failures rather than triggering a full re-list.
capped per sweep) to your configured chat provider. Kill switch:
`gbrain config set loops.extraction_enabled false`. The deterministic
unanswered-thread detector is free and always on.
-- Atom extraction from email and calendar pages is off until you run
- `gbrain config set cycle.extract_atoms.connector_pages true`; then page
- text goes to the `extract_atoms` model under the auto-drain cap
+- Atom extraction from email and calendar pages is on by default: page text
+ goes to the `extract_atoms` model under the auto-drain cap. Opt out with
+ `gbrain config set cycle.extract_atoms.connector_pages false`
([spend controls](../operations/spend-controls.md#atom-extraction-auto-drain-cap-and-connector-pages)).
## File permissions
diff --git a/docs/operations/spend-controls.md b/docs/operations/spend-controls.md
index 6f5e97a527..5056b8d73f 100644
--- a/docs/operations/spend-controls.md
+++ b/docs/operations/spend-controls.md
@@ -64,7 +64,7 @@ The USD-limit knobs accept `off`, `unlimited`, or `none` (case-insensitive) to m
| Image-OCR per-run ceiling | `embedding_image_ocr_max_images` / `embedding_image_ocr_max_usd` | `200` images / `$1.00` (estimated) | skips OCR over-cap (import continues; skips counted in `ocr_skipped_budget`, surfaced by doctor `ocr_health`) | `0` disables that cap | **not** bypassed (per-run cap, not a tracker gate) |
| Dream `extract_atoms` phase budget | `cycle.extract_atoms.budget_usd` | `0.30` | caps the phase's budget tracker (one tracker per drain attempt, across all its batches) | — | **not** consulted (phase budget enforces regardless) |
| Atom auto-drain daily cap | `autopilot.auto_drain.max_usd_per_day` | `2.00` | daily cap on drain **attempts** (`floor(max / 0.30)` = 6), not a dollar ledger | `gbrain config set autopilot.auto_drain.enabled false` | **not** consulted |
-| Connector email/meeting atoms | `cycle.extract_atoms.connector_pages` | `false` (opt-in) | Gmail/Calendar `email`/`meeting` pages are skipped by atom extraction | leave unset / `false` | **not** consulted |
+| Connector email/meeting atoms | `cycle.extract_atoms.connector_pages` | on (unset) | Gmail/Calendar `email`/`meeting` pages are extracted like other pages, under the auto-drain cap | `false` | **not** consulted |
| Dream `synthesize` per-run budget | `dream.synthesize.budget_usd` | `5` | defers the transcript and the rest of the run before submission (estimate: prompt size + child output cap, x `max_turns` in agentic mode) | `unlimited` (`0` = submit nothing) | **not** consulted |
| Dream `synthesize` daily submission cap | `dream.synthesize.max_submissions_per_source_per_day` | `0` (off) | skips whole files; a failed count query submits nothing that run | `0` | **not** consulted |
| Dream `BudgetMeter` phases (auto_think, drift, propose/grade takes, calibration) | `dream.auto_think.budget`, `dream.drift.budget`, `cycle.<phase>.budget_usd` | per phase | refuses the next submit past the cap | `unlimited` (`0` = spend nothing) | **not** consulted |
@@ -135,23 +135,24 @@ writer would refuse, and logs why. Checkout-backed and connector sources take
turns for the daily slots. With a model the tracker cannot price, the dollar
limit is not enforced (see above); only the attempt count bounds the drain.
-Connector pages are opt-in. Gmail threads (`email`) and Calendar events
-(`meeting`) from a Google or GitHub connector source are skipped by atom
-discovery, the backlog count, the routine cycle, `gbrain dream --drain` and
-the auto-drain until you turn them on:
+Connector pages are extracted by default. Gmail threads (`email`) and
+Calendar events (`meeting`) from a Google or GitHub connector source go
+through atom discovery, the backlog count, the routine cycle,
+`gbrain dream --drain` and the auto-drain like any other page, under the caps
+above. To keep them out:
```bash
-gbrain config set cycle.extract_atoms.connector_pages true # opt in
-gbrain config set cycle.extract_atoms.connector_pages false # opt out again
+gbrain config set cycle.extract_atoms.connector_pages false # opt out
+gbrain config unset cycle.extract_atoms.connector_pages # back to the default (on)
gbrain config set autopilot.auto_drain.enabled false # stop all automatic atom drains
```
-What leaves the machine when you opt in: the page text of each extracted email
+What leaves the machine while it is on: the page text of each extracted email
thread or calendar event (message bodies, subjects, participants as rendered on
the page, up to `cycle.extract_atoms.max_input_chars`) is sent to the
configured `extract_atoms` chat model (`models.dream.extract_atoms`, a
utility-tier model by default), under the caps above. Atoms already extracted
-stay; turning the setting off only stops new extraction.
+stay; opting out only stops new extraction.
## Notes & limits
diff --git a/src/core/cycle/connector-atoms.ts b/src/core/cycle/connector-atoms.ts
index 0511e79382..ca411168be 100644
--- a/src/core/cycle/connector-atoms.ts
+++ b/src/core/cycle/connector-atoms.ts
@@ -1,7 +1,8 @@
/**
- * #5856: atom extraction of connector `email` and `meeting` pages is opt-in.
- * While `cycle.extract_atoms.connector_pages` is off (the default), atom
- * discovery and the backlog count skip those pages of Google and GitHub
+ * #5856: atom extraction of connector `email` and `meeting` pages is on by
+ * default and bounded by the per-attempt auto-drain budget. Setting
+ * `cycle.extract_atoms.connector_pages` to false (or 0/off/no) opts out: atom
+ * discovery and the backlog count then skip those pages of Google and GitHub
* connector sources, so no routine cycle, drain or autopilot auto-drain sends
* their bodies to the chat model. Other page types of a connector source, and
* every page of a checkout-backed source, are unaffected.
@@ -13,10 +14,10 @@ export const CONNECTOR_ATOM_PAGES_KEY = 'cycle.extract_atoms.connector_pages';
export const CONNECTOR_ATOM_PAGE_TYPES = ['email', 'meeting'] as const;
export async function connectorAtomPagesEnabled(engine: BrainEngine): Promise<boolean> {
- return /^(true|1|on|yes)$/i.test((await engine.getConfig(CONNECTOR_ATOM_PAGES_KEY).catch(() => null)) ?? '');
+ return !/^(false|0|off|no)$/i.test(((await engine.getConfig(CONNECTOR_ATOM_PAGES_KEY).catch(() => null)) ?? '').trim());
}
-/** The discovery/backlog predicate over `pages p`: empty when opted in, else the connector email/meeting exclusion. */
+/** The discovery/backlog predicate over `pages p`: empty unless opted out, else the connector email/meeting exclusion. */
export async function connectorAtomExclusionSql(engine: BrainEngine): Promise<string> {
if (await connectorAtomPagesEnabled(engine)) return '';
const list = (values: readonly string[]) => values.map(v => `'${v}'`).join(',');
diff --git a/test/autopilot-auto-drain-dispatch.test.ts b/test/autopilot-auto-drain-dispatch.test.ts
index 7341623359..e73058a363 100644
--- a/test/autopilot-auto-drain-dispatch.test.ts
+++ b/test/autopilot-auto-drain-dispatch.test.ts
@@ -44,7 +44,6 @@ beforeEach(async () => {
await reset();
home = mkdtempSync(join(tmpdir(), 'gbrain-auto-drain-'));
await engine.setConfig('autopilot.auto_drain.threshold', '1');
- await engine.setConfig('cycle.extract_atoms.connector_pages', 'true');
});
const DAY1 = Date.parse('2026-09-20T12:00:00Z');
@@ -149,13 +148,13 @@ test('the cap counts attempts: a job retried three times consumes three units',
expect((await submitted()).map(j => j.source)).toEqual(['git-a', 'git-b']);
});
-test('connector email and meeting pages are opt-in: off, a connector backlog submits nothing', async () => {
+test('connector email and meeting pages drain by default; opted out, a connector backlog submits nothing', async () => {
await engine.setConfig('cycle.extract_atoms.connector_pages', 'false');
await connectorSource('gmail', 'email');
await connectorSource('gcal', 'meeting');
await tick(DAY1);
expect(await submitted()).toEqual([]);
- await engine.setConfig('cycle.extract_atoms.connector_pages', 'true');
+ await engine.executeRaw("DELETE FROM config WHERE key='cycle.extract_atoms.connector_pages'");
await tick(DAY1);
expect((await submitted()).map(j => j.source).sort()).toEqual(['gcal', 'gmail']);
});
diff --git a/test/connector-atom-pages.test.ts b/test/connector-atom-pages.test.ts
index a947d95553..0a51b76b6c 100644
--- a/test/connector-atom-pages.test.ts
+++ b/test/connector-atom-pages.test.ts
@@ -1,6 +1,6 @@
/**
- * #5856: atom extraction of connector email/meeting pages is opt-in
- * (`cycle.extract_atoms.connector_pages`, default off). Discovery and the
+ * #5856: atom extraction of connector email/meeting pages is on by default;
+ * `cycle.extract_atoms.connector_pages=false` opts out. Discovery and the
* backlog count agree, scoped and brain-wide; checkout-backed sources and
* other connector page types are unaffected.
*/
@@ -31,19 +31,22 @@ beforeEach(async () => {
const slugs = async (sourceId: string) => (await discoverExtractablePages(engine, sourceId)).map(p => p.slug).sort();
-test('off by default: connector email and meeting pages are neither discovered nor counted', async () => {
- expect(await slugs('gmail')).toEqual(['notes/connector-note']);
- expect(await countExtractAtomsBacklog(engine, 'gmail')).toBe(1);
- expect(await slugs('notes')).toEqual(['emails/forwarded']);
- expect(await countExtractAtomsBacklog(engine, 'notes')).toBe(1);
- expect(await countExtractAtomsBacklog(engine)).toBe(2);
+test('on by default: connector email and meeting pages are discovered and counted with no setting', async () => {
+ expect(await slugs('gmail')).toEqual(['calendar/standup', 'emails/thread-1', 'notes/connector-note']);
+ expect(await countExtractAtomsBacklog(engine, 'gmail')).toBe(3);
+ expect(await countExtractAtomsBacklog(engine)).toBe(4);
});
-test('opted in: connector email and meeting pages are discovered and counted', async () => {
+test('opted out: connector email and meeting pages are neither discovered nor counted', async () => {
+ for (const off of ['false', '0', 'off', 'no', ' FALSE ']) {
+ await engine.setConfig(CONNECTOR_ATOM_PAGES_KEY, off);
+ expect(await slugs('gmail')).toEqual(['notes/connector-note']);
+ expect(await countExtractAtomsBacklog(engine, 'gmail')).toBe(1);
+ expect(await slugs('notes')).toEqual(['emails/forwarded']);
+ expect(await countExtractAtomsBacklog(engine, 'notes')).toBe(1);
+ expect(await countExtractAtomsBacklog(engine)).toBe(2);
+ }
await engine.setConfig(CONNECTOR_ATOM_PAGES_KEY, 'true');
- expect(await slugs('gmail')).toEqual(['calendar/standup', 'emails/thread-1', 'notes/connector-note']);
expect(await countExtractAtomsBacklog(engine, 'gmail')).toBe(3);
- expect(await countExtractAtomsBacklog(engine)).toBe(4);
- await engine.setConfig(CONNECTOR_ATOM_PAGES_KEY, 'false');
- expect(await countExtractAtomsBacklog(engine, 'gmail')).toBe(1);
});
+
diff --git a/test/helpers/managed-connector-job-contract.ts b/test/helpers/managed-connector-job-contract.ts
index a0f0183824..096c21ae0d 100644
--- a/test/helpers/managed-connector-job-contract.ts
+++ b/test/helpers/managed-connector-job-contract.ts
@@ -69,8 +69,8 @@ export const contractCases = [
'cycle_extract_facts',
'extract_conversation_facts',
'facts_absorb',
- 'atom_drain_default_off',
- 'atom_drain_opted_in',
+ 'atom_drain_opted_out',
+ 'atom_drain_default_on',
'atom_dispatch',
'embed_backfill',
'synthesize_publish',
@@ -96,7 +96,7 @@ export const EXPECTED_FAILURES: Partial<Record<ContractCase, { issue: string; si
* behind one setting, default off. Lane L6 owns the key's final name; keep
* this constant in step with it.
*/
-export const CONNECTOR_ATOMS_OPT_IN = { key: 'cycle.extract_atoms.connector_pages', on: 'true' } as const;
+export const CONNECTOR_ATOMS_SETTING = { key: 'cycle.extract_atoms.connector_pages', off: 'false' } as const;
/**
* Handlers from registerBuiltinHandlers that this contract does not drive on
@@ -108,7 +108,7 @@ export const HANDLER_COVERAGE: Record<string, { covered: ContractCase } | { exem
'extract_facts': { covered: 'cycle_extract_facts' },
'extract-conversation-facts': { covered: 'extract_conversation_facts' },
'facts-absorb': { covered: 'facts_absorb' },
- 'extract-atoms-drain': { covered: 'atom_drain_opted_in' },
+ 'extract-atoms-drain': { covered: 'atom_drain_default_on' },
'loops_extract': { covered: 'loops_extract_run' },
'embed-backfill': { covered: 'embed_backfill' },
'synthesize': { covered: 'synthesize_publish' },
@@ -594,22 +594,27 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
expect(written.length).toBeGreaterThan(0);
},
- async atom_drain_default_off(state) {
+ async atom_drain_opted_out(state) {
await gmailSweep(state);
- // Off, connector email/meeting pages are outside discovery and the backlog (#5856 opt-in).
- expect(await countExtractAtomsBacklog(state.brain.engine, state.sourceId)).toBe(0);
- const [job] = await runJobs(state.brain.engine, [{ name: 'extract-atoms-drain', data: { sourceId: state.sourceId, window: 60 } }]);
- if (job.status !== 'completed') throw new Error(`extract-atoms-drain ended ${job.status} after ${job.attempts_started} attempt(s): ${job.error_text ?? ''}`);
- expect(job.attempts_started).toBe(1);
- const atoms = await state.brain.engine.executeRaw("SELECT 1 FROM pages WHERE source_id=$1 AND type='atom' AND deleted_at IS NULL", [state.sourceId]);
- expect(atoms).toHaveLength(0);
+ const { engine } = state.brain;
+ // Opted out, connector email/meeting pages are outside discovery and the backlog (#5856).
+ await engine.setConfig(CONNECTOR_ATOMS_SETTING.key, CONNECTOR_ATOMS_SETTING.off);
+ try {
+ expect(await countExtractAtomsBacklog(engine, state.sourceId)).toBe(0);
+ const [job] = await runJobs(engine, [{ name: 'extract-atoms-drain', data: { sourceId: state.sourceId, window: 60 } }]);
+ if (job.status !== 'completed') throw new Error(`extract-atoms-drain ended ${job.status} after ${job.attempts_started} attempt(s): ${job.error_text ?? ''}`);
+ expect(job.attempts_started).toBe(1);
+ const atoms = await engine.executeRaw("SELECT 1 FROM pages WHERE source_id=$1 AND type='atom' AND deleted_at IS NULL", [state.sourceId]);
+ expect(atoms).toHaveLength(0);
+ } finally { await engine.executeRaw('DELETE FROM config WHERE key=$1', [CONNECTOR_ATOMS_SETTING.key]); }
},
- async atom_drain_opted_in(state) {
+ async atom_drain_default_on(state) {
await gmailSweep(state);
const { engine } = state.brain;
- await engine.setConfig(CONNECTOR_ATOMS_OPT_IN.key, CONNECTOR_ATOMS_OPT_IN.on);
- try {
+ // No setting: connector email/meeting pages are extracted by default (#5856).
+ await engine.executeRaw('DELETE FROM config WHERE key=$1', [CONNECTOR_ATOMS_SETTING.key]);
+ {
expect(await countExtractAtomsBacklog(engine, state.sourceId)).toBeGreaterThan(0);
const [job] = await runJobs(engine, [{ name: 'extract-atoms-drain', data: { sourceId: state.sourceId, window: 60 } }]);
if (job.status !== 'completed') throw new Error(`extract-atoms-drain ended ${job.status} after ${job.attempts_started} attempt(s): ${job.error_text ?? ''}`);
@@ -619,7 +624,7 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
const atomChanges = (await changesSince(state)).filter(c => c.tbl === 'pages' && atoms.some(a => a.slug === c.row_key));
expect(atomChanges.length).toBeGreaterThan(0);
expect(atomChanges.every(c => c.request_kind !== null)).toBe(true);
- } finally { await engine.setConfig(CONNECTOR_ATOMS_OPT_IN.key, 'false'); }
+ }
},
async atom_dispatch(state) {
@@ -635,6 +640,7 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
return engine.executeRaw<{ id: number }>("SELECT id FROM minion_jobs WHERE name='extract-atoms-drain' AND data->>'sourceId'=$1 AND id > $2", [state.sourceId, state.detector.jobsFrom]);
};
await engine.setConfig('autopilot.auto_drain.threshold', '1');
+ await engine.setConfig(CONNECTOR_ATOMS_SETTING.key, CONNECTOR_ATOMS_SETTING.off);
try {
expect(await countExtractAtomsBacklog(engine, state.sourceId)).toBe(0);
const off = await tick();
@@ -642,9 +648,9 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
if (engine.kind === 'pglite') { expect(off).toHaveLength(0); return; }
if (off.length) {
await engine.executeRaw("UPDATE minion_jobs SET status='cancelled' WHERE id = ANY($1::int[]) AND status IN ('waiting','delayed')", [off.map(j => j.id)]);
- throw new Error('auto-drain submitted extract-atoms-drain for the connector source with connector atoms off');
+ throw new Error('auto-drain submitted extract-atoms-drain for the connector source with connector atoms opted out');
}
- await engine.setConfig(CONNECTOR_ATOMS_OPT_IN.key, CONNECTOR_ATOMS_OPT_IN.on);
+ await engine.executeRaw('DELETE FROM config WHERE key=$1', [CONNECTOR_ATOMS_SETTING.key]);
expect(await countExtractAtomsBacklog(engine, state.sourceId)).toBeGreaterThan(1);
const on = await tick();
expect(on).toHaveLength(1);
@@ -653,7 +659,7 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
expect(job.attempts_started).toBe(1);
} finally {
await engine.setConfig('autopilot.auto_drain.threshold', '25');
- await engine.setConfig(CONNECTOR_ATOMS_OPT_IN.key, 'false');
+ await engine.executeRaw('DELETE FROM config WHERE key=$1', [CONNECTOR_ATOMS_SETTING.key]);
}
},
@@ -761,7 +767,7 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {
},
};
-const ATOM_CASES: ReadonlySet<ContractCase> = new Set(['atom_drain_default_off', 'atom_drain_opted_in', 'atom_dispatch']);
+const ATOM_CASES: ReadonlySet<ContractCase> = new Set(['atom_drain_opted_out', 'atom_drain_default_on', 'atom_dispatch']);
const FACTS_CASES: ReadonlySet<ContractCase> = new Set(['cycle_extract_facts', 'extract_conversation_facts', 'facts_absorb']);
async function runCase(brain: ContractBrain, id: ContractCase): Promise<void> {