Skip to content

fix(forecast): save the forecast identity outside the lock - #1883

Merged
frahlg merged 1 commit into
masterfrom
a9-forecast-identity-save-outside-lock
Oct 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
a9-forecast-identity-save-outside-lock

Conversation

@frahlg

@frahlg frahlg commented Oct 27, 2026

Copy link
Copy Markdown
Member

Item A9 of the stable plan (reports/stable-plan-20261027.md).

Problem

RefreshIdentity holds forecastSiteConfig.mu while it calls SaveConfig twice: the identity binding (forecast_site.go:254) and config_revision (:262). Each save runs under a 5 s context with busy_timeout(5000). While another writer holds the SQLite write lock, one refresh holds the lock for about 10 s. The control tick calls Snapshot(), which takes a read lock on the same mutex (main.go:3073, 3316, 2973), so the tick waits too. At a 5 s tick that drops about two ticks, and fuse and watchdog reactions come late.

A failed binding save leaves bindingDirty set, and the 1 Hz identity poll tries again every second with no pause.

Repro on master (from the audit, caa-49): Snapshot waited 10.07s; RefreshIdentity took 10.17s.

Change

  • RefreshIdentity computes the receipt and revision under s.mu, drops the lock, then saves. A successful binding save clears bindingDirty under the lock. Callers already serialize RefreshIdentity under forecastConfigMu, so the saves keep their order.
  • A failed binding save sets bindingRetryAt 30 s ahead. The poll skips the binding save until then. The binding stays dirty, so the next try still happens.
  • Configure saves the weather generation receipt after it drops s.mu, the same way.

Tests

  • TestForecastSnapshotDoesNotWaitForIdentitySave (the audit repro, renamed): fails on master with a 10 s wait, passes here (Snapshot waited 31µs).
  • TestForecastIdentityBindingSaveBacksOffAfterFailure: a failed save is not retried within 30 s and is retried after.
  • cd go && go test -race ./cmd/ftw/... -count=1: ok (177 s).
  • go vet ./... and go build ./...: clean.

Risk

Low. Only the time of the writes moves; what gets written is unchanged. During the 30 s pause after a failed save, the in-memory learning revision is already in use, as it was before when a save failed.

🤖 Generated with Claude Code

RefreshIdentity held forecastSiteConfig.mu across two SaveConfig calls,
each up to 5 s against a busy SQLite writer. The control tick's
Snapshot waited behind them. Compute under the lock, save after it, and
wait 30 s before retrying a failed binding save. Configure's weather
generation save moves out of the lock the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T13:13:59.468956Z bc81ed8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit 60303cc into master Oct 27, 2026
23 checks passed
@frahlg
frahlg deleted the a9-forecast-identity-save-outside-lock branch November 11, 2026 09:12
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