Skip to content

Fetch reports by queue window, and fetch named projects - #10

Merged
aymanazeem merged 6 commits into
mainfrom
fix/fetch-queue-windows
Dec 1, 2026
Merged

aymanazeem merged 6 commits into
mainfrom
fix/fetch-queue-windows

Conversation

@aymanazeem

@aymanazeem aymanazeem commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Problem. make fetch chose reports by a date cutoff, 1 October 2020, which left out AG1 projects that Berkeley Lab dates 1 or 2 October, though some of them have reports. Adding another project's report meant saving it by hand. A report already on disk was reported as fetched. And if PJM's site failed, every project was counted as having no report, so the fetch carried on through each timeout.

What changes.

  • make fetch looks for reports of projects in the AG1 window or an earlier one (pdf_last_window in src/config.py). It works back from the active or withdrawn projects that applied most recently, skips any without a report, and stops once it has 25. Projects that applied on the same day are taken in order of queue ID.
  • python -m src.fetch_pdfs --ids AF1-236 ... downloads named projects' reports. An ID the panel doesn't hold is reported and not tried.
  • Each project's line says whether its report was downloaded, was already on disk, or wasn't found. Only a 404 or 410 from PJM counts as not found. If PJM's site can't be reached, or answers with a redirect or any other error, such as a refusal, a rate limit or a server error, the fetch names the error, stops, says to try again later and exits with status 1.
  • A report is written beside its final name and moved into place once whole, so an interrupted download leaves nothing that a later run would skip.
  • PDF_LAST_WINDOW is read in any case. A value that names no queue window, such as AG 1, is refused when the settings load.
  • The README, docs/decisions.md ("Which reports make fetch downloads") and future work follow the new default sample: 22 projects dated 30 September 2020, and AG1-462, 470 and 483, dated 1 October. In Berkeley Lab's data, 12 are 5 MW or smaller. The reports are 12 feasibility studies, 7 system impact studies and 6 that combine the two, and 13 of the projects are in Berkeley Lab's PJM cost data. The README also explains what a queue ID is.

Verification.

  • make test: 202 passed offline, with the current main merged in. New tests run the fetch against a stand-in for PJM's site. Twenty planted bugs, across both review rounds and my final review, each fail a test.
  • Live, against PJM's site on 30 November 2026:
    • A fresh make fetch into an empty folder downloaded the 25 default reports in 77 seconds, byte for byte the same as an earlier download. AG1-392A, B and C have no report.
    • PJM answers 404, with no redirect, at both addresses for AG1-392A, B and C, and for an ID that doesn't exist. I checked with curl, using the fetch's user agent.
    • After the review fixes, a rerun found all 25 already downloaded and the same three without a report, and exited with status 0.
    • --ids AF1-236 AC2-093 AF2-353 ZZ9-999 downloaded the three reports, byte for byte the copies I read by hand, and said ZZ9-999 isn't in the panel. After the review fixes, --ids AG1-462 into an empty folder downloaded the same file as before and left no partial file.
  • The embedding dry run on the new sample estimates 1,980,104 tokens, $0.0396.

Review. A separate agent reviewed the first commit. ac167c3 fixes its findings, among them: a failure to reach the site counted as no report, --ids could fetch a project twice, the docs gave 12 projects in Berkeley Lab's cost data rather than 13, and nothing tested the fetch against a stand-in for PJM's site. A second separate review, of this PR, asked for changes, and 6b8b193 makes them:

  • Only a 404 or 410 counts as no report. A refusal or a rate limit had counted as no report too.
  • A test checks the order of projects that applied on the same day.
  • The README explains queue IDs.
  • The command exits with status 1 after a site failure, a download is moved into place only once whole, and PDF_LAST_WINDOW is checked.
  • Wording points in the README and docs/decisions.md, and this description's note for existing checkouts.

A third separate review, of 07bc3e3, was stopped before it reported. My own final review of the whole diff found one gap: nothing said or tested what a redirect does. The fetch doesn't follow redirects, and a redirect stops it, like a refusal. PJM answered 404, without redirecting, for every missing report I checked, so this changes nothing in practice; the last commit says so in the code and docs/decisions.md, and tests it. These last fixes had my review only.

Not checked against OpenAI. This PR makes no OpenAI call. Embedding these reports and extracting their costs are paid steps that haven't run.

For existing checkouts. The old default sample included AG1-339, 340 and 341, which the new rule leaves out. Delete them from data/raw/pdfs/ before make embed. It takes the first 25 reports by file name that it hasn't embedded yet, so it would otherwise embed them in place of AG1-462, 470 and 483.

make fetch took the 25 most recent active or withdrawn projects that
applied before 1 October 2020. Berkeley Lab dates 10 AG1 projects 1 or 2
October 2020, so the cutoff left out three that have reports: AG1-462,
AG1-470 and AG1-483. A project without a report left the sample a report
short, a report already on disk was reported as fetched, the same as a
new download, and adding a report meant downloading it by hand.

- The selection keeps to the AG1 window and earlier ones
  (pdf_last_window), read from the queue ID, most recent first.
- It moves past projects without a report until it has 25, trying at
  most 50 (pdf_candidates_per_report).
- Each project's outcome is printed: downloaded, already downloaded or
  no report found.
- python -m src.fetch_pdfs --ids fetches named projects' reports, and
  flags any queue ID the panel doesn't hold.
- The README's sample facts, embedding estimate and "Adding a report"
  step follow the new default 25. docs/decisions.md records the choice.

make test: 172 passed offline. A live make fetch tried 28 projects:
AG1-392A, B and C have no report, and it took the next 25. The embed
dry run on them estimates 1,980,104 tokens, $0.0396.
…and-in

A network failure or a server error was reported as "no report found",
so with PJM's site down the fetch would try 50 projects, each waiting
out its timeouts. It now has its own outcome and stops at the first one.

- --ids fetches each named project once, the summary no longer counts
  IDs the panel doesn't hold as tried, and --ids can't be combined with
  --offline. The window setting is read in upper case.
- New tests run the fetch against a stand-in for PJM's site: a report at
  the second address, a missing report, a web page in place of a PDF,
  reports already on disk, an unreachable site, a server error and
  --ids from the command line. They also cover queue IDs that end in a
  letter. Eleven planted bugs each fail a test.
- The docs say 13 of the default 25 are in Berkeley Lab's cost data, not
  12. They also say that three of the six active or withdrawn AG1
  projects dated October have reports, and that the 1 October dates are
  Berkeley Lab's. The README's example of adding a report also runs
  make extract.
…aside

- Only a 404 or 410 counts as no report. PJM answered 404 at both
  addresses for AG1-392A, AG1-392B and AG1-392C. A refusal, a rate
  limit, a redirect or a server error stops the fetch, with a message
  that names the status, and the command exits with status 1.
- A report is written beside its final name and moved into place once
  whole, so an interrupted write leaves nothing a later run would skip.
- PDF_LAST_WINDOW is read in any case and must name a queue window,
  such as AG1.
- A test checks that projects that applied on the same day are taken in
  queue ID order.
- The README explains queue IDs, and docs/decisions.md gives the 404
  rule, its evidence and its trade-off.

189 tests pass offline.
The fetch doesn't follow redirects, and a redirect stops it, like a refusal. Nothing said
so or tested it. PJM answered 404, without redirecting, for every missing report checked,
so this changes nothing in practice.
@aymanazeem

Copy link
Copy Markdown
Owner Author

Evidence for 195c9bb, the head to be merged.

  • The checks job passed on Python 3.11 and 3.14 at every pushed head. Each run used 0 billable milliseconds, from gh api repos/aymanazeem/Interconnection-Queue-Agent/actions/runs/<id>/timing:
  • Locally, make test passed 202 tests, with the current main merged in. Twenty planted bugs each failed a test. The last one counted a redirect (302) as no report.
  • The live checks against PJM's site on 30 November 2026 are listed in the description.
  • Review: two separate reviews, whose findings ac167c3 and 6b8b193 fix. A third was stopped before it reported. 195c9bb comes from my own final review, and had my review only.
  • Not checked against OpenAI: this PR makes no OpenAI call.

@aymanazeem
aymanazeem merged commit 59ada9d into main Dec 1, 2026
2 checks passed
@aymanazeem
aymanazeem deleted the fix/fetch-queue-windows branch December 1, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant