Update open calls

From atanasster/electionsbg · View interactive version

Update open calls is an AI agent skill from the GitHub repository atanasster/electionsbg. Refresh the open-calls register — which EU-programme procedures (ИСУН 2020) and ДФ „Земеделие" Strategic-Plan intakes a reader can APPLY to right now, into data/opencalls/*.json + the open_calls Postgres table. Use when the daily watch report flags `isun_procedures`, `sp2023_indicative`, `interreg_c

How to use this skill

Skill file

Update open calls skill

<!-- pipeline-pointer:start (generated from the registry; edit scripts/pipeline/registry) -->

Pipeline: handler CODE0 runs this unattended — pnpm run pipeline:ingest --only update-open-calls. The registry holds its commands, gates and publish set; this runbook covers what a script cannot do (operator steps, judgement calls, troubleshooting). When a step fails, start from the repair packet the run writes, not from the procedure below.

<!-- pipeline-pointer:end -->

Crawls two registers of things you can still apply to, and publishes them:

(draft guidance out for comment, kind='consultation'), into data/opencalls/isun.json;

2023-2027, into data/opencalls/sp2023.json.

data/opencalls/interreg.json (pnpm run opencalls:interreg; see „What this skill does NOT do").

accessible environment, self-employment, чл. 49, protected-employment centres), into

data/opencalls/ahu.json (pnpm run opencalls:ahu, Step 2b).

„Заетост без бариери" …), into data/opencalls/az.json (pnpm run opencalls:az, Step 2c).

EXACT ROWS ONLY — most АЗ intakes are open-ended and are rejected, see Step 2c.

All five then load into open_calls (migration 142) and surface on the /funds band-1 tile,

/funds/calls, and the openCalls AI tool.

Read this before anything else: why this dataset is different

Every other dataset here fails by going STALE — a number is out of date. **This one fails by

costing a reader a deadline**, and that inverts three of the usual rules. Do not "simplify"

around them.

  1. Nothing stores a status. open_calls_table derives open / closed / upcoming /

indicative / consultation by comparing closes_at to now(). So if this skill never

runs again, expired calls disappear on their own and new ones are missing — the failure is

UNDER-reporting, which is safe. Storing a status at crawl time would show expired calls as

open all weekend after a Friday failure.

  1. The loader NEVER deletes. The crawler reads /Active, so a call that closes is absent

BY DESIGN. db:load:open-calls:pg is upsert-only and records absence as last_seen_at.

If you ever find yourself adding an anti-join DELETE to it, you are deleting exactly the

closed calls that make the archive and the base rates possible.

  1. A figure needs a provenance. enrichment is none / source / auto / reviewed,

and a CHECK bars the money columns unless it is source or reviewed. **This skill only

ever produces none and source** — source for the ДФЗ XLSX, which has real budget /

aid-rate / ceiling columns, and none for ИСУН, whose procedure page carries no money at

all. Extraction from documents is a SEPARATE skill (enrich-open-calls) precisely so this

one can run unattended without ever shipping an unreviewed number.

Step 0 — Pin the local database

db:load:open-calls:pg writes Postgres through scripts/db/lib/pg.ts, whose default is the

docker container with an inline password. An ambient DATABASE_URL always wins, and every

db:*:cloud script exports a password-less URL, so pg falls back to .pgpass — which holds

the Cloud SQL password. Against local PG that fails with 28P01. Any shell that has run a

:cloud command this session is poisoned, so pass the local URL inline when in doubt:

DATABASE_URL='postgres://postgres:postgres@localhost:5433/electionsbg' pnpm run db:load:open-calls:pg

Step 1 — Crawl ИСУН

pnpm run opencalls:isun

Serial, ≥1.1 s between requests, identifying User-Agent, ~57 requests for a full run

(two listings + one detail page per procedure). robots.txt on eumis2020.government.bg

was verified clear for these paths. Do not parallelise it — this is a government portal

with a WAF, and the politeness budget is what keeps the crawl working.

Two failure shapes to recognise:

detects it (looksLikeInterstitial) and treats it as a failure rather than as an empty

register. If more than 15% of detail pages fail, the run aborts without writing.

writer refuses an empty result and refuses a >25% shrink. That guard exists because it was

needed: a throwaway probe script once overwrote the real snapshot with {calls: []}.

The snapshot preserves each call's original crawledAt when nothing about it changed, so a

no-op run produces a no-op diff.

Step 2 — Refresh the ДФЗ indicative schedule

pnpm run opencalls:sp2023

One page fetch plus one XLSX. The year comes from the filename, never the URL — the host

is sp2023.bg, so a whole-URL match hands every link a phantom 2023.

The parse is header-driven rather than positional, and it declines prose: a cell reading

„съгласно условията" is not a budget, and a range of aid rates is not a single rate. Those

become NULL rather than a guess, and the row keeps its verbatim text.

Skip this step when only isun_procedures was flagged. The schedule is annual; there is

no reason to re-download it on an ИСУН change.

Step 2b — Refresh the АХУ competitions

pnpm run opencalls:ahu

One page fetch: the agency's NEWS page (/portal/page/6), where each competition is an

„обявява конкурс" announcement. Run it when ahu_calls was flagged. The deadline is read from

its label (four phrasings, see scripts/opencalls/ahu_parse.ts). An announcement whose window

is only in an attached .doc is REJECTED — never filed as indicative, because open_calls

never deletes and an indicative row would stay „expected" for ever. It prints as a ✗ line,

which is expected, not a failure. No money is read; the ceilings are prose.

Step 2c — Refresh the АЗ intake windows

pnpm run opencalls:az

Eleven page fetches (the news list plus the ten newest items, 1.2 s apart). АЗ has no calls

register: an intake is a news item. Only an item whose END date sits in a clause about applying

becomes a row („от 16 до 26 октомври 2026 г. включително", „до 17:00 ч. на 25 септември

2026 г."). Most АЗ intakes are open-ended („От 19 октомври започва прием …" — they run until

the money is spent) and are REJECTED as ✗ lines, deliberately: the only other shape 142 offers

is indicative, which renders „Очаквани приеми" for ever because open_calls never deletes.

Decided 2026-10-21; revisit only when the view can expire a stale indicative row.

The crawl MERGES into the committed az.json by key (az:<item>:<closing day>) — the list page

shows only the ten newest items, so a window scrolling off it is not a window that ended. One item

can yield several rows (employers by one date, the young graduates by another). A run where half

or more of the item pages fail to parse throws: that is a markup change, not a quiet week.

Statistics items („… безработни започнаха работа") are not intakes and print nothing.

Step 3 — Load locally

DATABASE_URL='postgres://postgres:postgres@localhost:5433/electionsbg' pnpm run db:load:open-calls:pg

It applies 005_ingest_tracking.sql + 142_open_calls.sql itself, so it works on a cold

database. Stage-merged upsert, so it is safe against a live database and never blocks readers.

One behaviour worth knowing: the upsert will not downgrade a reviewed or source row

back to none. A human's sign-off on a figure survives every subsequent crawl of a source

that does not publish that figure — which is the whole reason Stage 7's enrichment can be

trusted at all.

Check what it did:

pnpm exec vitest run scripts/db/tests/open_calls.data.test.ts

Step 4 — Publish to Cloud SQL (MANDATORY)

Nothing runs this automatically, and skipping it is invisible. Local goes green, prod

keeps serving the previous vintage at a 200, and every row count reconciles. This is the

reference_migrated_family_watch_reload failure class and it is the single most likely way

this dataset rots.

pnpm run db:load:open-calls:pg:cloud

Requires the Cloud SQL proxy on 5434. The loader applies 142 there too, including its

reconcile ALTER — which matters on a database that predates the numeric → `double

precision fix, because numeric` reaches the browser as a STRING and blanks every money cell

while the number sits in the payload.

The freshness stamp is PER SOURCE, and the page reports the newest SUCCESSFUL one across all of

them. So running only Step 1 (ИСУН) leaves sp2023's stamp where it was, which is correct — but it

also means a run where ИСУН failed and ДФЗ succeeded shows a fresh „Проверено на" while the ИСУН half

is stale. open_calls_crawl.ok records the failure; the page's banner reads the newest ok = true

row, so a wholly failed run correctly reports the previous date rather than today's.

There is no bucket:sync step. data/opencalls/ is excluded from GCS sync

(scripts/bucket_sync_paths.ts) because it is a PG load source, not a serving artifact — a

second copy on the bucket would be a spare serving surface that can go stale.

Step 5 — Verify what a reader sees

curl -s "http://localhost:5173/api/db/open-calls?limit=5" | head -c 400

Three things to eyeball, each of which has been wrong before:

ДФЗ window must never render a countdown, and a draft must never sit beside a real call;

applied to whatever database you are talking to.

Then load /funds and /funds/calls and confirm the freshness line („Проверено на …") is

present and recent. If it says „още не е зареждан", the loader has not run against the

database the page is reading.

Step 6 — Stamp the update feed

Add a data/data-changes.json entry and let process-watch-report stamp recent_updates

per its own rules. The two changelogs are separate — see reference_two_changelogs.

What this skill does NOT do

enrich-open-calls, and it is separate on purpose: crawl+load is mechanical and safe

unattended, while enrichment spends tokens per document and must not publish a figure

without human sign-off.

flagged isun_eu_funds or isun_eu_funds_projects, you want that skill, not this one.

Bulgarian cross-border programmes since 2026-10-21 (the 2026-08-09 note that BG-RS / BG-MK /

BG-TR were unreachable and RO-BG had no index was measured against the 2014–2020 hosts — see

CLAUDE.md). Run it alongside the two above; it writes data/opencalls/interreg.json and loads

through the same db:load:open-calls:pg. /funds/calls says „част от", never a count.

Two things about that crawl differ from these two. Zero open calls is normal — on

2026-08-09 all 7 rows were closed, and they load anyway, because „the last one closed on

22 June" is the answer a border municipality gets nowhere else. And **a programme being down

is not a failure**: the crawler keeps the programmes it could read and names the ones it could

not, so a partial run is expected output rather than something to re-run until it is clean.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.