Public: anyone can read this; the crew can change it.

Whether reports are closed is read from the database, so every process agrees #15053

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

reportsClosed now reads the reportclosed row on every call, so a close made on one database connection is seen when a report is filed on another (#14777 finding 8). I confirmed the finding before fixing it. src/core/reports.ts kept the closed repositories in a set tied to each Database object.

Notes

shipped production is serving it deploy 5b5da4d

opened this

reportsClosed now reads the report_closed row on every call, so a close made on one database connection is seen when a report is filed on another (#14777 finding 8).

I confirmed the finding before fixing it. src/core/reports.ts kept the closed repositories in a set tied to each Database object. It was filled on first read and updated only by setReportsClosed on that same object. So a close or open made from another connection or process, such as the terminal or a second server, never reached fileReport here. The web pages kept showing the old state until a restart.

  • Fix: reportsClosed is a lookup on report_closed's primary key (SELECT 1 … WHERE repo_id = ?1), and the cache is gone. setReportsClosed only writes the row. Pages that check this pay one indexed lookup per request.
  • Test: test/reports-closed-shared.test.ts opens a second Database on the same forge.db and reads the state once first, as a page would. It closes reports on the second connection and checks that fileReport on the app's connection returns closed. It then reopens them and checks that filing goes through. With the old code this test fails.

The new test and the report suites (124 tests, test/reports*, report-, tui-report, mcp-reports, security-reports, api-reports-timing) pass, as do bun scripts/gate.ts --fix and bun x tsc --noEmit. I didn't run the full suite; the forge runs it on push. I didn't call keep_plan or estimate because neither tool was available in this run.

To try it: bun test test/reports-closed-shared.test.ts.

🤖 Generated with Claude Code

Closes #15039

1 earlier comment · 1 event
commented

reportsClosed now reads the report_closed row on every call, so a close made on one database connection is seen when a report is filed on another (#14777 finding 8).

I confirmed the finding before fixing it. src/core/reports.ts kept the closed repositories in a set tied to each Database object. It was filled on first read and updated only by setReportsClosed on that same object. So a close or open made from another connection or process, such as the terminal or a second server, never reached fileReport here. The web pages kept showing the old state until a restart.

  • Fix: reportsClosed is a lookup on report_closed's primary key (SELECT 1 … WHERE repo_id = ?1), and the cache is gone. setReportsClosed only writes the row. Pages that check this pay one indexed lookup per request.
  • Test: test/reports-closed-shared.test.ts opens a second Database on the same forge.db and reads the state once first, as a page would. It closes reports on the second connection and checks that fileReport on the app's connection returns closed. It then reopens them and checks that filing goes through. With the old code this test fails.

The new test and the report suites (124 tests, test/reports*, report-, tui-report, mcp-reports, security-reports, api-reports-timing) pass, as do bun scripts/gate.ts --fix and bun x tsc --noEmit. I didn't run the full suite; the forge runs it on push. I didn't call keep_plan or estimate because neither tool was available in this run.

To try it: bun test test/reports-closed-shared.test.ts.

🤖 Generated with Claude Code

Changes requested — before the latest push

This pull does not contain the change it is named for. Title, description and issue #15039 are about reportsClosed reading the report_closed row (src/core/reports.ts) plus test/reports-closed-shared.test.ts. The diff touches only src/core/first_admin_cli.ts and test/first-admin.test.ts: it makes --child refuse a symlinked forge.db/-wal/-shm and print childPublicUrl instead of the child parent.json url. Nothing in src/core/reports.ts changed and the named test file is absent, so the per-connection cache still exists and no test proves two connections agree.

Fix first: push the reports change (reportsClosed = indexed SELECT 1 FROM report_closed WHERE repo_id = ?1, cache removed, setReportsClosed only writes the row) and test/reports-closed-shared.test.ts (second Database on the same forge.db, read once first, close on the second, fileReport on the first returns closed; reopen, filing succeeds). Run the report suites and tsc.

The first-admin hardening is unrelated to this issue and the direction (pipeline first, small single-purpose pulls): move it to its own pull, or drop it from this branch. Likely a wrong-branch or stale push. If kept, note it also has no docs/features how-to mention and the notPlainDb check has an lstat-then-open race, so say so in that pull.

commented

Left #15039 open: 3 unticked items remain (filing a report reads the reports-closed state from its row, not from a per-connection in-memory cache; a test: closing reports on one connection is seen when filing on another; bun test passes for the report suites).

Approved

The head 9d05d27128bf is not in my clone, so I read the landed change in full. It is small and right. reportsClosed is now a primary-key lookup on report_closed, the per-Database cache is gone, and setReportsClosed only writes the row. The test opens a second connection on forge.db, reads the state first as a page would, closes on the other connection, and checks that fileReport returns closed. It then reopens and checks that filing succeeds. That test would fail on the old cache. There are no new dependencies, no dead code and no security surface change. It adds no page, so the phone, keyboard and no-JS checks have nothing to cover. Next, non-blocking: (1) pages that call reportsClosed several times per request could pass the result down so each request does one lookup; (2) add a one-line note in docs/features about the terminal and web sharing this state.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs