Skip to Content
AaviDocs

The daily watch

What the Crew App in aavi-watch does: the daily census, field fingerprints, flags, the dashboard, the onboarding agent and the rules for its pull requests.

aavi-watch is a Kiro Crew App. Once a day it counts the lead water line records of the ten public sources and checks whether any city changed how it publishes them. When a city's field list changes, an agent edits that one city's settings and opens a pull request for a person to review. The code is at github.com/ramakrishnanhulk20/aavi-watch.

The census

A lookup asks the city's own server at the moment someone types an address, and keeps no copy of any home record. The Crew App keeps one thing: a dated count per source per day, in EPA's four classes. That is enough for a trend line, and enough to notice when a source changes underneath us. Live counts are on Cities.

The daily census job

A Crew cron job named daily-census runs a plain Node command once a day. It is set for 06:00 UTC, and the Crew scheduler has started it between 06:01 and 06:53 UTC so far (27 November to 4 December). The command asks each source for its counts by class, using the source's own grouped count query, so the numbers are the city's and not ours. It appends one line per source to data/census.jsonl. It spends no model credits.

A source that fails writes a failure line with a fixed kind, such as feed-error or bad-json, and the other sources still run. The job has a limit of 15 minutes.

Field fingerprints

Right after counting, the app asks each source for its list of fields and hashes the names, types and coded values. It uses fieldFingerprint from @aavi/sources, the same function the website uses. A different hash raises a flag for that city, with the fields that were added, removed or retyped. The flag stays until the owner clears it on the dashboard.

The website runs the same check on every lookup. If a field a city's settings depend on has changed, the lookup answers "source changed" for that city instead of guessing, until a reviewed update lands.

Count-drop flags

If a city's lead count or unknown count falls by more than 10 percent between two successful runs made with the same engine version, the city is flagged on the dashboard. A big fall can be good news, because a city resolved lines. It can also mean the source was swapped for a different file with the same layout. The flag only asks a person to look. It never starts an agent.

The census push

The census files sit in the app's data folder. A second, small program copies them into the database that /api/cities reads. It runs outside Crew, as a timer at 07:30 and 12:30 UTC. It reads exactly two files and follows no links. It inserts rows and never updates or deletes one. It runs outside Crew because Crew's sandbox has no write fence and this program holds the database's write login. The site reads the store with a separate read-only login.

The dashboard

The app adds an Aavi Watch page to Crew's dashboard. It shows each source with its state, last census, counts by class and a small trend line of the unknown share. It lists field changes, each with a Clear button, and agent runs, each with a link to its pull request. A banner appears when the newest census is more than 36 hours old. A second banner, with a Resume button, appears when Crew has paused the daily job after repeated failures.

The onboarding and fix agent

The agent is aavi-onboarder, defined in agents/onboarder.json, and it follows the onboard-city skill. It takes one of two requests: ONBOARD KEY URL to add a city, or FIX KEY to repair one whose fields changed. See add your city with Kiro for the steps it follows.

The fix loop

An owner can start a run by hand. The app also starts FIX runs on its own. Its backend looks at the flags every 10 minutes and starts the agent only when every one of these holds:

  • The flag carries a fingerprint the agent has not already worked on, and it is for a known city.
  • That city has had no agent run today (UTC).
  • Fewer than 3 agent runs have started today in total. Runs started by hand count toward the 3.
  • No pull request is open for that city.
  • No other agent run is going.
  • The job is exactly the expected one: the right agent, automatic approval, disabled, a limit of 3,600 seconds per run and the right project folder. If anything differs, the loop logs job-mismatch and does nothing.

The agent's job stays disabled and never fires on a schedule. Only the backend check or the owner starts it.

Scroll sideways to follow the diagram.
changedyesnoyesnothing needs to changestill failing after 3 roundsgate and tests passchanges outside the spec andits fixtures, or no spec changespec and fixtures onlyapproverejectdaily-census job, set for06:00 UTC, a command jobwith no model creditsFor each of the ten cities:count the records and readthe live field listCensus and field lines arewritten to the data files onevery runField fingerprint equals thelast good baseline?Lead or unknown count fellby more than 10 percent?Write a flag in flags.jsonwith the new hashWrite a count-drop flag:kept for the owner, neverreplaces a field flag, neverstarts the agentFix loop round, every 10minutesAll gates pass? Fewer than3 runs today, no agent jobor fix lock, a new flag for aknown city, no open pullrequest for the city, the jobis exactly oursStay idle until the nextroundSet the job message to FIXplus the city key and run itaavi-onboarder, autoapproval, 1 hour limit: readthe live fields, edit only thatcity's spec and fixtures, runthe gate and the tests, atmost 3 fix roundsRun record: no-change, nopull requestRun record: failed, no pullrequestPush its own branchcrew/fix-KEY, thenopen-pr.mjs opens one pullrequestPull request refusedGitHub checks agent-scopeand testsOwner review, code ownerOwner merges into mainPull request closed, nochange

A changed field list starts the agent, a falling count only raises a flag, and only the owner can merge what the agent opens.

The rules an agent pull request must pass

  1. The agent can change one city's settings file and that city's test data, and nothing else. ops/open-pr.mjs refuses any other file, and a required check on the product repo fails any agent pull request that touches more.
  2. The agent never holds a long-lived key. A timer mints a GitHub pass limited to the product repo that expires in about an hour.
  3. A person approves every change. The agent's identity cannot approve its own pull request, and it cannot merge, push to main, change branch protection or edit workflow files.
  4. Agent runs are capped: 3 a day, one per city per day, none while a pull request for that city is open.
  5. The agent runs in Crew's sandbox, with the app's own folder read-only inside it. The only database write login belongs to the census push, which uses an insert-only database role.

The known limit: anything running as the Crew user can write the census files. The database refuses malformed or backdated rows, and a fall of more than 10 percent in lead or unknown is flagged, but neither proves a count is true. The full reasoning is in security and privacy and the threat model.

Install

You need a Linux machine that runs Kiro Crew 0.13.1 or newer, with Node on its path. The steps are in the repo README. Where results go:

  • data/census.jsonl: one line per source per run.
  • data/fields.jsonl: each source's field list and hash.
  • data/flags.json: open flags.
  • data/agent-runs/: one record per agent run, whether it ended in a pull request or a failure.