diff-sentry 0.18.0__tar.gz → 0.18.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/rules/monitoring.md +2 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/CHANGELOG.md +8 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/PKG-INFO +2 -2
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/README.md +1 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/action.yml +1 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/__init__.py +1 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/actors.py +1 -3
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/watch.py +174 -65
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/docs/watch.md +2 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/pyproject.toml +1 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_watch.py +162 -3
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_watch_pool.py +69 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/uv.lock +1 -1
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/rules/detect-setup.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/rules/handoff.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/rules/indicators.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/rules/rubric-and-eval.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.claude/skills/release/SKILL.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.env.example +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.github/workflows/ci.yml +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.github/workflows/release.yml +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.gitignore +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/.python-version +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/AGENTS.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/LICENSE +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/VENDOR.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/__main__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/assemble.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/cli.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/config.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/dbutil.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/deep_classify.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/detect.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/emit.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/fetch_tool.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/history.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/hosts.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/images.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/indicators.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/ingest.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/linewide.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/normalize.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/npm.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/pycheck.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/releases.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/response.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/rl_export.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/rubric.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/schema.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/shelllex.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/ci-and-workflows.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/concealment-and-provenance.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/developer-autorun.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/llm-directed-text.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/package-and-build-hooks.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/runtime-droppers-and-exfil.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/skills/triage-a-change.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/diff_sentry/snapshot.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/docs/development.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/docs/how-it-works.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/docs/limits.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/docs/release-watch.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/README.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/__init__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/__main__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/cli.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/judge.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/schema.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/score.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/diff_sentry_eval/taskset.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/pyproject.toml +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/taskset.example.json +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/conftest.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_boundary.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_cli.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_judge.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_schema.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_score.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/eval/tests/test_taskset.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/DESIGN.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/README.md +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/diff_sentry_studio/__init__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/diff_sentry_studio/app.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/diff_sentry_studio/iterations.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/diff_sentry_studio/live.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/diff_sentry_studio/mapper.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/pyproject.toml +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/app.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/index.html +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/replay-core.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/run-core.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/style.css +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/trajectory.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/static/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/replay-core.test.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/run-core.test.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/static-contract.test.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/test_app.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/test_iterations.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/test_live.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/test_mapper.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/studio/tests/trajectory.test.js +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/__init__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/conftest.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/corpus/change_corpus.json +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/corpus/hackerbot_claw_campaign.json +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/corpus/hackerbot_claw_incident.json +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/fixtures/known-malicious.diff +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/__init__.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/grammar.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/harness.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/lexrunner.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/programs.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/oracle/runner.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_actors.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_adversarial_input.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_assemble.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_campaign_replay.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_cli.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_cli_watch.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_config.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_deep_classify.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_detect.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_detection_quality.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_dogfood_gate.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_emit.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_enclosure.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_export.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_fetch_tool.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_file_scope.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_file_structure.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_forward_offline.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_gate_edges.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_grounding.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_history.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_hosts.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_images.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_incident_hackerbot_claw.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_indicators.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_ingest.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_ingest_metadata.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_injection_offline.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_inline_exec_and_bidi.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_linewide.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_lookalike_owner.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_metadata_rules.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_normalize.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_npm.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_oracle.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_oracle_harness.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_provenance.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_python_loader.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_release_final.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_releases.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_response.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_rubric.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_schema.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_sft_trace.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_shelllex.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_skills.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_snapshot.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_subscription.py +0 -0
- {diff_sentry-0.18.0 → diff_sentry-0.18.1}/tests/test_workflows.py +0 -0
|
@@ -28,11 +28,12 @@ paths:
|
|
|
28
28
|
- **The first copy is kept.** `SnapshotStore.put` runs before anything else touches a change; objects are never rewritten and the index is append-only. An edit is a new revision with its own run id (`-r1`), so its trace never overwrites the original's, and `prior_indicators` carry the earlier hits forward so a removed payload cannot remove the evidence. `evidence-scrubbed` fires when a floor-level hit of an earlier revision is gone (matched by rule and location, not id; a payload rewritten to read as prose counts as gone) and names the vanished hit ids, so a later edit that still lacks them is the same finding and does not page again. A vanished hit whose file this version does not show is `evidence-unseen` (`medium`) instead, judged per hit (`actors._unseen_locations`): the file is listed without a patch, is not `removed`, and has changed lines, or is `added` or `modified` at 0/0 while GitHub withheld other content in the same event (another file with changed lines and no patch, or `files_truncated`); or it is not listed and the list is truncated. A lone 0/0 file (an emptied file, a mode change), a pure rename at 0/0 (the file now equals its base), a `removed` file, a file missing from a full list, a shown patch without the hit, and the body, a branch or a comment stay `evidence-scrubbed`. The prior hit is carried either way. An author who removes a payload and makes GitHub withhold the file (a huge file or pull request) gets `evidence-unseen` instead of the page: an accepted residual, since the carried hit keeps the evidence at its floor. Snapshot the event as ingested, before correlation attaches facts, so the archive holds what GitHub said and not what we derived.
|
|
29
29
|
- **Time is the cost, not money.** With a local model every change reaches the model by default; the screen sets the order (`_priority`), not eligibility. The caps (`deep_min_severity`, `max_queue`, `max_deep_per_hour`) default off. A shed change keeps its `screened/` record and a `shed` state.
|
|
30
30
|
- **The screen is not a trajectory.** `cli.screen` writes `screened/{run_id}.json`, never a trace, so the rollout corpus stays trajectories. Its early alert is `stage=screen`; the run's own is `stage=final`.
|
|
31
|
-
- **A run never shares a thread.** dspy's global configuration is bound to the thread that first set it up. With `workers=1` the worker thread runs the model itself; with more, each run goes to a `spawn` process of a `ProcessPoolExecutor` (its own interpreter and dspy), and the worker thread keeps every read and write of the state (claim, settle, finalize). Never run the model in a thread pool. A child that dies breaks the pool: every run in it counts as a failed attempt and the pool is rebuilt; a run that finished first keeps its result. A stopped pool terminates its children and leaves
|
|
31
|
+
- **A run never shares a thread.** dspy's global configuration is bound to the thread that first set it up. With `workers=1` the worker thread runs the model itself; with more, each run goes to a `spawn` process of a `ProcessPoolExecutor` (its own interpreter and dspy), and the worker thread keeps every read and write of the state (claim, settle, finalize). Never run the model in a thread pool. A child that dies breaks the pool: every run in it counts as a failed attempt and the pool is rebuilt; a run that finished first keeps its result. A stopped pool terminates its children, keeps the outcomes it received and leaves interrupted rows claimed for `recover()`; an unexpected error settles them as a failed attempt, so a long-lived watcher strands nothing. A claim or a submit that fails touches its own row only. Whatever a child's future raises, a Ctrl-C included, is that run failing, never the worker thread's end. A child exits as soon as its watcher is gone (`_child_init`), so a watcher killed outright cannot leave a run going while a restart runs the same run id again. A run sets the change's state only while it is the change's latest revision (`_mark`). An examined change's row, its queue row and the change shed to make room are written in one transaction (`record_examined`): a change never reads `queued` without a queue row (the next poll would call it unchanged and never run it), and a worker never claims a change without a row. A claim whose bookkeeping fails backs off like a failed run (`retry`, then `bury` after `_MAX_ATTEMPTS`) and its change reads `queued` again: given back at once, it would come first on the next claim and hold up every run behind it. On stop, `serve()` joins its worker before the CLI can close the databases and release the lock. The single worker finishes its current run. More than one worker needs a runner and poster that pickle, checked before any file is opened. The poller is a separate thread and touches no model.
|
|
32
32
|
- **A failed change must not block the ones behind it, and must be retried.** A failure holds the watermark below it and withholds the page-1 ETag (otherwise the next listing answers 304 and it is never retried), backs off exponentially, and after `_MAX_FAILS` is parked as `error` so it stops holding the listing. The others are skipped by their stored `updated_at`. A listing deeper than `_MAX_PAGES` is reported as truncated, never advanced past silently. A rate-limit refusal (`429`, or `403` saying so) is not a failure of the change: wait for the reset, and `_ingest` subtracts the calls it made from the budget the list responses report.
|
|
33
33
|
- **A read that failed is not a change.** `_comments` returns None on failure and the event carries `comments_incomplete`; the watcher then keeps what it has instead of judging the empty thread as an edit. Anything that feeds the digest must distinguish "none" from "could not read".
|
|
34
34
|
- **Run ids are unambiguous.** `owner__name-pr-7` (`-r1` per revision); a release's are `pypi__`, `npm__` and `oci__` ids, and a GitHub owner named `pypi`, `npm` or `oci` (case-folded: `PyPI__x` and `pypi__x` are one file on a case-insensitive disk) is written `<owner>_gh__` (`watch._ARTIFACT_NAMESPACES`), so a polled change and a release never share an id, a `screened/`, `responses/` or `traces/` file, or a queue row. Owners cannot contain `_`, so no other repository writes `<owner>_gh` and two repositories never collide. The import still refuses a release whose id a polled change uses (`names_change`, in any case), which only a change stored before the `_gh` form can. A queue row's repository stays its event's (`pypi/x` is both a GitHub repository and a package, as the pause reads it). The one-off `pr`/`issue` commands keep the `owner-name-pr-7` scheme, which can collide.
|
|
35
35
|
- **A failed model run is retried, and pages nothing.** It backs off up to `_MAX_ATTEMPTS` (about four hours, so a local model restarting does not fail the queue) with `cli.run` told `emit_failed=False`, then is buried (`claimed=2`, event kept) for `--requeue-failed`. Claiming counts as an attempt, so an input that kills the process cannot loop across restarts. The queue row stays claimed until the run completes, and `recover()` (called by `serve` and `--once`, never by a read-only look) requeues it under a per-directory `flock`. Neither thread may die on an unexpected exception.
|
|
36
|
+
- **A completed outcome is saved before actor bookkeeping.** `pending_settlements` and `queue.claimed=3` are committed together in `watch.db`. Recovery leaves those rows out of model dispatch. The worker retries actor finalization from the saved outcome and removes the queue row and checkpoint in the same transaction that marks the current revision done. This replay issues no model call or SIEM request. Paused repositories hold their saved outcomes. Graceful exit flushes successful outcomes still in memory if the initial checkpoint write failed. A kill before the checkpoint can still interrupt this sequence. A queue cap can only shed a row that is still unclaimed when the poller deletes it.
|
|
36
37
|
- **A paused repository is held, never cleared.** `WatchConfig.paused` (`DS_WATCH_PAUSED_REPOS`, `parse_paused`, lower-cased; an `owner/name` is kept as written, and a `pypi/`, `npm/` or `oci/` entry also adds the queue `repo` its release carries when it parses: `releases.parse_packages`' normalized name, `npm.parse_npm_packages`' name, `images.parse_image`'s label; an entry neither form reads is refused, and `--repos` stays `owner/name` only) leaves it out of polling, `due_checks`, `pending_alerts` (before the per-poll slice, so it holds no retry slot), `claim`, and the queue cap's `queue_size`/`lowest` (so it is never shed for another's change). A queue row's repository is read from its event (`json_extract`), never its run id's prefix, which `owner/name-pr` shares. Nothing it stores is written: no row deleted or shed, no watermark, ETag or snapshot touched (only `recover` still buries a run a stop cut off on its last attempt, as for any repository). A pause may name a repository no longer in `repos` (that is the point: its queue outlives the listing), so it is never checked against `repos`; the watcher logs what it holds at start and `stats(paused)` counts it as `queued_paused`.
|
|
37
38
|
- **Undelivered alerts are retried a few at a time.** `_retry_alerts` re-sends at most `_ALERT_RETRIES_PER_POLL` (5) per poll, so a SIEM that hangs (a POST is bounded by 15 s) cannot stall polling for a whole backlog.
|
|
38
39
|
- **An alert counts once delivered.** `changes.alerted` gains ids only after the SIEM answered 2xx (`EmitResult.ok`); a refusal or outage leaves `alert_pending`, re-sent from `screened/{run_id}.json` on later polls. `emitted` alone is also True for a 5xx.
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to diff-sentry, a BewAIre-style detector that classifies one GitHub change (PR, issue or push) for malicious intent on [`rlm-harness`](https://github.com/qazbnm456/rlm-harness).
|
|
4
4
|
|
|
5
|
+
## 0.18.1
|
|
6
|
+
|
|
7
|
+
Upgrade from 0.18.0: `watch` can reuse its existing state directory.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- **`watch` waits for its worker before closing the databases and releasing the state lock.** A single worker finishes its current run, and work interrupted in a process pool can resume after restart within the existing attempt limit.
|
|
11
|
+
- **`watch` can finish recording a completed run after a database error.** Once the result is saved, the watcher can retry the actor update, including after a restart, without rerunning the model or sending the final SIEM alert again.
|
|
12
|
+
|
|
5
13
|
## 0.18.0
|
|
6
14
|
|
|
7
15
|
Upgrade from 0.17.0: a pull request of an LLM product no longer signals on the words "system prompt" in its own translations and code, and the planner must quote the change it accuses. If you run `watch`, delete `actors.db` from its state directory (`DS_WATCH_STATE_DIR`, default `output/state`) before restarting it: otherwise hits stored under the old rules read as a scrubbed payload on the next revision. This restarts the cross-event memory (actor history, prior flags, `ioc_reuse`, carried hits) from zero; leave `watch.db` and `snapshots/` alone. The GitHub Action's scan is unchanged, and `rlm-harness==1.25.0` is unchanged.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: diff-sentry
|
|
3
|
-
Version: 0.18.
|
|
3
|
+
Version: 0.18.1
|
|
4
4
|
Summary: Catch malicious pull requests before they merge: scan a diff for supply-chain attack patterns with deterministic evidence a model cannot suppress.
|
|
5
5
|
Author: Boik Su
|
|
6
6
|
License-Expression: MIT
|
|
@@ -43,7 +43,7 @@ jobs:
|
|
|
43
43
|
- uses: actions/checkout@v7
|
|
44
44
|
with:
|
|
45
45
|
fetch-depth: 0 # the scan diffs against the PR base
|
|
46
|
-
- uses: qazbnm456/diff-sentry@v0.18.
|
|
46
|
+
- uses: qazbnm456/diff-sentry@v0.18.1
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
That is the whole setup. The job fails when an indicator at or above `high` fires. Add `push` to `on:` to also scan commits pushed straight to a branch. A push that bypasses branch protection can also delete this workflow, so `watch` and `release-watch` read the repository and its releases from outside.
|
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
- uses: actions/checkout@v7
|
|
22
22
|
with:
|
|
23
23
|
fetch-depth: 0 # the scan diffs against the PR base
|
|
24
|
-
- uses: qazbnm456/diff-sentry@v0.18.
|
|
24
|
+
- uses: qazbnm456/diff-sentry@v0.18.1
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
That is the whole setup. The job fails when an indicator at or above `high` fires. Add `push` to `on:` to also scan commits pushed straight to a branch. A push that bypasses branch protection can also delete this workflow, so `watch` and `release-watch` read the repository and its releases from outside.
|
|
@@ -40,7 +40,7 @@ inputs:
|
|
|
40
40
|
that PR rather than by the ones already on main.
|
|
41
41
|
required: false
|
|
42
42
|
# KEEP IN STEP WITH [project].version. release.yml fails the build if this drifts from the tag being released, because a stale default here would silently run an old scanner under a new action tag.
|
|
43
|
-
default: '0.18.
|
|
43
|
+
default: '0.18.1'
|
|
44
44
|
|
|
45
45
|
outputs:
|
|
46
46
|
failed:
|
|
@@ -296,19 +296,17 @@ class ActorStore:
|
|
|
296
296
|
"""Attach the model's outcome to a sighting once the run has finished.
|
|
297
297
|
|
|
298
298
|
Attribution follows the evidence. If the change's floor-level evidence is a third party's comment (the author's own hits stayed below the floor), the verdict belongs to that commenter, not to the author."""
|
|
299
|
-
with self._lock:
|
|
299
|
+
with self._lock, self._db:
|
|
300
300
|
row = self._db.execute("SELECT mixed, own_signal FROM sightings WHERE run_id=?", (run_id,)).fetchone()
|
|
301
301
|
if row is not None and row["mixed"] and not row["own_signal"]:
|
|
302
302
|
taken = self._db.execute(
|
|
303
303
|
"UPDATE sightings SET verdict=? WHERE parent=? AND channel='comment' AND signal=1",
|
|
304
304
|
(verdict, run_id)).rowcount
|
|
305
305
|
if taken:
|
|
306
|
-
self._db.commit()
|
|
307
306
|
return
|
|
308
307
|
# nobody else's sighting exists to carry it (the comment is gone, or its writer could not be matched): the verdict is not lost, it stays with the change it was made about
|
|
309
308
|
self._db.execute("UPDATE sightings SET verdict=?, signal=?, max_severity=? WHERE run_id=?",
|
|
310
309
|
(verdict, int(signal), max_severity, run_id))
|
|
311
|
-
self._db.commit()
|
|
312
310
|
|
|
313
311
|
# ── reading ────────────────────────────────────────────────────────────────────────────────────
|
|
314
312
|
|
|
@@ -40,6 +40,7 @@ from concurrent.futures import FIRST_COMPLETED, Future, ProcessPoolExecutor, wai
|
|
|
40
40
|
from concurrent.futures.process import BrokenProcessPool
|
|
41
41
|
from dataclasses import dataclass, field
|
|
42
42
|
from datetime import UTC, datetime, timedelta
|
|
43
|
+
from itertools import islice
|
|
43
44
|
from typing import Any
|
|
44
45
|
|
|
45
46
|
from .actors import ActorStore
|
|
@@ -68,6 +69,9 @@ SCHEMA_VERSION = 2
|
|
|
68
69
|
_DEAD = 2 # `queue.claimed` value for a run that exhausted its attempts (kept for --requeue-failed)
|
|
69
70
|
# The hand-over from `release-watch --final` (`spool_final`): a release's event as a file, imported into the queue by `Watcher.import_spool`.
|
|
70
71
|
FINAL_QUEUE = "final-queue"
|
|
72
|
+
_PENDING_SETTLEMENT = 3 # the result is saved and only bookkeeping can run
|
|
73
|
+
_SETTLEMENT_RETRY_S = 5
|
|
74
|
+
_SETTLEMENT_BATCH = 4
|
|
71
75
|
_CONSUMER = ".consumer" # written by every `watch` that imports: whether it runs the model, and when it last looked
|
|
72
76
|
_CONSUMER_VERSION = 1
|
|
73
77
|
_CONSUMER_STALE_S = 3600
|
|
@@ -88,6 +92,8 @@ CREATE TABLE IF NOT EXISTS queue (
|
|
|
88
92
|
seq INTEGER PRIMARY KEY AUTOINCREMENT, run_id TEXT UNIQUE NOT NULL, priority INTEGER NOT NULL,
|
|
89
93
|
enqueued_at TEXT NOT NULL, event_json TEXT NOT NULL, claimed INTEGER NOT NULL DEFAULT 0,
|
|
90
94
|
attempts INTEGER NOT NULL DEFAULT 0, not_before TEXT);
|
|
95
|
+
CREATE TABLE IF NOT EXISTS pending_settlements (
|
|
96
|
+
run_id TEXT PRIMARY KEY NOT NULL, verdict TEXT, signal INTEGER NOT NULL, severity TEXT NOT NULL);
|
|
91
97
|
CREATE TABLE IF NOT EXISTS deep_log (started_at TEXT NOT NULL);
|
|
92
98
|
"""
|
|
93
99
|
|
|
@@ -435,12 +441,13 @@ class WatchState:
|
|
|
435
441
|
(repo, kind, number, *cols.values()))
|
|
436
442
|
|
|
437
443
|
def record_examined(self, repo: str, kind: str, number: int, cols: dict[str, Any], *,
|
|
438
|
-
queue: tuple[str, int, dict, datetime] | None = None, shed: str | None = None) ->
|
|
444
|
+
queue: tuple[str, int, dict, datetime] | None = None, shed: str | None = None) -> bool:
|
|
439
445
|
"""What one examination decided, in ONE transaction: the change row, its queue row (`queue`: run id, priority, event, time), and the change `shed` to make room. A failure writes none of them, so a change never reads `queued` without a queue row (the next poll would call it unchanged and never run it), and a worker never claims a queue row whose change has no row."""
|
|
440
446
|
with self._lock:
|
|
441
447
|
try:
|
|
442
|
-
|
|
443
|
-
|
|
448
|
+
removed = shed is not None and bool(self._db.execute(
|
|
449
|
+
"DELETE FROM queue WHERE run_id=? AND claimed=0", (shed,)).rowcount)
|
|
450
|
+
if removed:
|
|
444
451
|
self._db.execute("UPDATE changes SET state='shed' WHERE run_id=?", (shed,))
|
|
445
452
|
self._upsert(repo, kind, number, cols)
|
|
446
453
|
if queue is not None:
|
|
@@ -452,6 +459,7 @@ class WatchState:
|
|
|
452
459
|
except BaseException:
|
|
453
460
|
self._db.rollback()
|
|
454
461
|
raise
|
|
462
|
+
return removed
|
|
455
463
|
|
|
456
464
|
def due_checks(self, now: datetime, paused: tuple[str, ...] = ()) -> list[sqlite3.Row]:
|
|
457
465
|
skip, args = _unpaused("repo", paused)
|
|
@@ -513,10 +521,44 @@ class WatchState:
|
|
|
513
521
|
return row
|
|
514
522
|
|
|
515
523
|
def unclaim(self, run_id: str) -> None:
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
524
|
+
"""Return the single dispatcher's most recent claim when it stops before starting the model."""
|
|
525
|
+
with self._lock, self._db:
|
|
526
|
+
returned = self._db.execute("UPDATE queue SET claimed=0, attempts=attempts-1 WHERE run_id=? AND claimed=1",
|
|
527
|
+
(run_id,)).rowcount
|
|
528
|
+
if returned:
|
|
529
|
+
self._db.execute("UPDATE changes SET state='queued' WHERE run_id=?", (run_id,))
|
|
530
|
+
self._db.execute("DELETE FROM deep_log WHERE rowid=(SELECT MAX(rowid) FROM deep_log)")
|
|
531
|
+
|
|
532
|
+
def checkpoint(self, run_id: str, outcome: tuple) -> None:
|
|
533
|
+
with self._lock, self._db:
|
|
534
|
+
self._db.execute("INSERT OR IGNORE INTO pending_settlements VALUES (?, ?, ?, ?)", (run_id, *outcome))
|
|
535
|
+
self._db.execute("UPDATE queue SET claimed=? WHERE run_id=?", (_PENDING_SETTLEMENT, run_id))
|
|
536
|
+
|
|
537
|
+
def pending_settlements(self, paused: tuple[str, ...], after: int) -> list[sqlite3.Row]:
|
|
538
|
+
skip, args = _unpaused(_QUEUE_REPO, paused)
|
|
539
|
+
with self._lock:
|
|
540
|
+
return self._db.execute(
|
|
541
|
+
"SELECT queue.seq, queue.run_id, verdict, signal, severity,"
|
|
542
|
+
" json_extract(event_json, '$.kind')='release' AS release,"
|
|
543
|
+
" json_extract(event_json, '$.spooled') IS NOT NULL AS spooled"
|
|
544
|
+
f" FROM pending_settlements JOIN queue USING (run_id) WHERE queue.seq>?{skip}"
|
|
545
|
+
" ORDER BY queue.seq LIMIT ?", (after, *args, _SETTLEMENT_BATCH)).fetchall()
|
|
546
|
+
|
|
547
|
+
def finish(self, run_id: str) -> None:
|
|
548
|
+
with self._lock, self._db:
|
|
549
|
+
self._db.execute("UPDATE changes SET state='done' WHERE run_id=?", (run_id,))
|
|
550
|
+
self._db.execute("DELETE FROM queue WHERE run_id=?", (run_id,))
|
|
551
|
+
self._db.execute("DELETE FROM pending_settlements WHERE run_id=?", (run_id,))
|
|
552
|
+
|
|
553
|
+
def settle_failure(self, run_id: str, attempts: int, not_before: datetime) -> None:
|
|
554
|
+
with self._lock, self._db:
|
|
555
|
+
if attempts >= _MAX_ATTEMPTS:
|
|
556
|
+
self._db.execute("UPDATE queue SET claimed=? WHERE run_id=?", (_DEAD, run_id))
|
|
557
|
+
self._db.execute("UPDATE changes SET state='failed' WHERE run_id=?", (run_id,))
|
|
558
|
+
else:
|
|
559
|
+
self._db.execute("UPDATE queue SET claimed=0, attempts=?, not_before=? WHERE run_id=?",
|
|
560
|
+
(attempts, _iso(not_before), run_id))
|
|
561
|
+
self._db.execute("UPDATE changes SET state='queued' WHERE run_id=?", (run_id,))
|
|
520
562
|
|
|
521
563
|
def retry(self, run_id: str, attempts: int, not_before: datetime) -> None:
|
|
522
564
|
self._q("UPDATE queue SET claimed=0, attempts=?, not_before=? WHERE run_id=?",
|
|
@@ -528,8 +570,13 @@ class WatchState:
|
|
|
528
570
|
|
|
529
571
|
def requeue_claimed(self) -> int:
|
|
530
572
|
"""Put back what a previous process was running when it stopped, unless it has used up its attempts."""
|
|
531
|
-
self.
|
|
532
|
-
|
|
573
|
+
with self._lock, self._db:
|
|
574
|
+
self._db.execute("UPDATE changes SET state='failed' WHERE run_id IN"
|
|
575
|
+
" (SELECT run_id FROM queue WHERE claimed=1 AND attempts>=?)", (_MAX_ATTEMPTS,))
|
|
576
|
+
self._db.execute("UPDATE queue SET claimed=? WHERE claimed=1 AND attempts>=?", (_DEAD, _MAX_ATTEMPTS))
|
|
577
|
+
self._db.execute("UPDATE changes SET state='queued' WHERE run_id IN"
|
|
578
|
+
" (SELECT run_id FROM queue WHERE claimed=1)")
|
|
579
|
+
return self._db.execute("UPDATE queue SET claimed=0 WHERE claimed=1").rowcount
|
|
533
580
|
|
|
534
581
|
def requeue_dead(self) -> list[str]:
|
|
535
582
|
with self._lock:
|
|
@@ -550,8 +597,9 @@ class WatchState:
|
|
|
550
597
|
self._q("UPDATE changes SET state=? WHERE run_id=?", (state, run_id))
|
|
551
598
|
|
|
552
599
|
def note_deep(self, now: datetime) -> None:
|
|
553
|
-
self.
|
|
554
|
-
|
|
600
|
+
with self._lock, self._db:
|
|
601
|
+
self._db.execute("INSERT INTO deep_log (started_at) VALUES (?)", (_iso(now),))
|
|
602
|
+
self._db.execute("DELETE FROM deep_log WHERE started_at<?", (_iso(now - timedelta(hours=2)),))
|
|
555
603
|
|
|
556
604
|
def deep_last_hour(self, now: datetime) -> list[str]:
|
|
557
605
|
with self._lock:
|
|
@@ -711,6 +759,9 @@ class Watcher:
|
|
|
711
759
|
self._import_lock = threading.Lock() # the poller and, with workers > 1, the worker thread both import
|
|
712
760
|
self._stop = threading.Event()
|
|
713
761
|
self._wake = threading.Event()
|
|
762
|
+
self._unwritten: dict[str, tuple[sqlite3.Row, tuple | None]] = {}
|
|
763
|
+
self._next_settlement = 0.0
|
|
764
|
+
self._settlement_cursor = 0
|
|
714
765
|
self._interval = config.poll_interval_s
|
|
715
766
|
self._rate_wait_until: datetime | None = None
|
|
716
767
|
self._rate_left: int | None = None # the API budget we believe is left
|
|
@@ -726,8 +777,7 @@ class Watcher:
|
|
|
726
777
|
n = self.state.requeue_claimed()
|
|
727
778
|
if n:
|
|
728
779
|
log.info("requeued %d change(s) a previous run was judging when it stopped", n)
|
|
729
|
-
|
|
730
|
-
self.state.set_state_of_run(run_id, "queued")
|
|
780
|
+
|
|
731
781
|
|
|
732
782
|
# ── polling ────────────────────────────────────────────────────────────────────────────────────
|
|
733
783
|
|
|
@@ -1044,13 +1094,13 @@ class Watcher:
|
|
|
1044
1094
|
state, prio, victim = "screened", 0, None
|
|
1045
1095
|
if not self.config.screen_only and self._wants_model(hits):
|
|
1046
1096
|
state, prio, victim = self._admit(run_id, hits, event)
|
|
1047
|
-
self.state.record_examined(
|
|
1097
|
+
removed = self.state.record_examined(
|
|
1048
1098
|
repo, kind, number,
|
|
1049
1099
|
{"updated_at": updated, "content_sha256": digest, "flags": flags, "revision": revision, "run_id": run_id,
|
|
1050
1100
|
"state": state, "first_seen": first_seen, "checks": checks, "next_check_at": next_check, "gone_at": None,
|
|
1051
1101
|
"alerted": json.dumps(sorted(alerted)), "alert_pending": pending, "alert_fails": 0, **healthy},
|
|
1052
1102
|
queue=(run_id, prio, event, now) if state == "queued" else None, shed=victim)
|
|
1053
|
-
if
|
|
1103
|
+
if removed or state == "shed":
|
|
1054
1104
|
report.shed += 1
|
|
1055
1105
|
log.info("queue full — shed %s", victim or run_id)
|
|
1056
1106
|
report.queued += state == "queued"
|
|
@@ -1102,7 +1152,7 @@ class Watcher:
|
|
|
1102
1152
|
|
|
1103
1153
|
def _claim(self) -> tuple[sqlite3.Row, dict] | None:
|
|
1104
1154
|
"""Take the highest-priority ready change, unless the hourly cap is reached, and mark it running. A handed-over release's full event is read from `final-queue/accepted/` here; one that cannot be read is buried at once (nothing brings it back). A claim whose bookkeeping fails backs off like a failed run, so the row does not come first again on the next claim and hold up every one behind it."""
|
|
1105
|
-
while self._may_run():
|
|
1155
|
+
while not self._stop.is_set() and self._may_run():
|
|
1106
1156
|
row = self.state.claim(self._clock(), self.config.paused)
|
|
1107
1157
|
if row is None:
|
|
1108
1158
|
return None
|
|
@@ -1146,13 +1196,6 @@ class Watcher:
|
|
|
1146
1196
|
raise ValueError("the handed-over file holds no event")
|
|
1147
1197
|
return event
|
|
1148
1198
|
|
|
1149
|
-
def _drop_accepted(self, row: sqlite3.Row) -> None:
|
|
1150
|
-
try:
|
|
1151
|
-
if json.loads(row["event_json"]).get("spooled"):
|
|
1152
|
-
os.remove(self._accepted(row["run_id"]))
|
|
1153
|
-
except (OSError, ValueError):
|
|
1154
|
-
pass
|
|
1155
|
-
|
|
1156
1199
|
def _responded(self, run_id: str) -> bool:
|
|
1157
1200
|
return os.path.exists(os.path.join(self.config.out_dir, "responses", f"{run_id}.json"))
|
|
1158
1201
|
|
|
@@ -1255,43 +1298,85 @@ class Watcher:
|
|
|
1255
1298
|
|
|
1256
1299
|
def run_next(self) -> str | None:
|
|
1257
1300
|
"""Run the highest-priority ready change through the model, in this thread. Returns its run id, or None when nothing is ready or the hourly cap is reached. A run that itself fails (a model outage) is retried with backoff up to `_MAX_ATTEMPTS` times before the change is marked `failed`."""
|
|
1301
|
+
self._retry_settlements()
|
|
1258
1302
|
claimed = self._claim()
|
|
1259
1303
|
if claimed is None:
|
|
1260
1304
|
return None
|
|
1261
1305
|
row, event = claimed
|
|
1262
|
-
|
|
1306
|
+
if self._stop.is_set():
|
|
1307
|
+
self.state.unclaim(row["run_id"])
|
|
1308
|
+
return None
|
|
1309
|
+
self._settle(row, _run_model(event, *self._run_args(row["run_id"])))
|
|
1263
1310
|
return row["run_id"]
|
|
1264
1311
|
|
|
1265
|
-
def
|
|
1266
|
-
"""Record what a run produced: the verdict onto the sighting and the queue row done, or a retry with backoff, or after `_MAX_ATTEMPTS` the change buried as `failed`. `outcome` is `_outcome`'s tuple."""
|
|
1312
|
+
def _save_settlement(self, row: sqlite3.Row, outcome: tuple | None) -> bool:
|
|
1267
1313
|
run_id = row["run_id"]
|
|
1268
1314
|
try:
|
|
1269
1315
|
if outcome is not None:
|
|
1270
|
-
|
|
1271
|
-
if event.get("kind") != "release": # a release is no account's sighting
|
|
1272
|
-
self.actors.finalize(run_id, verdict=verdict, signal=signal, max_severity=top)
|
|
1273
|
-
self._mark(run_id, event, "done")
|
|
1274
|
-
self.state.complete(run_id)
|
|
1275
|
-
self._drop_accepted(row)
|
|
1276
|
-
elif row["attempts"] + 1 < _MAX_ATTEMPTS:
|
|
1277
|
-
delay = _backoff(row["attempts"] + 1)
|
|
1278
|
-
self.state.retry(run_id, row["attempts"] + 1, self._clock() + delay)
|
|
1279
|
-
self._mark(run_id, event, "queued")
|
|
1280
|
-
log.warning("run %s failed (attempt %d) — retrying in %s", run_id, row["attempts"] + 1, delay)
|
|
1316
|
+
self.state.checkpoint(run_id, outcome)
|
|
1281
1317
|
else:
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1318
|
+
attempts = row["attempts"] + 1
|
|
1319
|
+
delay = _backoff(attempts)
|
|
1320
|
+
self.state.settle_failure(run_id, attempts, self._clock() + delay)
|
|
1321
|
+
if attempts < _MAX_ATTEMPTS:
|
|
1322
|
+
log.warning("run %s failed (attempt %d), retrying in %s", run_id, attempts, delay)
|
|
1323
|
+
else:
|
|
1324
|
+
log.error("run %s failed %d times (use watch --requeue-failed to retry)", run_id, attempts)
|
|
1286
1325
|
except Exception:
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1326
|
+
self._unwritten.pop(run_id, None)
|
|
1327
|
+
self._unwritten[run_id] = (row, outcome)
|
|
1328
|
+
log.exception("could not save the outcome of %s; will retry bookkeeping", run_id)
|
|
1329
|
+
return False
|
|
1330
|
+
self._unwritten.pop(run_id, None)
|
|
1331
|
+
return True
|
|
1332
|
+
|
|
1333
|
+
def _finish_settlement(self, run_id: str, outcome: tuple, *, release: bool, spooled: bool) -> None:
|
|
1334
|
+
verdict, signal, top = outcome
|
|
1335
|
+
try:
|
|
1336
|
+
if not release:
|
|
1337
|
+
self.actors.finalize(run_id, verdict=verdict, signal=bool(signal), max_severity=top)
|
|
1338
|
+
self.state.finish(run_id)
|
|
1339
|
+
except Exception:
|
|
1340
|
+
log.exception("could not finalize %s; its outcome is saved for retry", run_id)
|
|
1341
|
+
else:
|
|
1342
|
+
if spooled:
|
|
1343
|
+
with contextlib.suppress(OSError):
|
|
1344
|
+
os.remove(self._accepted(run_id))
|
|
1345
|
+
|
|
1346
|
+
def _settle(self, row: sqlite3.Row, outcome: tuple | None) -> None:
|
|
1347
|
+
if self._save_settlement(row, outcome) and outcome is not None:
|
|
1348
|
+
event = json.loads(row["event_json"])
|
|
1349
|
+
self._finish_settlement(row["run_id"], outcome, release=event.get("kind") == "release",
|
|
1350
|
+
spooled=bool(event.get("spooled")))
|
|
1351
|
+
|
|
1352
|
+
def _retry_settlements(self) -> None:
|
|
1353
|
+
now = time.monotonic()
|
|
1354
|
+
if now < self._next_settlement:
|
|
1355
|
+
return
|
|
1356
|
+
self._next_settlement = now + _SETTLEMENT_RETRY_S
|
|
1357
|
+
for row, outcome in list(islice(self._unwritten.values(), _SETTLEMENT_BATCH)):
|
|
1358
|
+
if self._stop.is_set():
|
|
1359
|
+
return
|
|
1360
|
+
self._save_settlement(row, outcome)
|
|
1361
|
+
self._settlement_cursor = self._retry_saved_settlements(self._settlement_cursor)
|
|
1362
|
+
|
|
1363
|
+
def _retry_saved_settlements(self, after: int) -> int:
|
|
1364
|
+
rows = self.state.pending_settlements(self.config.paused, after)
|
|
1365
|
+
for row in rows:
|
|
1366
|
+
if self._stop.is_set():
|
|
1367
|
+
return after
|
|
1368
|
+
self._finish_settlement(row["run_id"], (row["verdict"], row["signal"], row["severity"]),
|
|
1369
|
+
release=bool(row["release"]), spooled=bool(row["spooled"]))
|
|
1370
|
+
after = row["seq"]
|
|
1371
|
+
return after if len(rows) == _SETTLEMENT_BATCH else 0
|
|
1372
|
+
|
|
1373
|
+
def _flush_successful_outcomes(self) -> None:
|
|
1374
|
+
"""Do not exit gracefully with a successful outcome held only in memory."""
|
|
1375
|
+
while pending := [(row, outcome) for row, outcome in self._unwritten.values() if outcome is not None]:
|
|
1376
|
+
for row, outcome in pending:
|
|
1377
|
+
self._settle(row, outcome)
|
|
1378
|
+
if any(outcome is not None for _, outcome in self._unwritten.values()):
|
|
1379
|
+
time.sleep(_SETTLEMENT_RETRY_S)
|
|
1295
1380
|
|
|
1296
1381
|
# ── several runs at once: one process each ──
|
|
1297
1382
|
|
|
@@ -1303,7 +1388,9 @@ class Watcher:
|
|
|
1303
1388
|
budget: int | None) -> tuple[int, bool]:
|
|
1304
1389
|
"""Fill the free processes with ready changes (at most `budget` more), then settle whatever finished within a second. Returns how many it started and whether the pool broke (a child died)."""
|
|
1305
1390
|
started = 0
|
|
1306
|
-
|
|
1391
|
+
self._retry_settlements()
|
|
1392
|
+
while (not self._stop.is_set() and len(inflight) < self.config.workers
|
|
1393
|
+
and (budget is None or started < budget)):
|
|
1307
1394
|
try:
|
|
1308
1395
|
claimed = self._claim()
|
|
1309
1396
|
except Exception:
|
|
@@ -1312,11 +1399,14 @@ class Watcher:
|
|
|
1312
1399
|
if claimed is None:
|
|
1313
1400
|
break
|
|
1314
1401
|
row, event = claimed
|
|
1402
|
+
if self._stop.is_set():
|
|
1403
|
+
self.state.unclaim(row["run_id"])
|
|
1404
|
+
break
|
|
1315
1405
|
try:
|
|
1316
1406
|
inflight[pool.submit(_run_model, event, *self._run_args(row["run_id"]))] = claimed
|
|
1317
1407
|
except Exception as exc: # noqa: BLE001 (BrokenProcessPool, or a spawn that failed: ENOMEM, EMFILE)
|
|
1318
1408
|
log.warning("could not start %s: %s", row["run_id"], exc)
|
|
1319
|
-
self._settle(row,
|
|
1409
|
+
self._settle(row, None)
|
|
1320
1410
|
return started, True # start over with a new pool, without waiting
|
|
1321
1411
|
started += 1
|
|
1322
1412
|
if not inflight:
|
|
@@ -1324,17 +1414,19 @@ class Watcher:
|
|
|
1324
1414
|
done, _ = wait(list(inflight), timeout=1, return_when=FIRST_COMPLETED)
|
|
1325
1415
|
broken = False
|
|
1326
1416
|
for fut in done:
|
|
1327
|
-
|
|
1417
|
+
if self._stop.is_set():
|
|
1418
|
+
break
|
|
1419
|
+
row, _ = inflight.pop(fut)
|
|
1328
1420
|
outcome, died = _result(fut, row["run_id"])
|
|
1329
1421
|
broken = broken or died
|
|
1330
|
-
self._settle(row,
|
|
1422
|
+
self._settle(row, outcome)
|
|
1331
1423
|
return started, broken
|
|
1332
1424
|
|
|
1333
1425
|
def _settle_all(self, inflight: dict[Future, tuple[sqlite3.Row, dict]]) -> None:
|
|
1334
1426
|
"""Settle every run still in flight from what its future holds: a finished one keeps its result, the rest count as a failed attempt (their process is gone or about to be)."""
|
|
1335
|
-
for fut, (row,
|
|
1427
|
+
for fut, (row, _) in list(inflight.items()):
|
|
1336
1428
|
inflight.pop(fut)
|
|
1337
|
-
self._settle(row,
|
|
1429
|
+
self._settle(row, _result(fut, row["run_id"])[0] if fut.done() else None)
|
|
1338
1430
|
|
|
1339
1431
|
def _run_pool(self, limit: int | None, *, serving: bool = False) -> int:
|
|
1340
1432
|
"""Run ready changes `workers` at a time until none is left and none is running (`drain`, at most `limit`), or, `serving`, until `stop()`. Returns how many it started. A stop or an interrupt leaves the runs it cuts off claimed for `recover()`; an error settles them, so a long-lived watcher strands nothing."""
|
|
@@ -1348,6 +1440,8 @@ class Watcher:
|
|
|
1348
1440
|
budget = None if limit is None else limit - ran
|
|
1349
1441
|
started, broken = self._pump(pool, inflight, budget)
|
|
1350
1442
|
ran += started
|
|
1443
|
+
if self._stop.is_set():
|
|
1444
|
+
break
|
|
1351
1445
|
if broken: # every run in a broken pool fails; settle and start over
|
|
1352
1446
|
self._settle_all(inflight)
|
|
1353
1447
|
_terminate(pool)
|
|
@@ -1356,7 +1450,7 @@ class Watcher:
|
|
|
1356
1450
|
if not inflight:
|
|
1357
1451
|
if not serving:
|
|
1358
1452
|
break
|
|
1359
|
-
self._wake.wait(timeout=
|
|
1453
|
+
self._wake.wait(timeout=_SETTLEMENT_RETRY_S)
|
|
1360
1454
|
self._wake.clear()
|
|
1361
1455
|
except Exception:
|
|
1362
1456
|
failed = True
|
|
@@ -1366,17 +1460,31 @@ class Watcher:
|
|
|
1366
1460
|
# An error settles what it cut off; a stop or an interrupt (Ctrl-C) leaves it claimed for `recover()`.
|
|
1367
1461
|
if failed and inflight and not self._stop.is_set():
|
|
1368
1462
|
self._settle_all(inflight)
|
|
1463
|
+
else:
|
|
1464
|
+
for fut, (row, _) in inflight.items():
|
|
1465
|
+
if fut.done() and not fut.cancelled() and fut.exception() is None:
|
|
1466
|
+
outcome = fut.result()
|
|
1467
|
+
if outcome is not None:
|
|
1468
|
+
self._settle(row, outcome)
|
|
1369
1469
|
return ran
|
|
1370
1470
|
|
|
1371
1471
|
def drain(self, limit: int | None = None) -> int:
|
|
1372
1472
|
"""Run ready changes until none is left (or `limit`, or the hourly cap). Returns how many ran."""
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1473
|
+
try:
|
|
1474
|
+
if not self._stop.is_set():
|
|
1475
|
+
cursor = self._retry_saved_settlements(0)
|
|
1476
|
+
while cursor and not self._stop.is_set():
|
|
1477
|
+
cursor = self._retry_saved_settlements(cursor)
|
|
1478
|
+
self._next_settlement = time.monotonic() + _SETTLEMENT_RETRY_S
|
|
1479
|
+
if self.config.workers > 1:
|
|
1480
|
+
return self._run_pool(limit)
|
|
1481
|
+
self.import_hand_overs()
|
|
1482
|
+
ran = 0
|
|
1483
|
+
while (limit is None or ran < limit) and self.run_next() is not None:
|
|
1484
|
+
ran += 1
|
|
1485
|
+
return ran
|
|
1486
|
+
finally:
|
|
1487
|
+
self._flush_successful_outcomes()
|
|
1380
1488
|
|
|
1381
1489
|
# ── serving ────────────────────────────────────────────────────────────────────────────────────
|
|
1382
1490
|
|
|
@@ -1414,7 +1522,8 @@ class Watcher:
|
|
|
1414
1522
|
finally:
|
|
1415
1523
|
self.stop()
|
|
1416
1524
|
if worker.is_alive():
|
|
1417
|
-
worker.join(
|
|
1525
|
+
worker.join()
|
|
1526
|
+
self._flush_successful_outcomes()
|
|
1418
1527
|
|
|
1419
1528
|
def _work_loop(self) -> None:
|
|
1420
1529
|
while not self._stop.is_set():
|
|
@@ -1425,7 +1534,7 @@ class Watcher:
|
|
|
1425
1534
|
self._stop.wait(5)
|
|
1426
1535
|
continue
|
|
1427
1536
|
if ran is None:
|
|
1428
|
-
self._wake.wait(timeout=
|
|
1537
|
+
self._wake.wait(timeout=_SETTLEMENT_RETRY_S)
|
|
1429
1538
|
self._wake.clear()
|
|
1430
1539
|
|
|
1431
1540
|
def _pool_loop(self) -> None:
|
|
@@ -31,6 +31,8 @@ poll (ETag) → ingest → snapshot archive → actor store → screen → queue
|
|
|
31
31
|
|
|
32
32
|
**Nothing is dropped without a trace.** A listing deeper than one pass reads (2000 changes) is reported as truncated. A change that cannot be ingested is retried with exponential backoff and parked as `error` after six failures; a rate-limit refusal is waited out and is not a failure. A model run that fails is retried up to ten times over about four hours and then kept as `failed`, and so is a run whose start could not be recorded, which backs off instead of coming first again; stop the watcher and run `watch --requeue-failed` to bring it back. An early alert the SIEM refused is sent again on later polls (twenty tries). One `watch` may use a state directory at a time.
|
|
33
33
|
|
|
34
|
+
On SIGINT or SIGTERM, `watch` stops taking new jobs and waits for its worker before closing the databases and releasing the state lock. With one worker, the current model run can finish. With a process pool, interrupted jobs stay in the queue for recovery on restart, subject to the attempt limit. Completed outcomes are saved before the actor store is updated. If that update fails, the watcher retries it during service or on the next model-enabled run without invoking the model or sending the final alert again. Paused repositories hold these retries. If the watcher database is unavailable while an outcome is still in memory, graceful shutdown waits until it can save it.
|
|
35
|
+
|
|
34
36
|
**The first copy is kept.** Every capture, with the raw API responses beside the derived event, goes into a content-addressed archive before anything else happens, so `archive verify` detects a changed or missing object. The index is append-only but not hash-chained, and nothing prunes the archive, the store or the queue's events, so size them yourself. An edit is a new revision (`…-r1`) with its own trace, never an overwrite, and the hits an earlier revision raised ride into the next one, so removing a payload cannot remove the evidence. A floor-level hit that a later revision no longer shows is `evidence-scrubbed` (`high`), unless the file that held it is only hidden: GitHub withheld its patch or cut the file list. That is `evidence-unseen` (`medium`), and the earlier hit still rides along. Changes are re-examined after 15 minutes, 1 hour, 6 hours and 24 hours to see a deleted fork, account or PR (`--recheck-hours` can shorten that schedule, not extend it).
|
|
35
37
|
|
|
36
38
|
**The store remembers the account.** It keys accounts on GitHub's numeric id, so a rename does not reset the record. Cross-event facts (the same account in several repositories within a day, a burst from a new account, a payload host a flagged change already used) reach the signal through the ordinary provenance path.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "diff-sentry"
|
|
3
|
-
version = "0.18.
|
|
3
|
+
version = "0.18.1"
|
|
4
4
|
description = "Catch malicious pull requests before they merge: scan a diff for supply-chain attack patterns with deterministic evidence a model cannot suppress."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|