Skip to content

Enforce analysis queue claims and state integrity#15

Merged
kasnder merged 4 commits into
mainfrom
agent/enforce-analysis-queue-leases
Jul 13, 2026
Merged

Enforce analysis queue claims and state integrity#15
kasnder merged 4 commits into
mainfrom
agent/enforce-analysis-queue-leases

Conversation

@kasnder

@kasnder kasnder commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • add a one-use UUID claim token to each analysis queue assignment and require the token for success/failure completion
  • keep /queue's plain bundle-ID response body while carrying the claim in X-Analysis-Claim-Token, and update the analyser (including exact ONLY_APP_ID runs) to round-trip it
  • accept case-insensitive App Store lookup matches while persisting the App Store's canonical bundle-ID casing
  • make successful signature replay clear failure/processing state and mark the app analysed

Why

Queue timeouts and explicit resets could previously issue the same app to a new worker while an older worker was still running. Completion updated by bundle ID alone, so that stale worker could overwrite the newer result. The completion update is now a compare-and-set on (appid, status = 'processing', analysis_claim_token) and consumes the claim on success. Refetches and replays clear the claim, which also invalidates work that they supersede.

First-time mixed-case bundle-ID requests also failed because addApp compared the request with canonical App Store casing using strict equality. Replay writes updated only the JSON/version/timestamp, leaving successful results hidden behind stale failure state.

Rollout

Migration 010_analysis_claim_tokens.sql adds the claim column and requeues processing rows that predate tokens. This requires a coordinated deployment: stop every queue processor, deploy the website and run the migration, deploy the matching analyser/processQueue.sh to every worker, then restart the workers. The queue body remains backward-compatible, but old analyser completions without the new header are deliberately rejected. Interrupted work is safely requeued by the migration.

Integration note

Draft PR #14 also changes routes/index.js. Rebase this branch after #14 lands, or resolve that route overlap explicitly if this PR merges first.

Validation

  • npm test — 27/27 passing, including live App Store, localhost endpoint, and route-level stale-claim 409 tests
  • node --test test/appsState.test.js test/replay-ios-signatures.test.js — 13/13 passing
  • bash -n analyser/processQueue.sh
  • node --check on changed JavaScript runtime files
  • git diff --check

@kasnder

kasnder commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Review complete. The claim-token CAS, migration ordering, and analyser token round-trip look sound. I removed the unused appId = app.details.appId reassignment in /analysis/:appId (commit 161a74d); npm test passes: 27/27.

Please keep the stated integration order explicit: rebase/reconcile this branch after #14, or resolve the overlapping route changes before merging. Otherwise /queue can miss #14’s async rejection bridge. The rollout remains coordinated: stop processors, migrate/deploy server, update every analyser, then restart, because old workers’ completion calls are intentionally rejected.

@kasnder
kasnder force-pushed the agent/enforce-analysis-queue-leases branch from 161a74d to 6b743bb Compare July 13, 2026 15:01
@kasnder
kasnder marked this pull request as ready for review July 13, 2026 15:02
@kasnder
kasnder merged commit aedb3a9 into main Jul 13, 2026
2 checks passed
@kasnder
kasnder deleted the agent/enforce-analysis-queue-leases branch July 13, 2026 15:02
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