Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CONTINUITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ reference is [CLAUDE.md](CLAUDE.md); the phase plan is [ROADMAP.md](ROADMAP.md).
or buy anything without showing Marc the exact item + price first. IPv6 is disabled on
CloudFront on purpose (AAAA-only resolver answers broke the fresh domain on IPv6-less
networks); Tailscale MagicDNS on Marc's Mac negative-cached the name for an hour.
3b. **Rename — one planned pass once Marc picks a name** (2026-09-26: "naming is all over the
place: earthdeck / Earth Watch / vitalearth.io"). Checklist: npm package + bin + repo
name; `src/site.config.ts` (name, fullName, organization, baseUrl); ledger predicate
`https://earthdeck.dev/finding-event/v1` (keep v1 URL for old entries, add v2 or a
`$schema` alias — do NOT rewrite history); CloudFormation stack/bucket/function names
(new stack + migrate state, or keep internal names); domain (registration only after
trademark check + Marc's explicit OK on the exact name + price); README/CLAUDE/VISION;
`checkpoint` signer name stays "earthdeck" unless the key is rotated. Do it in one PR.
2b. **Scale-out state (2026-09-26 late)**: `earthdeck discover` generates 549 AOIs
(`watchlists/generated/`, 19 API calls, 53 s; re-run every ~14 days — doctor warns when
stale). Runner sweeps `all-generated` in 8 shards per 6-h window (13.5-min budget each),
analyst +1:20, export +1:30, hand-written lists +1:40; per-day caps: CDSE 40, GFW 400,
FIRMS 3000, analyst 10 cases / $3. **Measured** (shard 0/8 dry run on Lambda): 82 pairs,
47 done in budget, 39 candidates, 13 optical confirmations, Copernicus 32 / GFW 69 /
FIRMS 86 calls. Confirm-only providers (Copernicus for forest_loss) *defer* confirmation
when spent — detection always runs. TODO: measure Copernicus PU per `eo_compare`/S5P
call (free tier 10k PU/month) and set the cap from data. Name: **TerraKeep**, slogan
"Keeping Earth within its limits." — package/repo/stack rename still pending (3b).
3c. **Queued by Marc 2026-09-26 (in this order, one at a time — "take it slowly")**:
1. **Backtest harness** — `earthdeck backtest --event <file>`: replay rules with the clock
set to a past date for 8–10 documented events (2019 Amazon fires, 2020 Black Summer,
2023 Canada, 2023 Maui, Rumaila flaring 2024, São Félix 2025 loss, Permian methane
super-emitters, a known false alarm…); report detected / confirmed / lag; publish a
"would we have caught it" page. Data limits: GFW alerts ≥ 2015, VIIRS ≥ 2012.
2. **Coral bleaching rule** — NOAA CRW DHW crossing alert levels at a reef watchlist
(tool `coral_bleaching` exists); second signal: SST anomaly persistence / neighbour cell.
3. **Extreme-fire rule** — global VIIRS FRP/extent anomaly vs. the same weeks in prior
years (not only inside protected areas); confirm with a later pass + burn index.
4. **Radiation** — `radiation` tool + `radiation_anomaly` rule from open ground networks:
BfS ODL (DE, open JSON), EURDEP (EU), EPA RadNet (US), Safecast (global, CC0); dose
rate vs. station baseline, confirmed by a neighbouring station or second network.
Add to TRUST.md blind spots meanwhile: satellites cannot see radiation.
4. **Next build steps**: (a) attribution onto cases in `created.context` (`protected_areas` +
`emitters`); (b) `emitters` as the methane confirmer while EMIT is stale; (c) `ledger verify
--remote <base-url>` (the case pages already print it); (d) GEE: Marc creates the GCP
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,34 @@ decides: `ledger_advance` publishes when the gates hold (it computes `gates` via
a `publish | hold | reject` verdict; naming a party still needs tier ≥ 2, two distinct
reviewer identities and the private-notice clock.
`earthdeck doctor` has a **Watch** section (ledger verify, each rule's keys, watchlists,
last sweep heartbeat).
generated watchlists and their age, last sweep heartbeat).

**Discovery: watchlists from data** — `earthdeck discover --out watchlists/generated
[--max-per-list N] [--only a,b] [--budget 200]` (`src/watch/discover/`) writes five
watchlists plus `_summary.json` (counts, sources, dataset versions, request count). One
run is ~19 requests and under a minute (no CDSE, no FIRMS); it needs `GFW_API_KEY`.

| File | Source (open data) | Default N | What becomes an AOI | Rules |
| --- | --- | --- | --- | --- |
| `forest-hotspots.json` | GFW `gadm__integrated_alerts__adm2_daily_alerts` (high+ confidence, primary forest, last 30 days) + GADM 4.1 boxes | 150 districts | GADM level-2 box, tiled to ≤ 4 deg² / ≤ 2° a side (`<iso>-<adm1>-<adm2>-<i>`) | `forest_loss`, `minHa = max(25, ⌈100 ha/deg² × tile⌉)`, `minAlerts = 10 × minHa`, 90 d |
| `flaring-fields.json` | EOG VIIRS Nightfire annual flare sites (~14k) | 60 fields | sites chained within 15 km, box + 10 km, ≤ 25 deg² | `flaring`, 30 d, `minNights` 5 |
| `methane-basins.json` | Climate TRACE v7 oil & gas CH₄ (production, refining, transport) | 40 basins | sources chained within 50 km, box + ~0.5°, ≤ 2° a side | `methane_anomaly` (defaults) |
| `protected-fires.json` | WDPA via GFW (IDs/stats only) + GFW alerts per protected area | 80 areas | tropical areas > 2,000 km² with primary forest, IUCN Ia–IV first, tiled ≤ 4 deg² | `fires_in_protected` + `forest_loss` (60 d, `minHa = max(5, ⌈40 ha/deg² × tile⌉)`), cooldown 14 d |
| `controls-generated.json` | Intact Forest Landscapes 2020 via GFW | 20 cores | ≤ 0.5° box on each IFL's deepest interior point (maximum inscribed circle), clear of hotspot tiles | `controls.json` thresholds, `control: true` |

Why the thresholds look like that: a São Félix-level frontier runs ≈ 930 ha/deg² per 90 days
and the control cores' noise is ≈ 60–76 ha/deg² — `100 ha/deg²` is the controls' 25 ha /
0.25 deg² floor scaled to the tile, so the bar depends only on geometry and does not move
between runs. Ids come from dataset ids (GADM, VNF site position, Climate TRACE source id,
WDPA site id, IFL id), so watermarks and cooldowns persist across re-runs; output is
byte-identical for the same data. Choices and their costs: the forest ranking counts only
primary-forest alerts (otherwise Sahel dryland alerts top the list; secondary forest and
cerrado frontiers rank lower); `protected-or-indigenous` marks districts with ≥ 25 % of
their alerts in IUCN Ia/Ib/II areas or LandMark lands; Climate TRACE places basin-level
estimates at a basin centroid, so a methane box is a window around that point; national
"OtherBasins" residuals and offshore basins are dropped. Sweep with
`earthdeck watch --once --watchlist watchlists/generated` (`--max` caps pairs; lists are in
rank order). Re-run weekly — `doctor` flags output older than 14 days.

**Analyst (autonomous publishing)** — `src/analyst/`: `earthdeck analyst --once` takes
confirmed findings (newest first, `--max` default 5) through three steps, each journaled
Expand Down
98 changes: 89 additions & 9 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ runs the scheduled watch sweeps on Lambda, keeps the signed findings ledger in S
serves the static Earth Watch site at `https://earthdeck.marcsperzel.com/`.

```
EventBridge Scheduler (UTC, every 6 h, staggered)
:00 amazon :10 congo-borneo :20 controls :30 methane :40 flaring :50 analyst +1h export
EventBridge Scheduler (UTC, every 6 h from 00/06/12/18, staggered)
+0:00…+1:10 generated shards 0–7 +1:20 analyst +1:30 export +1:40 hand-written lists
│ async invoke, JSON payload
▼
SSM /earthdeck/* ──► Lambda "earthdeck" (Node 22, arm64, 900 s, 1 GB, concurrency 1)
Expand Down Expand Up @@ -73,9 +73,26 @@ touched. Pause/resume all schedules: `EARTHDECK_SCHEDULES=DISABLED|ENABLED scrip

## How a run works

Payload: `{ "job": "sweep"|"analyst"|"export"|"all", "watchlist"?: "amazon"|"congo-borneo"|"controls"|"methane"|"flaring", "dryRun"?: true }`
(`watchlist`/`dryRun` only with `sweep`; `all` = five sweeps + analyst + export, manual use —
it may not fit in 900 s).
Payload: `{ "job": "sweep"|"analyst"|"export"|"all", "watchlist"?: W, "shard"?: "i/n", "timeBudgetSec"?: N, "dryRun"?: true }`
where `W` is a hand-written list (`amazon`|`congo-borneo`|`controls`|`methane`|`flaring` →
`watchlists/<W>.json`), `all-handwritten` (those five), `all-generated` (every file in
`watchlists/generated/`) or `generated/<name>` (`watchlists/generated/<name>.json`).
`watchlist`/`shard`/`timeBudgetSec`/`dryRun` only with `sweep`; no `watchlist` = every
top-level `watchlists/*.json`. `all` = five hand-written sweeps + analyst + export, manual use —
it may not fit in 900 s.

- **Every sweep in Lambda is time-budgeted**: the runner passes
`--time-budget` = remaining invocation time − 90 s (or `timeBudgetSec`, whichever is smaller)
to `node dist/cli.js watch --once`. The kernel stops opening new pairs when one more pair (as
slow as the slowest so far) would overrun, finishes the current one, writes watermarks /
journal / ledger as usual and exits 0 with `budget exhausted: k of n pairs done`. As a
backstop the child is SIGTERMed at remaining − 60 s, leaving the rest for verify + upload.
- **Shards**: `--shard i/n` keeps only pairs with `sha256(aoi.id, rule) mod n == i` — disjoint,
deterministic, independent of file order. Within a sweep, pairs run **least-recently-swept
first** (never-swept first of all, by watermark), so a budget- or quota-cut sweep resumes
where the last one left off and nothing starves.
- **Quotas** (below): pairs whose provider's daily cap is spent are `skipped` with reason
`quota:<provider>` (journaled, watermark untouched).

- The ledger working copy is `ledger/` in the state bucket minus `ledger/checkpoints/` (the
archive) and `ledger.key` (never stored). It is downloaded fresh every run.
Expand All @@ -99,18 +116,77 @@ The AWS SDK v3 is **not** in the zip: the Lambda Node.js 22 runtime ships it. Th
`@aws-sdk/client-*` packages are exact-pinned devDependencies for typechecking only; the
runner loads them lazily (`import()`, falling back to `require` via `NODE_PATH`).

## Schedule

Every 6 hours, windows starting 00:00 / 06:00 / 12:00 / 18:00 UTC (11 schedules, all behind
`SchedulesState`):

| Offset | Schedule | Payload |
| --- | --- | --- |
| +0:00 | `earthdeck-sweep-shard-0` | `{"job":"sweep","watchlist":"all-generated","shard":"0/8"}` |
| +0:10 … +1:10 | `earthdeck-sweep-shard-1` … `-7` (every 10 min) | same, `shard` `1/8` … `7/8` |
| +1:20 | `earthdeck-analyst` | `{"job":"analyst"}` |
| +1:30 | `earthdeck-export` | `{"job":"export"}` |
| +1:40 | `earthdeck-sweep-handwritten` | `{"job":"sweep","watchlist":"all-handwritten"}` |

- ~350 generated AOIs / 8 shards ≈ 44 pairs per shard; at 1.5 s politeness delay + a few
seconds of API time per pair that is ~5–8 min, inside the ~13 min budget. A shard that runs
long is cut by its budget and resumes least-recently-swept first next window.
- Slots are 10 min apart but a run may take up to 15: with concurrency 1 an overlapping
invocation is throttled and Lambda's async queue retries it (event age ≤ 6 h), so the chain
drifts later instead of dropping a run. Only one writer ever touches the ledger.
- The hand-written lists run after the export, so their findings are narrated/published in
the next window (≤ 6 h later).
- 44 invocations/day; the 14 h no-success alarm is unchanged.

## Quotas

Per-UTC-day caps, counted in the ledger's `watch/quota.json` (synced with the ledger, so they
hold across invocations) and set as function env vars in the template:

| Env var | Default | Counts |
| --- | --- | --- |
| `EARTHDECK_MAX_CDSE_CALLS` | 60 | `eo_compare`, `methane_plumes`, `eo_*` tool calls (1 each) |
| `EARTHDECK_MAX_GFW_CALLS` | 400 | `forest_alerts` calls (1 each) |
| `EARTHDECK_MAX_FIRMS_CALLS` | 300 | FIRMS transactions: `fires_in` 1; `flaring` ⌈days/5⌉ × sources (30 d × 2 = 12) |
| `EARTHDECK_MAX_ANALYST_CASES` | 10 | findings the analyst takes on per day (also the `--max` default) |
| `EARTHDECK_MAX_ANALYST_USD` | 3 | analyst API spend per day; journaled as `analyst_spend` |

A pair is skipped `quota:<provider>` when any provider its rule needs (from the rule's
`requires`) is spent — note `forest_loss` needs CDSE (for its NDVI confirmation), so it stops
when CDSE does. A call that would cross a cap mid-pair is refused (skip, not gap). An HTTP 429,
a 403 whose body says quota/limit, or FIRMS's "transaction limit" text marks that provider
exhausted for the rest of the run.

Expected demand for ~350 AOIs (assumed mix — one rule each: 170 `forest_loss`, 90
`fires_in_protected`, 45 `flaring`, 45 `methane_anomaly`; recompute when the generated lists
land):

| Provider | Per pair | Per full pass | Per day (4 passes) | Daily cap | Effective revisit under the cap | Provider's own limit |
| --- | --- | --- | --- | --- | --- | --- |
| GFW | forest 2 | 340 | 1,360 | 400 | forest pairs ~1.2×/day | rate-limited per key (UNCONFIRMED figure) |
| CDSE | forest 0–1 (confirm only; ~10% → 17), methane 1 | ~62 (45–215) | ~250 (180–860) | 60 | methane ~1×/day; forest capped with it | processing units / requests per month (UNCONFIRMED figure) |
| FIRMS | fires 2 (1 when quiet), flaring ~12 | 720 (180 + 540) | 2,880 | 300 | FIRMS pairs ~every 2.4 days | 5,000 transactions / 10 min per map key |
| Anthropic | ≈ $0.10 per case (narrate + review) | — | ≤ 10 cases | $3 | — | — |

The caps, not Lambda time, set the revisit rate. FIRMS's own limit is per 10 minutes, so
`EARTHDECK_MAX_FIRMS_CALLS` can be raised (≈ 3,000 covers four full passes; one shard spends
~90) without risk; raising CDSE needs the account's monthly PU budget checked first. Caps
reset at 00:00 UTC, so the 00:00 window's shards spend them first; later windows sweep what
is left, least-recently-swept first within each shard.

## Monthly cost (estimate)

| Item | Usage | ≈ USD/month |
| --- | --- | --- |
| Lambda (arm64, 1 GB) | 28 invocations/day ≈ 840/month; at ~3 min avg ≈ 150k GB-s (worst case 900 s each ≈ 760k GB-s) | 0 within the 400k GB-s free tier; ≤ 5 worst case |
| Lambda (arm64, 1 GB) | 44 invocations/day ≈ 1,320/month; shards ~8 min, others ~2 min ≈ 500k GB-s (worst case 900 s each ≈ 1.19M GB-s) | ~1.5 over the 400k GB-s free tier; ≤ 11 worst case |
| S3 (3 buckets, versioned state) | tens of MB, a few thousand PUT/GET | < 0.20 |
| CloudFront | low traffic; 1 TB + 10M requests/month always-free; ~120 `/*` invalidations (1,000 free) | ~0 |
| Route 53 | existing zone (already paid); alias queries free | 0 extra |
| SSM + KMS | standard parameters free; `aws/ssm` key free; ~5k decrypts | < 0.05 |
| CloudWatch | 1 custom metric 0.30 + 1 alarm 0.10 + small log ingest (30-day retention) | ~0.50 |
| EventBridge Scheduler, ACM, SNS email | well inside free tiers | 0 |
| **Total** | | **~1–3** (Anthropic API usage by the analyst is separate) |
| **Total** | | **~2–5** (analyst Anthropic spend is separate, capped at $3/day ≈ $90/month) |

## Key rotation

Expand Down Expand Up @@ -160,5 +236,9 @@ CFN cannot create a bucket whose name already exists.
and `s3://earthdeck-state-185692190330/state/heartbeat.json` for the last success.
- **Site shows the placeholder** — the export job is `unavailable` in this build or hasn't
run yet; `scripts/run-job.sh export`.
- **Sweeps time out at 900 s** — split a watchlist, or lower per-call delay (`--delay-ms`);
watermarks mean a killed sweep resumes next slot (its unverified writes are not uploaded).
- **Sweeps time out at 900 s** — should not happen (every Lambda sweep is time-budgeted); if
one does, a single call hung past the budget. Watermarks mean a killed sweep resumes next
slot. `budget exhausted: k of n pairs done` in the log is normal, not an error.
- **Many `quota:<provider>` skips** — the daily cap is spent (see Quotas); check
`ledger/watch/quota.json` in the state bucket, raise the env var in the template if the
provider allows it.
Loading
Loading