Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

fix(watchlist): close the review findings on the research watch policy

Rufuse377c602404c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 189762df..5793b6f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -76,6 +76,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
ranking and is shown to the review as evidence.
### Changed
+- The research routing pass no longer carries the watchlist write tools
+ (`add_watchlist_entry`, `tune_watchlist_entry`, `remove_watchlist_entry`):
+ every watch a research run creates goes through the watchlist policy.
+ `tune_watchlist_entry` refuses `mode` / `enabled` changes on a pending
+ suggestion, URL targets are SSRF-checked at insert time for every kind,
+ and deleting a watch now removes its signal history in the same
+ transaction (the foreign key previously made any polled watch
+ undeletable).
- Watchlist rows carry an `origin` (`manual` | `executive` | `research` |
`research_proposed`); the research skip-if-unchanged fingerprint hashes
only enabled, active rows so approving or declining a suggestion never
diff --git a/packages/core/openexecutive/api/routes/watchlist.py b/packages/core/openexecutive/api/routes/watchlist.py
index 98bcb9c8..3c7a6638 100644
--- a/packages/core/openexecutive/api/routes/watchlist.py
+++ b/packages/core/openexecutive/api/routes/watchlist.py
@@ -24,12 +24,11 @@ from openexecutive.monitoring.models import (
DECLINE_KIND_EXPLICIT,
DECLINE_REASON_NOT_RELEVANT,
DECLINE_REASON_TOO_NOISY,
+ EXPLICIT_DECLINE_REASONS,
MODE_ACTIVE,
MODE_DRY_RUN,
- ORIGIN_RESEARCH,
ORIGIN_RESEARCH_PROPOSED,
RESEARCH_ORIGINS,
- VALID_DECLINE_REASONS,
WatchlistItem,
is_valid_cadence,
is_valid_mode,
@@ -401,7 +400,7 @@ def delete_watchlist_entry(slug: str, reason: str | None = None) -> Response:
if item is None:
raise HTTPException(status_code=404, detail=f"Watchlist entry {slug!r} not found")
assert item.id is not None
- if reason is not None and reason not in VALID_DECLINE_REASONS:
+ if reason is not None and reason not in EXPLICIT_DECLINE_REASONS:
raise HTTPException(status_code=400, detail=f"unknown reason {reason!r}")
try:
removed = ms.delete_watchlist_item(item.id)
@@ -477,24 +476,25 @@ def decline_watchlist_suggestion(slug: str, body: DeclineBody | None = None) ->
from openexecutive.monitoring.research import watch_policy
reason = (body.reason if body else DECLINE_REASON_NOT_RELEVANT)
- if reason not in VALID_DECLINE_REASONS:
+ if reason not in EXPLICIT_DECLINE_REASONS:
raise HTTPException(status_code=400, detail=f"unknown reason {reason!r}")
item = _pending_suggestion_or_409(slug)
assert item.id is not None
+ # Both remedies are compare-and-act on "still pending", so a concurrent
+ # approve (or the sweep) cannot be undone by this decline.
if reason == DECLINE_REASON_TOO_NOISY:
- ms.update_watchlist_fields(item.id, {
- "mode": MODE_ACTIVE, "origin": ORIGIN_RESEARCH,
- "severity_floor": "high", "enabled": 1,
- })
+ if not ms.quiet_pending_suggestion(item.id):
+ raise HTTPException(status_code=409, detail=f"{slug!r} is not a pending research suggestion")
watch_policy.record_outcome_for(item, watch_policy.OUTCOME_APPROVED)
result = "kept_quiet"
else:
+ if not ms.delete_pending_suggestion(item.id):
+ raise HTTPException(status_code=409, detail=f"{slug!r} is not a pending research suggestion")
try:
_record_decline(item, reason)
except Exception:
logger.exception("watchlist.decline: decline record failed slug=%s", slug)
- ms.delete_watchlist_item(item.id)
result = "removed"
audit_log(
watch_policy.EVENT_SUGGESTION_DECLINED,
diff --git a/packages/core/openexecutive/architecture/architecture-facts.yaml b/packages/core/openexecutive/architecture/architecture-facts.yaml
index 5ace2763..9873a2c6 100644
--- a/packages/core/openexecutive/architecture/architecture-facts.yaml
+++ b/packages/core/openexecutive/architecture/architecture-facts.yaml
@@ -1375,8 +1375,10 @@ external_monitoring:
eur-lex), +1 finding confidence high, +1 verification confirmed, +1
cross-specialist consensus, ±1 policy history for (signal_type,
grounding_kind) at >= 5 samples (>= 0.7 / <= 0.3 approval rate).
- - direct add at score >= 4 with the mandatory match; model `certainty`
- can only downgrade; `query` never direct; above WATCHLIST_MAX_ENABLED
+ - direct add at score >= 4 with the mandatory match AND a strong kind
+ (company / competitor / vendor / ticker — initiative- or
+ priority-grounded proposals are suggestions at most); model
+ `certainty` can only downgrade; `query` never direct; above WATCHLIST_MAX_ENABLED
(40) enabled rows every add is a suggestion; WATCHLIST_RESEARCH_MAX_DIRECT_ADDS
(2) and WATCHLIST_RESEARCH_MAX_PROPOSALS (2) per run.
- quiet defaults on every research row (model cannot loosen): cadence
@@ -1388,12 +1390,23 @@ external_monitoring:
grounding_kind, specialist, score, reasons, source_url) in
config_json._policy. Reject: invalid target, same site + signal_type
already watched, declined target, spent budget.
- - declines (`watchlist_declines`, keyed by normalized target): explicit
- (Decline button, "Stop watching…", remove_watchlist_entry / DELETE on a
- research-origin row) is permanent; expired_unreviewed retries once
- after 90 days. Enforced in the propose_watch handler, rendered to the
- model as DECLINED. Decline reasons: not_relevant (blacklist entity),
- wrong_source (blacklist target), too_noisy (keep live at floor=high).
+ - declines (`watchlist_declines`, keyed by normalized target — https
+ forced, www. dropped, host/path lower-cased, query/fragment/trailing
+ slash removed): explicit (Decline button, "Stop watching…",
+ remove_watchlist_entry / DELETE on a research-origin row) is permanent;
+ expired_unreviewed (sweep expiry, and auto-disable) retries once after
+ 90 days. Enforced in the propose_watch handler BEFORE any fetch — by
+ target, and by entity for not_relevant declines (token match) —
+ and rendered to the model as DECLINED. Decline reasons: not_relevant
+ (blacklist entity), wrong_source (blacklist target), too_noisy (keep
+ live at floor=high). Tool-supplied reasons outside the explicit set
+ fall back to not_relevant.
+ - isolation: the routing/synthesis pass has NO watchlist write tools
+ (add/tune/remove are in _SYNTHESIS_EXCLUDED_TOOLS), so every watch a
+ research run creates goes through the policy; tune_watchlist_entry
+ refuses mode/enabled on a pending suggestion (only approve/decline
+ move it); URL-typed targets pass validate_target_url at insert time;
+ approve / decline / expiry are compare-and-act on "still pending".
- outcomes (`watchlist_policy_outcomes`: approved / declined / expired /
auto_disabled by signal_type, grounding_kind, specialist) feed the
history term and are rendered to the model as HOW PAST PROPOSALS TURNED OUT.
diff --git a/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json b/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json
index 5611fa7f..2ccf8ca5 100644
--- a/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json
+++ b/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json
@@ -1,7 +1,7 @@
{
"section_id": "external_monitoring",
"title": "External Monitoring",
- "markdown": "`openexecutive.monitoring` watches the outside world on a heartbeat and turns detected changes into briefing proposals via the same alert pipeline that handles inbound email and Slack.\n\nThe `external_monitor_scan` heartbeat (`__internal__` channel, default every 5 min) walks `list_watchlist(enabled_only=True)`, skipping rows fresher than their per-source cadence floor. For each due row it fires a read-only source adapter resolved from `_REGISTRY` by `signal_type`:\n\n- `vendor_status` — Statuspage Atom/RSS incident feeds (AWS, Stripe, GitHub, …). Reads each incident's current status out of the entry body, parses `<updated>` into `published_at`, and keys its dedup on `(entry id, <updated>)`; a **seeding** source (see below).\n- `rss` — generic Atom/RSS via feedparser (changelogs, layoffs.fyi, filings). Parses each entry's `<pubDate>`/`<updated>` into `published_at`; a **seeding** source (see below).\n- `stock` — Yahoo Finance chart endpoint; fires on `abs_change_pct_gte` moves.\n- `page_watch` — change-detection on a feed-less page. Fetches via the keyless httpx fetcher by default, or via xcrawl's scrape API when the row carries `config.fetch = \"xcrawl\"` — so JS-rendered / bot-blocked pages that publish no RSS (most modern news / marketing sites) are still monitorable.\n- `edgar` and the BILLED `query` web-search adapter.\n\nEach `Signal` is trigger-filtered, severity-clamped to the row's `[floor, ceiling]`, and INSERTed into `external_signals` where `UNIQUE(dedup_key)` drops replays. Survivors pass a suppression cascade (`baseline` → `stale` → `dry_run` → `below_floor` → capture-time relevance enrichment → promote), then `promote_signal_to_alert` builds an `AlertEvent` handed to `alerts.pipeline.schedule_evaluation` and surfaced as a `/today` proposal.\n\nEvery signal carries two timestamps that are never conflated: `captured_at` (when the monitor first saw it) and `published_at` (when the upstream says it happened — RSS `<pubDate>`, EDGAR filing date; null for `stock`, `page_watch`, `query`). Two freshness gates run first in the cascade, before anything that costs an LLM call. **Baseline:** the first poll that returns entries for a row whose adapter declares `seed_on_first_poll` (`rss`, `edgar`) records every entry already in the feed — trigger misses included, so the first entry that ever matches a keyword is news and a later, wider trigger can't resurface old ones — as `suppressed_baseline`, promotes nothing, and stamps `watchlist.baselined_at`, so a new watch reports what changes from now on instead of replaying the feed's back-catalogue (the same idea as `page_watch`'s first-observation baseline). It is keyed on `baselined_at` rather than `last_polled_at`, so a failed first fetch can't forfeit it; the claim and the recording are one transaction (a compare-and-swap on the stamp plus the rows, all-or-nothing), so of two overlapping scans exactly one records the back-catalogue and a failure part-way leaves nothing behind to replay; the other scan promotes only entries dated after that stamp (undated entries count as baseline, since the feed controls the date; entries dated more than a few minutes past its own clock are deferred rather than recorded); and baseline rows don't count against `max_signals_per_scan`, so a large feed can't be half-baselined. `vendor_status` used to sit outside both gates for a structural reason: its dedup key was `sha256(slug, entry id)`, and an incident's id never changes across its updates, so any suppressed insert muted that incident for good. Keying on `(entry id, <updated>)` instead (issue #90) makes a suppression cost one *state* of an incident rather than the incident, so both gates now apply to vendor feeds too — and an incident moving Investigating → Resolved mints a new key and surfaces, while re-polling an unchanged feed still dedups. Because a history feed's archive is mostly incidents resolved months ago, the adapter also carves live news out of its own baseline: it reads each incident's current status from the entry body (Statuspage renders the newest update first as `<strong>Resolved</strong>` / `Investigating` / `Monitoring` / … — the body is parsed by a real HTML parser, off the event loop, and the reading is deliberately asymmetric: any sign that the incident is over closes it, wherever it appears, while only a marked-up label can say it is still open. Working out which update is newest turned out to be something tag soup cannot be trusted to express, and every attempt reported a long-resolved incident as live) and exempts the ones still OPEN via the optional `promote_on_baseline` hook, so a watch added during an outage reports that outage on its first poll while the resolved archive is recorded as `suppressed_baseline`. An unrecognised status counts as closed — a vendor changing feed format must not be able to promote its whole archive at HIGH, and nothing is lost, since the next `<updated>` bump surfaces normally. An exempt entry must still pass the row's trigger filter (one that misses stays in the baseline, so widening a trigger later cannot resurface it) and is still judged by the stale gate below: the exemption buys an entry past the baseline, never past its own timestamp, because \"this is live\" is a reading of vendor-controlled markup and an entry the feed dates outside the age window is not news whatever that reading says. **Stale:** a signal whose `published_at` is older than `EXTERNAL_MONITOR_MAX_SIGNAL_AGE_DAYS` (default 7; `0` disables) at capture time is recorded as `suppressed_stale` and never promoted — a January article a feed resurfaces in September is not September news. An entry dated more than `EXTERNAL_MONITOR_MAX_FUTURE_SKEW_HOURS` ahead (default 24; `0` disables; `config_json.max_future_skew_hours` overrides it per row for calendar or maintenance feeds that legitimately date entries ahead) is deferred instead: skipped for the tick and not recorded (recording would burn its dedup key and let a feed mute an announcement for good by post-dating it), with one aggregated `external_signal_deferred` audit row per poll — carrying each held-back entry's summary and link, and emitted even if the poll later raises — then judged normally once the date passes. Inside the window, the alert body handed to triage carries `Published:` and `Discovered:` lines so the item is judged on when it happened. Adapters prefer a plausible date key over one more than a day in the future (and keep the future value when every key is implausible, so the pipeline defers it rather than waving an undated entry through), and the alert body collapses whitespace in the summary so no source can forge its own labeled body line.\n\nThe `query` adapter is a special case: it emits every web hit flat-LOW (it can't judge materiality per-hit), so for query signals enrichment runs BEFORE the floor gate and `_grade_query_severity` regrades from the relevance read (≥0.8 HIGH, ≥0.5 MEDIUM, else LOW). Without this, any query watch item with a `severity_floor` above LOW would suppress every hit — which is what left the Monitoring section empty even while standing queries were returning material findings.\n\nWhich lane a proposal lands in is decided by `briefing.ranking.categorize`: an unrouted, low/medium signal from a monitoring source (`stock`, `vendor_status`, `rss`, `query`, `edgar`, `page_watch`, or any `external:*` topic tag) is `monitoring` (the collapsible Monitoring section); a routed or high/urgent one is `action` (the \"Needs you\" queue). The triage prompt's External Signals rule covers all six source kinds so it trusts the source and emits the `external:*` tags that drive this split.\n\nThe watchlist is editable from chat (`add_watchlist_entry`, `tune_watchlist_entry`) and HTTP (`/watchlist`); the `executive_research` workflow proposes what to watch through a deterministic policy (next section). Because that workflow is LLM-driven and historically proposed feed URLs it never verified (most were dead — 404 / 403 / not-actually-a-feed), every `rss` target is validated at insert time (`monitoring.target_validation`): a URL that fetches and parses as a feed is kept; a public page that isn't a feed is converted to a scrape-backed `page_watch` when xcrawl can read it, otherwise rejected (HTTP 422 / tool error); SSRF-blocked or unparseable URLs are rejected outright and never handed to xcrawl. Non-`rss` types insert unchanged with no network I/O.\n\n### One watch, one card — and dismissals teach the watch\n\n`promote_signal_to_alert` stamps the `AlertEvent` with `dedup_hint=\"watch:<slug>\"`, which `alerts.pipeline` uses as the *alert* dedup key. A repeat from the same watch coalesces into the open card (`occurrence_count`, `last_seen_at`, severity max) rather than minting another, and re-pings only when severity rose into high/urgent — so a ticker that stays over its threshold or an incident that keeps updating no longer produces a new \"Needs you\" item every day. The signal-level `dedup_key` (stock's UTC-date bucket, vendor_status's `<updated>`) is untouched, so every observation still lands in `external_signals`. Dismissing a watch-sourced alert calls `store.record_dismissal(slug)` (`dismiss_count += 1`, `trust_score = max(0.2, trust × 0.8)`); approving calls `record_confirmation` (+0.05). `trust_score` discounts the briefing ranking and is shown to the Executive's alert review as evidence, alongside the newer signals for that watch (a \"Resolved\" incident state, a reversed move) that let it close the card with evidence.\n\n### What the research pass may put on the watchlist\n\nEvery watchlist row carries an `origin`: `manual` (the principal, via UI/API), `executive` (the chat tool acting on a request), `research` (the research pass added it on its own) or `research_proposed` (a pending suggestion). The `executive_research` workflow's watchlist pass no longer calls `add_watchlist_entry`; its only tool is `propose_watch` (slug, signal_type, target, `grounding_entity`, `rationale`, `certainty`), and `monitoring.research.watch_policy` decides what happens to each proposal from company data, not from the model's confidence in itself:\n\n- **Direct add** — the row lands live, `origin=research`, with quiet defaults the model cannot loosen (daily cadence — hourly for `vendor_status`, weekly for `page_watch`/`query` — `severity_floor=medium`, a keyword trigger built from the grounding entity + material-event words + the current-year priorities for feeds, `abs_change_pct_gte=5` for stocks). Requires the `grounding_entity` to match the **grounding vocabulary** (the company name, `competitive_landscape.primary_competitors`, the profile's `vendors` and `tickers`, active initiative titles, current-year priorities) *and* a score ≥ 4 on a fixed ledger: +2 entity in company data (mandatory), +1 entity already watched under another source, +1 target is the entity's own source (its ticker, its domain, or a primary-source host such as sec.gov), +1 finding confidence high, +1 verification confirmed, +1 cross-specialist consensus, ±1 from the policy's own approval history for that `(signal_type, grounding kind)` once it has ≥5 samples. The model's `certainty` can only downgrade a direct add to a suggestion; a `query` watch is always a suggestion; above `WATCHLIST_MAX_ENABLED` (40) enabled watches every add becomes a suggestion. At most `WATCHLIST_RESEARCH_MAX_DIRECT_ADDS` (2) per run.\n- **Suggestion** — anything that validates but misses the bar is inserted in `dry_run` (polls and records signals, never alerts) with `origin=research_proposed` and the rationale in `notes`, at most `WATCHLIST_RESEARCH_MAX_PROPOSALS` (2) per run. `/watchlist` shows them in a \"Suggested by the Executive\" section with Approve (`POST /watchlist/{slug}/approve` → `active`, `origin=research`) and Decline (`POST /watchlist/{slug}/decline` with a reason: `not_relevant` blacklists the entity, `wrong_source` blacklists only this target, `too_noisy` keeps it live with `severity_floor=high`). A suggestion nobody reviews within `WATCHLIST_PROPOSAL_TTL_DAYS` (14) is removed. The morning brief mentions the pending count in one line; a `watchlist_suggestions` alert nudges only once ≥3 suggestions have waited ≥7 days.\n- **Reject** — an invalid target, a second watch on the same site + signal type, a declined target, or a spent budget. Every decision is audited (`watchlist_research_added` / `_suggested` / `_rejected`) with the score and reasons; the stamp also lives in the row's `config_json._policy` so approve/decline/auto-disable can attribute the outcome.\n\n**Declines are remembered and enforced.** `watchlist_declines` is keyed by the normalized target (upper-cased ticker; lower-cased URL without fragment or trailing slash). An explicit decline — the Decline button, \"Stop watching…\" on a research-added card, `remove_watchlist_entry` or `DELETE /watchlist/{slug}` on a research-origin row — is permanent; an unreviewed expiry may be re-proposed once after 90 days. The `propose_watch` handler refuses a declined target before the model sees a result, so a new slug cannot route around a decline; the list is also rendered to the model as DECLINED.\n\n**The policy learns from outcomes.** Approve, decline, expiry and auto-disable write `watchlist_policy_outcomes` rows keyed by `(signal_type, grounding kind, specialist)`; the pass renders the tallies (\"stock watches grounded in a competitor: 4 approved / 1 declined\"; \"proposals from cso: …\") and the score ledger reads them. The research turn also shows each existing watch's `origin`, `fired_count`, `dismiss_count` and `trust_score`.\n\n**Research watches retire themselves.** The scheduler's 15-minute sweep (`watch_policy.sweep`, alongside the alert expiry sweep) disables a `research`-origin watch — audited as `watchlist_auto_disabled`, re-enable from `/watchlist` — when it fired ≥5 alerts of which ≥2 were dismissed and trust ≤ 0.5, when a feed/page/status watch produced no signal in 30 days, or after 3 consecutive poll failures. Direct adds and auto-disables appear in the brief's \"handled overnight\" block as `watching` / `stopped_watching`. The research skip-if-unchanged fingerprint hashes only enabled, `active` rows, so approving or declining a suggestion never triggers a fresh 7-specialist run.\n\n### Invariants\n\n- Adapters are read-only — they never write upstream and never auto-execute.\n- Every `Signal` carries a deterministic `dedup_key` and a mandatory `provenance_url`.\n- Fetches are SSRF-guarded and bounded by `external_monitor_max_fetch_bytes`; xcrawl scrape (off by default, gated by `XCRAWL_ENABLED` + `XCRAWL_API_KEY`) is the one path that delegates the fetch to an external API.\n- Suppressed signals are still persisted so audits show the full picture.\n- A repeat from the same watch never becomes a second open card: the alert-level `watch:<slug>` key coalesces it, and only a severity escalation re-dispatches.\n- The research model never writes the watchlist: it proposes, deterministic policy adds (only when grounded in company data) or suggests, and a target the principal declined is refused at the handler.",
+ "markdown": "`openexecutive.monitoring` watches the outside world on a heartbeat and turns detected changes into briefing proposals via the same alert pipeline that handles inbound email and Slack.\n\nThe `external_monitor_scan` heartbeat (`__internal__` channel, default every 5 min) walks `list_watchlist(enabled_only=True)`, skipping rows fresher than their per-source cadence floor. For each due row it fires a read-only source adapter resolved from `_REGISTRY` by `signal_type`:\n\n- `vendor_status` — Statuspage Atom/RSS incident feeds (AWS, Stripe, GitHub, …). Reads each incident's current status out of the entry body, parses `<updated>` into `published_at`, and keys its dedup on `(entry id, <updated>)`; a **seeding** source (see below).\n- `rss` — generic Atom/RSS via feedparser (changelogs, layoffs.fyi, filings). Parses each entry's `<pubDate>`/`<updated>` into `published_at`; a **seeding** source (see below).\n- `stock` — Yahoo Finance chart endpoint; fires on `abs_change_pct_gte` moves.\n- `page_watch` — change-detection on a feed-less page. Fetches via the keyless httpx fetcher by default, or via xcrawl's scrape API when the row carries `config.fetch = \"xcrawl\"` — so JS-rendered / bot-blocked pages that publish no RSS (most modern news / marketing sites) are still monitorable.\n- `edgar` and the BILLED `query` web-search adapter.\n\nEach `Signal` is trigger-filtered, severity-clamped to the row's `[floor, ceiling]`, and INSERTed into `external_signals` where `UNIQUE(dedup_key)` drops replays. Survivors pass a suppression cascade (`baseline` → `stale` → `dry_run` → `below_floor` → capture-time relevance enrichment → promote), then `promote_signal_to_alert` builds an `AlertEvent` handed to `alerts.pipeline.schedule_evaluation` and surfaced as a `/today` proposal.\n\nEvery signal carries two timestamps that are never conflated: `captured_at` (when the monitor first saw it) and `published_at` (when the upstream says it happened — RSS `<pubDate>`, EDGAR filing date; null for `stock`, `page_watch`, `query`). Two freshness gates run first in the cascade, before anything that costs an LLM call. **Baseline:** the first poll that returns entries for a row whose adapter declares `seed_on_first_poll` (`rss`, `edgar`) records every entry already in the feed — trigger misses included, so the first entry that ever matches a keyword is news and a later, wider trigger can't resurface old ones — as `suppressed_baseline`, promotes nothing, and stamps `watchlist.baselined_at`, so a new watch reports what changes from now on instead of replaying the feed's back-catalogue (the same idea as `page_watch`'s first-observation baseline). It is keyed on `baselined_at` rather than `last_polled_at`, so a failed first fetch can't forfeit it; the claim and the recording are one transaction (a compare-and-swap on the stamp plus the rows, all-or-nothing), so of two overlapping scans exactly one records the back-catalogue and a failure part-way leaves nothing behind to replay; the other scan promotes only entries dated after that stamp (undated entries count as baseline, since the feed controls the date; entries dated more than a few minutes past its own clock are deferred rather than recorded); and baseline rows don't count against `max_signals_per_scan`, so a large feed can't be half-baselined. `vendor_status` used to sit outside both gates for a structural reason: its dedup key was `sha256(slug, entry id)`, and an incident's id never changes across its updates, so any suppressed insert muted that incident for good. Keying on `(entry id, <updated>)` instead (issue #90) makes a suppression cost one *state* of an incident rather than the incident, so both gates now apply to vendor feeds too — and an incident moving Investigating → Resolved mints a new key and surfaces, while re-polling an unchanged feed still dedups. Because a history feed's archive is mostly incidents resolved months ago, the adapter also carves live news out of its own baseline: it reads each incident's current status from the entry body (Statuspage renders the newest update first as `<strong>Resolved</strong>` / `Investigating` / `Monitoring` / … — the body is parsed by a real HTML parser, off the event loop, and the reading is deliberately asymmetric: any sign that the incident is over closes it, wherever it appears, while only a marked-up label can say it is still open. Working out which update is newest turned out to be something tag soup cannot be trusted to express, and every attempt reported a long-resolved incident as live) and exempts the ones still OPEN via the optional `promote_on_baseline` hook, so a watch added during an outage reports that outage on its first poll while the resolved archive is recorded as `suppressed_baseline`. An unrecognised status counts as closed — a vendor changing feed format must not be able to promote its whole archive at HIGH, and nothing is lost, since the next `<updated>` bump surfaces normally. An exempt entry must still pass the row's trigger filter (one that misses stays in the baseline, so widening a trigger later cannot resurface it) and is still judged by the stale gate below: the exemption buys an entry past the baseline, never past its own timestamp, because \"this is live\" is a reading of vendor-controlled markup and an entry the feed dates outside the age window is not news whatever that reading says. **Stale:** a signal whose `published_at` is older than `EXTERNAL_MONITOR_MAX_SIGNAL_AGE_DAYS` (default 7; `0` disables) at capture time is recorded as `suppressed_stale` and never promoted — a January article a feed resurfaces in September is not September news. An entry dated more than `EXTERNAL_MONITOR_MAX_FUTURE_SKEW_HOURS` ahead (default 24; `0` disables; `config_json.max_future_skew_hours` overrides it per row for calendar or maintenance feeds that legitimately date entries ahead) is deferred instead: skipped for the tick and not recorded (recording would burn its dedup key and let a feed mute an announcement for good by post-dating it), with one aggregated `external_signal_deferred` audit row per poll — carrying each held-back entry's summary and link, and emitted even if the poll later raises — then judged normally once the date passes. Inside the window, the alert body handed to triage carries `Published:` and `Discovered:` lines so the item is judged on when it happened. Adapters prefer a plausible date key over one more than a day in the future (and keep the future value when every key is implausible, so the pipeline defers it rather than waving an undated entry through), and the alert body collapses whitespace in the summary so no source can forge its own labeled body line.\n\nThe `query` adapter is a special case: it emits every web hit flat-LOW (it can't judge materiality per-hit), so for query signals enrichment runs BEFORE the floor gate and `_grade_query_severity` regrades from the relevance read (≥0.8 HIGH, ≥0.5 MEDIUM, else LOW). Without this, any query watch item with a `severity_floor` above LOW would suppress every hit — which is what left the Monitoring section empty even while standing queries were returning material findings.\n\nWhich lane a proposal lands in is decided by `briefing.ranking.categorize`: an unrouted, low/medium signal from a monitoring source (`stock`, `vendor_status`, `rss`, `query`, `edgar`, `page_watch`, or any `external:*` topic tag) is `monitoring` (the collapsible Monitoring section); a routed or high/urgent one is `action` (the \"Needs you\" queue). The triage prompt's External Signals rule covers all six source kinds so it trusts the source and emits the `external:*` tags that drive this split.\n\nThe watchlist is editable from chat (`add_watchlist_entry`, `tune_watchlist_entry`) and HTTP (`/watchlist`); the `executive_research` workflow proposes what to watch through a deterministic policy (next section). Because that workflow is LLM-driven and historically proposed feed URLs it never verified (most were dead — 404 / 403 / not-actually-a-feed), every `rss` target is validated at insert time (`monitoring.target_validation`): a URL that fetches and parses as a feed is kept; a public page that isn't a feed is converted to a scrape-backed `page_watch` when xcrawl can read it, otherwise rejected (HTTP 422 / tool error); SSRF-blocked or unparseable URLs are rejected outright and never handed to xcrawl. Non-`rss` types insert unchanged with no network I/O.\n\n### One watch, one card — and dismissals teach the watch\n\n`promote_signal_to_alert` stamps the `AlertEvent` with `dedup_hint=\"watch:<slug>\"`, which `alerts.pipeline` uses as the *alert* dedup key. A repeat from the same watch coalesces into the open card (`occurrence_count`, `last_seen_at`, severity max) rather than minting another, and re-pings only when severity rose into high/urgent — so a ticker that stays over its threshold or an incident that keeps updating no longer produces a new \"Needs you\" item every day. The signal-level `dedup_key` (stock's UTC-date bucket, vendor_status's `<updated>`) is untouched, so every observation still lands in `external_signals`. Dismissing a watch-sourced alert calls `store.record_dismissal(slug)` (`dismiss_count += 1`, `trust_score = max(0.2, trust × 0.8)`); approving calls `record_confirmation` (+0.05). `trust_score` discounts the briefing ranking and is shown to the Executive's alert review as evidence, alongside the newer signals for that watch (a \"Resolved\" incident state, a reversed move) that let it close the card with evidence.\n\n### What the research pass may put on the watchlist\n\nEvery watchlist row carries an `origin`: `manual` (the principal, via UI/API), `executive` (the chat tool acting on a request), `research` (the research pass added it on its own) or `research_proposed` (a pending suggestion). The `executive_research` workflow's watchlist pass no longer calls `add_watchlist_entry`; its only tool is `propose_watch` (slug, signal_type, target, `grounding_entity`, `rationale`, `certainty`), and `monitoring.research.watch_policy` decides what happens to each proposal from company data, not from the model's confidence in itself:\n\n- **Direct add** — the row lands live, `origin=research`, with quiet defaults the model cannot loosen (daily cadence — hourly for `vendor_status`, weekly for `page_watch`/`query` — `severity_floor=medium`, a keyword trigger built from the grounding entity + material-event words + the current-year priorities for feeds, `abs_change_pct_gte=5` for stocks). Requires the `grounding_entity` to name an external entity in company data — the company itself, a `competitive_landscape.primary_competitors` entry, or one of the profile's `vendors` / `tickers` (an initiative title or a current-year priority also grounds a proposal, but only ever to a suggestion: they are bags of common words a planted finding can echo) — *and* a score ≥ 4 on a fixed ledger: +2 entity in company data (mandatory), +1 entity already watched under another source, +1 target is the entity's own source (its ticker, its domain, or a primary-source host such as sec.gov), +1 finding confidence high, +1 verification confirmed, +1 cross-specialist consensus, ±1 from the policy's own approval history for that `(signal_type, grounding kind)` once it has ≥5 samples. The model's `certainty` can only downgrade a direct add to a suggestion; a `query` watch is always a suggestion; above `WATCHLIST_MAX_ENABLED` (40) enabled watches every add becomes a suggestion. At most `WATCHLIST_RESEARCH_MAX_DIRECT_ADDS` (2) per run.\n- **Suggestion** — anything that validates but misses the bar is inserted in `dry_run` (polls and records signals, never alerts) with `origin=research_proposed` and the rationale in `notes`, at most `WATCHLIST_RESEARCH_MAX_PROPOSALS` (2) per run. `/watchlist` shows them in a \"Suggested by the Executive\" section with Approve (`POST /watchlist/{slug}/approve` → `active`, `origin=research`) and Decline (`POST /watchlist/{slug}/decline` with a reason: `not_relevant` blacklists the entity, `wrong_source` blacklists only this target, `too_noisy` keeps it live with `severity_floor=high`). A suggestion nobody reviews within `WATCHLIST_PROPOSAL_TTL_DAYS` (14) is removed. The morning brief mentions the pending count in one line; a `watchlist_suggestions` alert nudges only once ≥3 suggestions have waited ≥7 days.\n- **Reject** — an invalid target, a second watch on the same site + signal type, a declined target, or a spent budget. Every decision is audited (`watchlist_research_added` / `_suggested` / `_rejected`) with the score and reasons; the stamp also lives in the row's `config_json._policy` so approve/decline/auto-disable can attribute the outcome.\n\n**Declines are remembered and enforced.** `watchlist_declines` is keyed by the normalized target (upper-cased ticker; URL with `https` forced, `www.` dropped, host and path lower-cased, query, fragment and trailing slash removed; free-text queries case- and whitespace-folded). A `not_relevant` decline also blacklists the *entity*: any later proposal whose `grounding_entity` names it is refused whatever the target. An explicit decline — the Decline button, \"Stop watching…\" on a research-added card, `remove_watchlist_entry` or `DELETE /watchlist/{slug}` on a research-origin row — is permanent; an unreviewed expiry may be re-proposed once after 90 days. The `propose_watch` handler refuses a declined target or entity before anything is fetched, so a new slug cannot route around a decline; the list is also rendered to the model as DECLINED. The routing pass that runs before the watchlist pass has no watchlist write tools at all (`add_watchlist_entry`, `tune_watchlist_entry`, `remove_watchlist_entry` are withheld from synthesis), and `tune_watchlist_entry` refuses `mode` / `enabled` changes on a pending suggestion — only the principal's approve or decline moves one out of review. Every URL-typed target (`rss`, `vendor_status`, `page_watch`) is checked against the SSRF guard at insert time, and a suggestion's `source_url` link is kept only when it is a public http(s) URL.\n\n**The policy learns from outcomes.** Approve, decline, expiry and auto-disable write `watchlist_policy_outcomes` rows keyed by `(signal_type, grounding kind, specialist)`; the pass renders the tallies (\"stock watches grounded in a competitor: 4 approved / 1 declined\"; \"proposals from cso: …\") and the score ledger reads them. The research turn also shows each existing watch's `origin`, `fired_count`, `dismiss_count` and `trust_score`.\n\n**Research watches retire themselves.** The scheduler's 15-minute sweep (`watch_policy.sweep`, alongside the alert expiry sweep) disables a `research`-origin watch — audited as `watchlist_auto_disabled`, re-enable from `/watchlist` — when it fired ≥5 alerts of which ≥2 were dismissed and trust ≤ 0.5, when a feed/page/status watch produced no signal in 30 days, or after 3 consecutive poll failures; the retired target is also recorded as a 90-day decline so the next run cannot re-add it under a new slug with fresh counters (a disabled row already counts as \"same source watched\"). Approve, decline and expiry are compare-and-act on \"still pending\", so a concurrent approve always wins over a decline or the sweep. Direct adds and auto-disables appear in the brief's \"handled overnight\" block as `watching` / `stopped_watching`. The research skip-if-unchanged fingerprint hashes only enabled, `active` rows, so approving or declining a suggestion never triggers a fresh 7-specialist run.\n\n### Invariants\n\n- Adapters are read-only — they never write upstream and never auto-execute.\n- Every `Signal` carries a deterministic `dedup_key` and a mandatory `provenance_url`.\n- Fetches are SSRF-guarded and bounded by `external_monitor_max_fetch_bytes`; xcrawl scrape (off by default, gated by `XCRAWL_ENABLED` + `XCRAWL_API_KEY`) is the one path that delegates the fetch to an external API.\n- Suppressed signals are still persisted so audits show the full picture.\n- A repeat from the same watch never becomes a second open card: the alert-level `watch:<slug>` key coalesces it, and only a severity escalation re-dispatches.\n- The research model never writes the watchlist: it proposes, deterministic policy adds (only when grounded in company data) or suggests, and a target the principal declined is refused at the handler.",
"mermaid": "flowchart TD\n ADD[\"add (chat tool / POST /watchlist / research)\"]\n VAL[\"target_validation: rss feed? → keep / convert→page_watch(xcrawl) / reject\"]\n WL[(\"watchlist\")]\n HB[\"external_monitor_scan heartbeat (~5 min)\"]\n AD[\"read-only adapters: vendor_status / rss / stock / query / edgar / page_watch (httpx | xcrawl)\"]\n SIG[(\"external_signals UNIQUE(dedup_key)\")]\n ENRICH[\"capture-time enrichment<br/>(relevance score + why_it_matters)\"]\n PROMO[\"promote_signal_to_alert\"]\n PIPE[\"alert pipeline (triage)\"]\n TODAY[\"/today proposals\"]\n ADD --> VAL\n VAL -->|\"insert valid rows\"| WL\n HB -->|\"walk enabled rows\"| WL\n WL -->|\"poll due rows\"| AD\n AD -->|\"emit Signal\"| SIG\n SIG -->|\"baseline / stale / dry_run / floor gates\"| ENRICH\n ENRICH -->|\"≥ relevance floor\"| PROMO\n PROMO --> PIPE\n PIPE --> TODAY\n class HB hot\n class WL storage\n class VAL compute\n class AD external\n class SIG storage\n class ENRICH compute\n class PROMO compute\n class PIPE compute\n class TODAY entry\n class ADD compute",
- "generated_at": "2026-09-12T10:42:31.179581+00:00"
+ "generated_at": "2026-09-12T11:00:48.077989+00:00"
}
diff --git a/packages/core/openexecutive/monitoring/models.py b/packages/core/openexecutive/monitoring/models.py
index ff4f628f..9d45297c 100644
--- a/packages/core/openexecutive/monitoring/models.py
+++ b/packages/core/openexecutive/monitoring/models.py
@@ -82,6 +82,11 @@ VALID_DECLINE_REASONS = frozenset({
DECLINE_REASON_NOT_RELEVANT, DECLINE_REASON_TOO_NOISY,
DECLINE_REASON_WRONG_SOURCE, DECLINE_REASON_EXPIRED,
})
+# The reasons a principal (or a tool acting for one) may give; `expired` is
+# only ever written by the sweep.
+EXPLICIT_DECLINE_REASONS = frozenset({
+ DECLINE_REASON_NOT_RELEVANT, DECLINE_REASON_TOO_NOISY, DECLINE_REASON_WRONG_SOURCE,
+})
# Watchlist row "cadence" hints — used by the briefing/digest layer in
# PR-C to decide whether a signal surfaces real-time vs in a digest.
diff --git a/packages/core/openexecutive/monitoring/research/watch_policy.py b/packages/core/openexecutive/monitoring/research/watch_policy.py
index 0f29c01b..10a9d0cb 100644
--- a/packages/core/openexecutive/monitoring/research/watch_policy.py
+++ b/packages/core/openexecutive/monitoring/research/watch_policy.py
@@ -38,6 +38,7 @@ from openexecutive.monitoring import store as ms
from openexecutive.monitoring.models import (
DECLINE_KIND_EXPIRED,
DECLINE_REASON_EXPIRED,
+ DECLINE_REASON_NOT_RELEVANT,
MODE_ACTIVE,
MODE_DRY_RUN,
ORIGIN_RESEARCH,
@@ -51,6 +52,7 @@ from openexecutive.monitoring.models import (
WatchlistItem,
)
from openexecutive.monitoring.research.models import ResearchFinding
+from openexecutive.monitoring.sources._http import validate_target_url
from openexecutive.monitoring.validation import normalize_target, registrable_domain
logger = logging.getLogger(__name__)
@@ -99,6 +101,13 @@ KIND_WATCH = "watch" # already watched (label/target) — corroborates, never g
GROUNDING_KINDS: frozenset[str] = frozenset({
KIND_COMPANY, KIND_COMPETITOR, KIND_VENDOR, KIND_TICKER, KIND_INITIATIVE, KIND_PRIORITY,
})
+# Kinds that name an external ENTITY the company deals with. Only these can
+# ground a direct add: an initiative title or a priority sentence is company
+# data too, but it is a bag of common words ("growth", "platform") that a
+# planted finding can echo, so a watch grounded only in one is a suggestion.
+STRONG_GROUNDING_KINDS: frozenset[str] = frozenset({
+ KIND_COMPANY, KIND_COMPETITOR, KIND_VENDOR, KIND_TICKER,
+})
# Material-event words every research feed trigger carries, so a competitor
# blog surfaces "we raised / we launched / pricing" and not every post.
@@ -109,8 +118,13 @@ _EVENT_KEYWORDS: tuple[str, ...] = (
_STOPWORDS: frozenset[str] = frozenset({
"the", "and", "for", "with", "our", "into", "from", "that", "this", "year",
"grow", "growth", "build", "expand", "increase", "improve", "drive", "launch",
- "new", "more", "across", "team", "company", "inc", "corp", "ltd", "llc",
+ "new", "more", "across", "team", "company", "inc", "corp", "ltd", "llc", "co",
+ "group", "labs", "platform", "product", "market", "customer", "customers",
+ "revenue", "sales", "enterprise", "global", "digital", "cloud", "data", "api",
})
+# Shortest token that may match on its own inside a multi-word term. Tickers
+# and short names still match exactly (whole-term equality is checked first).
+_MIN_PARTIAL_TOKEN = 4
_TOKEN_RE = re.compile(r"[a-z0-9]+")
# Auto-add defaults per source kind: (cadence, severity_floor).
@@ -276,12 +290,17 @@ def match_entity(entity: str, vocabulary: dict[str, str]) -> tuple[str, str] | N
exact = vocabulary.get(n)
if exact is not None and exact != KIND_WATCH:
return n, exact
- tokens = set(n.split())
+ # Partial matching only on distinctive tokens: no stopwords, nothing
+ # shorter than _MIN_PARTIAL_TOKEN, so "Growth Inc" cannot match the
+ # priority "drive growth in EMEA" and "corp" matches nothing.
+ tokens = {t for t in n.split() if t not in _STOPWORDS and len(t) >= _MIN_PARTIAL_TOKEN}
# An exact hit on a watch label is only the fallback: a company-data term
# that contains (or is contained by) the entity still wins.
best: tuple[str, str] | None = (n, exact) if exact is not None else None
+ if not tokens:
+ return best
for term, kind in vocabulary.items():
- term_tokens = set(term.split())
+ term_tokens = {t for t in term.split() if t not in _STOPWORDS and len(t) >= _MIN_PARTIAL_TOKEN}
if not term_tokens or not (term_tokens <= tokens or tokens <= term_tokens):
continue
# Prefer a company-data kind over a watch label, then the longer term.
@@ -292,6 +311,27 @@ def match_entity(entity: str, vocabulary: dict[str, str]) -> tuple[str, str] | N
return best
+def entity_declined(entity: str, declines: list[Any]) -> bool:
+ """True when the principal declined this entity as *not relevant* (the
+ reason that blacklists the company/topic, not just one source)."""
+ n = _norm(entity)
+ if len(n) < 2:
+ return False
+ tokens = {t for t in n.split() if t not in _STOPWORDS and len(t) >= _MIN_PARTIAL_TOKEN}
+ for d in declines:
+ if getattr(d, "reason", "") != DECLINE_REASON_NOT_RELEVANT:
+ continue
+ dn = _norm(str(getattr(d, "entity", "") or ""))
+ if len(dn) < 2:
+ continue
+ if dn == n:
+ return True
+ d_tokens = {t for t in dn.split() if t not in _STOPWORDS and len(t) >= _MIN_PARTIAL_TOKEN}
+ if tokens and d_tokens and (d_tokens <= tokens or tokens <= d_tokens):
+ return True
+ return False
+
+
# --------------------------------------------------------------------- #
# Classification
# --------------------------------------------------------------------- #
@@ -310,7 +350,9 @@ def _is_own_source(proposal: WatchProposal, entity_term: str, vocabulary: dict[s
if host in PRIMARY_SOURCE_HOSTS or any(host.endswith("." + h) for h in PRIMARY_SOURCE_HOSTS):
return True
host_tokens = set(_TOKEN_RE.findall(host.replace(".", " ")))
- entity_tokens = {t for t in entity_term.split() if len(t) >= 3}
+ entity_tokens = {
+ t for t in entity_term.split() if len(t) >= _MIN_PARTIAL_TOKEN and t not in _STOPWORDS
+ }
return bool(entity_tokens & host_tokens)
@@ -334,8 +376,8 @@ def _history_adjustment(
def _same_source_already_watched(proposal: WatchProposal, existing: list[WatchlistItem]) -> bool:
host = registrable_domain(proposal.target)
for item in existing:
- if not item.enabled:
- continue
+ # Disabled rows count: a source the sweep retired as noisy or dead
+ # must not come back under a new slug with reset counters.
if normalize_target(item.signal_type, item.target) == proposal.normalized_target:
return True
if host and item.signal_type == proposal.signal_type and registrable_domain(item.target) == host:
@@ -356,8 +398,10 @@ def classify(
+1 cross-specialist consensus on the finding
±1 policy history for (signal_type, grounding kind) at >=5 samples
- Direct at >= DIRECT_THRESHOLD with the mandatory entity match; the model's
- own ``certainty`` can only downgrade. ``query`` is never direct.
+ Direct at >= DIRECT_THRESHOLD with the mandatory entity match, and only
+ when the entity is a named competitor / vendor / ticker / the company
+ (STRONG_GROUNDING_KINDS); the model's own ``certainty`` can only
+ downgrade. ``query`` is never direct.
"""
reasons: list[str] = []
score = 0
@@ -398,6 +442,9 @@ def classify(
tier = TIER_SUGGEST
if grounded and score >= DIRECT_THRESHOLD:
tier = TIER_DIRECT
+ if tier == TIER_DIRECT and kind not in STRONG_GROUNDING_KINDS:
+ tier = TIER_SUGGEST
+ reasons.append(f"grounded only in a {kind} — needs a named competitor, vendor or ticker")
if tier == TIER_DIRECT and proposal.signal_type == SOURCE_KIND_QUERY:
tier = TIER_SUGGEST
reasons.append("standing web queries are always suggestions")
@@ -446,6 +493,19 @@ def quiet_defaults(
# --------------------------------------------------------------------- #
+def _safe_source_url(finding: ResearchFinding | None) -> str:
+ """First cited URL that is a public http(s) URL — it is rendered as a
+ link beside the Approve button, so anything else is dropped."""
+ for url in (finding.relevant_urls if finding else []):
+ candidate = str(url or "").strip()
+ if not candidate.lower().startswith(("http://", "https://")):
+ continue
+ ok, _reason = validate_target_url(candidate)
+ if ok:
+ return candidate[:500]
+ return ""
+
+
def _policy_stamp(decision: Decision, proposal: WatchProposal, finding: ResearchFinding | None) -> dict[str, Any]:
return {
"entity": decision.entity,
@@ -453,7 +513,7 @@ def _policy_stamp(decision: Decision, proposal: WatchProposal, finding: Research
"specialist": (finding.source_specialist if finding else ""),
"score": decision.score,
"reasons": decision.reasons[:6],
- "source_url": (finding.relevant_urls[0] if finding and finding.relevant_urls else ""),
+ "source_url": _safe_source_url(finding),
}
@@ -529,9 +589,9 @@ def apply_proposals(
origin=ORIGIN_RESEARCH if is_direct else ORIGIN_RESEARCH_PROPOSED,
db_path=db_path,
)
- except Exception as exc:
+ except Exception:
logger.exception("watch_policy: insert failed for %s", proposal.slug)
- summaries.append(_summary(proposal, "rejected", f"insert failed: {exc}"[:120]))
+ summaries.append(_summary(proposal, "rejected", "insert failed (see server log)"))
continue
inserted = ms.get_watchlist_item(new_id, db_path=db_path)
@@ -685,6 +745,10 @@ def _expire_suggestions(now: datetime, settings: PolicySettings, db_path: Path |
created = _parse(item.created_at)
if created is None or now - created < ttl or item.id is None:
continue
+ # Compare-and-delete: a principal approving this very row a moment
+ # ago must win over the sweep.
+ if not ms.delete_pending_suggestion(item.id, db_path=db_path):
+ continue
ms.insert_decline(
normalized_target=normalize_target(item.signal_type, item.target),
kind=DECLINE_KIND_EXPIRED, reason=DECLINE_REASON_EXPIRED,
@@ -692,7 +756,6 @@ def _expire_suggestions(now: datetime, settings: PolicySettings, db_path: Path |
signal_type=item.signal_type, slug=item.slug, db_path=db_path,
)
record_outcome_for(item, OUTCOME_EXPIRED, db_path=db_path)
- ms.delete_watchlist_item(item.id, db_path=db_path)
audit_log(
EVENT_SUGGESTION_EXPIRED,
f"Watch suggestion {item.slug} expired unreviewed after {settings.suggestion_ttl_days}d",
@@ -713,6 +776,15 @@ def _auto_disable(now: datetime, db_path: Path | None) -> int:
continue
ms.set_enabled(item.id, False, db_path=db_path)
record_outcome_for(item, OUTCOME_AUTO_DISABLED, db_path=db_path)
+ # Remember the target (retryable after 90 days, like an unreviewed
+ # expiry) so the next research run cannot re-add the same source
+ # under a new slug with fresh counters.
+ ms.insert_decline(
+ normalized_target=normalize_target(item.signal_type, item.target),
+ kind=DECLINE_KIND_EXPIRED, reason=reason[:120],
+ entity=str(policy_stamp_of(item).get("entity", "")),
+ signal_type=item.signal_type, slug=item.slug, db_path=db_path,
+ )
audit_log(
EVENT_AUTO_DISABLED,
f"Stopped watching {item.slug} — {reason}",
@@ -770,12 +842,14 @@ __all__ = [
"TIER_DIRECT",
"TIER_REJECT",
"TIER_SUGGEST",
+ "STRONG_GROUNDING_KINDS",
"Decision",
"PolicyContext",
"PolicySettings",
"WatchProposal",
"apply_proposals",
"classify",
+ "entity_declined",
"grounding_vocabulary",
"match_entity",
"policy_stamp_of",
diff --git a/packages/core/openexecutive/monitoring/store.py b/packages/core/openexecutive/monitoring/store.py
index 9ff15ded..28aba974 100644
--- a/packages/core/openexecutive/monitoring/store.py
+++ b/packages/core/openexecutive/monitoring/store.py
@@ -605,6 +605,37 @@ def approve_suggestion(item_id: int, db_path: Path | None = None) -> bool:
return cursor.rowcount > 0
+def delete_pending_suggestion(item_id: int, db_path: Path | None = None) -> bool:
+ """Delete a row only while it is still a pending research suggestion
+ (compare-and-delete, with its signal history). False when it was
+ approved, declined or removed in the meantime."""
+ with _get_conn(db_path) as conn:
+ row = conn.execute(
+ "SELECT 1 FROM watchlist WHERE id = ? AND origin = ? AND mode = ?",
+ (item_id, ORIGIN_RESEARCH_PROPOSED, MODE_DRY_RUN),
+ ).fetchone()
+ if row is None:
+ return False
+ conn.execute("DELETE FROM external_signals WHERE watchlist_id = ?", (item_id,))
+ cursor = conn.execute(
+ "DELETE FROM watchlist WHERE id = ? AND origin = ? AND mode = ?",
+ (item_id, ORIGIN_RESEARCH_PROPOSED, MODE_DRY_RUN),
+ )
+ return cursor.rowcount > 0
+
+
+def quiet_pending_suggestion(item_id: int, db_path: Path | None = None) -> bool:
+ """The too_noisy remedy: a pending suggestion goes live as a research
+ watch with a high severity floor. Conditional on it still being pending."""
+ with _get_conn(db_path) as conn:
+ cursor = conn.execute(
+ "UPDATE watchlist SET mode = ?, origin = ?, enabled = 1, severity_floor = 'high' "
+ "WHERE id = ? AND origin = ? AND mode = ?",
+ (MODE_ACTIVE, ORIGIN_RESEARCH, item_id, ORIGIN_RESEARCH_PROPOSED, MODE_DRY_RUN),
+ )
+ return cursor.rowcount > 0
+
+
def _row_to_decline(row: sqlite3.Row) -> WatchlistDecline:
return WatchlistDecline(**dict(row))
@@ -707,39 +738,44 @@ def record_policy_outcome(
)
+def _outcome_tally(
+ group_cols: tuple[str, ...], *, where: str = "", db_path: Path | None = None,
+) -> list[tuple[tuple[str, ...], str, int]]:
+ """``[(group key, outcome, n)]`` from watchlist_policy_outcomes. Column
+ names are internal constants, never user input."""
+ resolved = _resolve_db_path(db_path)
+ if not resolved.exists():
+ return []
+ cols = ", ".join(group_cols)
+ with _get_conn(db_path) as conn:
+ rows = conn.execute(
+ f"SELECT {cols}, outcome, COUNT(*) AS n FROM watchlist_policy_outcomes "
+ f"{where} GROUP BY {cols}, outcome"
+ ).fetchall()
+ return [
+ (tuple(str(row[c]) for c in group_cols), str(row["outcome"]), int(row["n"]))
+ for row in rows
+ ]
+
+
def policy_outcome_counts(
db_path: Path | None = None,
) -> dict[tuple[str, str], dict[str, int]]:
"""``{(signal_type, grounding_kind): {outcome: n}}`` — the policy's
track record by the shape of the guess. Empty on a fresh install."""
- resolved = _resolve_db_path(db_path)
- if not resolved.exists():
- return {}
out: dict[tuple[str, str], dict[str, int]] = {}
- with _get_conn(db_path) as conn:
- rows = conn.execute(
- "SELECT signal_type, grounding_kind, outcome, COUNT(*) AS n "
- "FROM watchlist_policy_outcomes GROUP BY signal_type, grounding_kind, outcome"
- ).fetchall()
- for row in rows:
- key = (str(row["signal_type"]), str(row["grounding_kind"]))
- out.setdefault(key, {})[str(row["outcome"])] = int(row["n"])
+ for key, outcome, n in _outcome_tally(("signal_type", "grounding_kind"), db_path=db_path):
+ out.setdefault((key[0], key[1]), {})[outcome] = n
return out
def specialist_outcome_counts(db_path: Path | None = None) -> dict[str, dict[str, int]]:
"""``{specialist: {outcome: n}}`` for the research turn's calibration line."""
- resolved = _resolve_db_path(db_path)
- if not resolved.exists():
- return {}
out: dict[str, dict[str, int]] = {}
- with _get_conn(db_path) as conn:
- rows = conn.execute(
- "SELECT specialist, outcome, COUNT(*) AS n FROM watchlist_policy_outcomes "
- "WHERE specialist != '' GROUP BY specialist, outcome"
- ).fetchall()
- for row in rows:
- out.setdefault(str(row["specialist"]), {})[str(row["outcome"])] = int(row["n"])
+ for key, outcome, n in _outcome_tally(
+ ("specialist",), where="WHERE specialist != ''", db_path=db_path,
+ ):
+ out.setdefault(key[0], {})[outcome] = n
return out
diff --git a/packages/core/openexecutive/monitoring/validation.py b/packages/core/openexecutive/monitoring/validation.py
index cd0d88d5..3d23f62f 100644
--- a/packages/core/openexecutive/monitoring/validation.py
+++ b/packages/core/openexecutive/monitoring/validation.py
@@ -44,15 +44,20 @@ def normalize_target(signal_type: str, target: str) -> str:
if signal_type in ("stock", "edgar"):
return raw.upper()
if "://" not in raw:
- return raw.lower()
+ # Free-text targets (standing queries): collapse case + whitespace.
+ return " ".join(raw.lower().split())
try:
parts = urlsplit(raw)
except ValueError:
return raw.lower()
- path = parts.path.rstrip("/") if parts.path not in ("", "/") else ""
- return urlunsplit((
- parts.scheme.lower(), parts.netloc.lower(), path, parts.query, "",
- ))
+ # Scheme, www., query string, fragment, path case and a trailing slash
+ # are all ways to spell the same source; none of them may defeat a
+ # decline or the duplicate-source guard.
+ host = (parts.hostname or "").lower()
+ if host.startswith("www."):
+ host = host[4:]
+ path = parts.path.lower().rstrip("/") if parts.path not in ("", "/") else ""
+ return urlunsplit(("https", host, path, "", ""))
def registrable_domain(url: str) -> str:
diff --git a/packages/core/openexecutive/orchestrator/watchlist_tools.py b/packages/core/openexecutive/orchestrator/watchlist_tools.py
index 27715f47..71280cd3 100644
--- a/packages/core/openexecutive/orchestrator/watchlist_tools.py
+++ b/packages/core/openexecutive/orchestrator/watchlist_tools.py
@@ -24,13 +24,16 @@ from openexecutive.monitoring import store as ms
from openexecutive.monitoring.models import (
DECLINE_KIND_EXPLICIT,
DECLINE_REASON_NOT_RELEVANT,
+ EXPLICIT_DECLINE_REASONS,
MODE_ACTIVE,
ORIGIN_EXECUTIVE,
+ ORIGIN_RESEARCH_PROPOSED,
RESEARCH_ORIGINS,
is_valid_cadence,
is_valid_mode,
)
from openexecutive.monitoring.sources import list_registered_kinds
+from openexecutive.monitoring.sources._http import validate_target_url
from openexecutive.monitoring.target_validation import (
WatchlistTargetError,
validate_and_normalize_target,
@@ -50,6 +53,9 @@ logger = logging.getLogger(__name__)
# watchlist when it only wants a quick check.
_LIST_DEFAULT_LIMIT = 50
+# Signal types whose target is a URL (validated at insert time).
+_URL_SIGNAL_TYPES: frozenset[str] = frozenset({"rss", "vendor_status", "page_watch"})
+
# --------------------------------------------------------------------- #
# Tool specs
@@ -429,6 +435,15 @@ async def _validated_target(
if ms.get_watchlist_item_by_slug(slug) is not None:
return _err(tool, f"slug {slug!r} already exists; use tune_watchlist_entry to modify")
+ if signal_type in _URL_SIGNAL_TYPES:
+ # Reject non-public / unparseable URLs at insert time for every
+ # URL-typed kind (the adapters guard again at poll time, but a junk
+ # row must not land — a dry-run suggestion still polls and is shown
+ # to the principal with an Approve button).
+ ok, reason = validate_target_url(target)
+ if not ok:
+ return _err(tool, f"target {target!r} is not a fetchable public URL: {reason}")
+
config = _display_label_config(signal_type, tool_input.get("display_label"))
# Validate the target before it lands: a non-feed rss URL is converted
# to a scrape-backed page_watch (when scrapeable) or rejected, so the
@@ -517,9 +532,22 @@ async def handle_propose_watch(tool_input: dict[str, Any], collector: list[Any])
model's turn and decides add / suggest / reject. A target the principal
declined is refused HERE so a new slug cannot route around the decline.
"""
- from openexecutive.monitoring.research.watch_policy import WatchProposal
+ from openexecutive.monitoring.research.watch_policy import (
+ WatchProposal,
+ entity_declined,
+ )
tool = "propose_watch"
+ # Decline checks come first — before the target is fetched for
+ # validation, so a declined source is never even requested again.
+ raw_type = str(tool_input.get("signal_type", "")).strip()
+ raw_target = str(tool_input.get("target", "")).strip()
+ if raw_target and ms.is_declined(normalize_target(raw_type, raw_target)):
+ return _err(tool, f"target {raw_target!r} was declined by the principal — do not re-propose it")
+ entity = str(tool_input.get("grounding_entity", ""))[:120]
+ if entity_declined(entity, ms.list_declines()):
+ return _err(tool, f"the principal declined watching {entity!r} — do not re-propose it")
+
validated = await _validated_target(tool, tool_input)
if isinstance(validated, str):
return validated
@@ -527,6 +555,7 @@ async def handle_propose_watch(tool_input: dict[str, Any], collector: list[Any])
normalized = normalize_target(signal_type, target)
if ms.is_declined(normalized):
+ # The rss → page_watch conversion can change the target; re-check.
return _err(tool, f"target {target!r} was declined by the principal — do not re-propose it")
certainty = str(tool_input.get("certainty", "unsure")).strip().lower()
@@ -545,7 +574,7 @@ async def handle_propose_watch(tool_input: dict[str, Any], collector: list[Any])
target=target,
normalized_target=normalized,
rationale=str(tool_input.get("rationale", ""))[:240],
- grounding_entity=str(tool_input.get("grounding_entity", ""))[:120],
+ grounding_entity=entity,
finding_index=finding_index,
certainty=certainty,
config=config,
@@ -617,11 +646,14 @@ async def handle_remove_watchlist_entry(tool_input: dict[str, Any]) -> str:
# "Stop watching" a research-added source is feedback: remember the
# decline so the research pass never re-proposes it under a new slug.
if removed and item.origin in RESEARCH_ORIGINS:
+ reason = str(tool_input.get("reason") or DECLINE_REASON_NOT_RELEVANT)
+ if reason not in EXPLICIT_DECLINE_REASONS:
+ reason = DECLINE_REASON_NOT_RELEVANT
try:
ms.insert_decline(
normalized_target=normalize_target(item.signal_type, item.target),
kind=DECLINE_KIND_EXPLICIT,
- reason=str(tool_input.get("reason") or DECLINE_REASON_NOT_RELEVANT),
+ reason=reason,
signal_type=item.signal_type,
slug=item.slug,
)
@@ -659,6 +691,14 @@ async def handle_tune_watchlist_entry(tool_input: dict[str, Any]) -> str:
fields: dict[str, Any] = {}
changes: list[str] = []
+ if item.origin == ORIGIN_RESEARCH_PROPOSED and ("mode" in tool_input or "enabled" in tool_input):
+ # A pending research suggestion leaves the pending state only through
+ # the principal's approve / decline — never by a tune from a model.
+ return _err(
+ tool,
+ f"{slug!r} is a pending research suggestion; the principal approves or "
+ "declines it on the watch list",
+ )
if "enabled" in tool_input:
enabled = bool(tool_input["enabled"])
fields["enabled"] = 1 if enabled else 0
diff --git a/packages/core/openexecutive/workflows/executive_research.py b/packages/core/openexecutive/workflows/executive_research.py
index 34aeeb3e..af5811f0 100644
--- a/packages/core/openexecutive/workflows/executive_research.py
+++ b/packages/core/openexecutive/workflows/executive_research.py
@@ -184,7 +184,7 @@ def _build_synthesis_system(configured: set[str], has_roster: bool = True) -> st
"as quiet.\n\n"
f"## ROUTING BUDGET: {_MAX_ROUTING_TOOLS_PER_RUN}\n\n"
f"You may fire AT MOST {_MAX_ROUTING_TOOLS_PER_RUN} outbound tool "
- "calls in this run combined (DMs, alerts, watchlist adds, "
+ "calls in this run combined (DMs, alerts, "
"follow-ups, workflow suggestions). The runtime enforces this "
"ceiling — calls beyond the budget will be rejected. Choose the "
"few that genuinely deserve the cost. Read-only lookups "
@@ -203,14 +203,12 @@ def _build_synthesis_system(configured: set[str], has_roster: bool = True) -> st
" (c) **Surface as briefing card** via create_alert — RARE. Only "
"when the principal personally must decide / react and the matter "
"is materially company-wide. Default away from this.\n"
- " (d) **Add to the watchlist** via add_watchlist_entry — ONLY "
- "for ongoing-monitor signals (a new competitor ticker, a vendor "
- "status page not yet watched). Most findings are NOT watchlist "
- "material; a dedicated pass after this one proposes monitors.\n"
- " (e) **Schedule a follow-up** via schedule_followup for "
+ " (d) **Schedule a follow-up** via schedule_followup for "
"time-shifted chases.\n"
- " (f) **Suggest a deeper workflow** via suggest_workflow only "
- "for major events (M&A, fundraising, crisis comms).\n\n"
+ " (e) **Suggest a deeper workflow** via suggest_workflow only "
+ "for major events (M&A, fundraising, crisis comms).\n"
+ " Watchlist changes are NOT yours to make here — a dedicated pass "
+ "after this one proposes monitors under policy.\n\n"
"## INVARIANTS\n\n"
" - Privacy: board / comp / legal stay per-Person. NEVER "
"broadcast.\n"
@@ -1058,6 +1056,15 @@ async def _watchlist_analysis_loop(
_SYNTHESIS_EXCLUDED_TOOLS = frozenset({
"run_executive_research",
"send_company_broadcast",
+ # Watchlist writes are withheld from the routing pass: every watch the
+ # research run creates must go through the dedicated watchlist pass and
+ # its policy (grounding, budgets, declines, suggestions). With these
+ # tools present, a finding could add an unfiltered live watch, flip a
+ # pending suggestion to active (self-approval), or write a permanent
+ # decline in the principal's name.
+ "add_watchlist_entry",
+ "tune_watchlist_entry",
+ "remove_watchlist_entry",
# Raw per-channel DM tools are withheld from synthesis: the model kept
# passing the wrong identifier into them (a person_id, another channel's
# id, or an invented Slack-style handle), so DMs silently failed the roster
diff --git a/packages/core/tests/unit/test_executive_research_watchlist.py b/packages/core/tests/unit/test_executive_research_watchlist.py
index f89b8a76..6c2d2a86 100644
--- a/packages/core/tests/unit/test_executive_research_watchlist.py
+++ b/packages/core/tests/unit/test_executive_research_watchlist.py
@@ -32,6 +32,10 @@ def _passthrough_target_validation(monkeypatch: pytest.MonkeyPatch) -> None:
return signal_type, target, config
monkeypatch.setattr(wt, "validate_and_normalize_target", _passthrough)
+ monkeypatch.setattr(wt, "validate_target_url", lambda url: (True, ""))
+ from openexecutive.monitoring.research import watch_policy as wp
+
+ monkeypatch.setattr(wp, "validate_target_url", lambda url: (True, ""))
@pytest.fixture
diff --git a/packages/core/tests/unit/test_executive_research_workflow.py b/packages/core/tests/unit/test_executive_research_workflow.py
index 3bb467c8..7c8bd2f8 100644
--- a/packages/core/tests/unit/test_executive_research_workflow.py
+++ b/packages/core/tests/unit/test_executive_research_workflow.py
@@ -30,6 +30,7 @@ from openexecutive.workflows.executive_research import (
_SYNTHESIS_EXCLUDED_TOOLS,
ExecutiveResearchInput,
ExecutiveResearchWorkflow,
+ _build_synthesis_system,
_render_research_context,
_render_synthesis_turn,
_render_team_roster,
@@ -460,3 +461,15 @@ def test_synthesis_turn_with_no_people_steers_to_lookup():
turn = _render_synthesis_turn(findings, [])
assert "YOUR TEAM" not in turn
assert "lookup_person" in turn # fallback path when roster absent
+
+
+def test_routing_pass_has_no_watchlist_write_tools() -> None:
+ """Every watch the research run creates must go through the watchlist
+ pass and its policy; the routing pass must not be able to add, tune or
+ remove watches (an unfiltered add, a self-approved suggestion, a decline
+ written in the principal's name)."""
+ from openexecutive.orchestrator.executive import _ALL_SKILL_TOOLS
+
+ tools = {t["name"] for t in _ALL_SKILL_TOOLS if t["name"] not in _SYNTHESIS_EXCLUDED_TOOLS}
+ assert not tools & {"add_watchlist_entry", "tune_watchlist_entry", "remove_watchlist_entry"}
+ assert "add_watchlist_entry" not in _build_synthesis_system({"slack"})
diff --git a/packages/core/tests/unit/test_watch_policy.py b/packages/core/tests/unit/test_watch_policy.py
index b9c207b5..aba9a360 100644
--- a/packages/core/tests/unit/test_watch_policy.py
+++ b/packages/core/tests/unit/test_watch_policy.py
@@ -27,6 +27,20 @@ from openexecutive.monitoring.research.models import ResearchFinding
from openexecutive.monitoring.validation import normalize_target, registrable_domain
[email protected](autouse=True)
+def _no_network(monkeypatch: pytest.MonkeyPatch) -> None:
+ """URL validation resolves DNS; keep the policy tests offline."""
+ from openexecutive.orchestrator import watchlist_tools as wt
+
+ monkeypatch.setattr(wp, "validate_target_url", lambda url: (True, ""))
+ monkeypatch.setattr(wt, "validate_target_url", lambda url: (True, ""))
+
+ async def _passthrough(signal_type: str, target: str, config: dict) -> tuple[str, str, dict]:
+ return signal_type, target, config
+
+ monkeypatch.setattr(wt, "validate_and_normalize_target", _passthrough)
+
+
@pytest.fixture
def db(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
db_path = tmp_path / "policy.db"
@@ -118,13 +132,17 @@ def test_match_entity_is_token_based_and_prefers_company_data() -> None:
def test_priority_terms_drop_stopwords() -> None:
- assert wp.priority_terms(_profile()) == ["enterprise", "accounts"]
+ # "expand", "into", "enterprise" are stopwords; only distinctive words remain.
+ assert wp.priority_terms(_profile()) == ["accounts"]
def test_normalize_target_and_domain() -> None:
assert normalize_target("stock", " acme ") == "ACME"
- assert normalize_target("rss", "HTTPS://www.Acme.com/feed/#top") == "https://www.acme.com/feed"
+ # scheme, www., query, fragment, path case and trailing slash never
+ # distinguish two spellings of one source.
+ assert normalize_target("rss", "HTTP://www.Acme.com/Feed/?x=1#top") == "https://acme.com/feed"
assert normalize_target("rss", "https://acme.com/") == "https://acme.com"
+ assert normalize_target("query", " Acme Corp pricing ") == "acme corp pricing"
assert registrable_domain("https://www.acme.com/blog") == "acme.com"
assert registrable_domain("ACME") == ""
@@ -288,13 +306,16 @@ def test_explicit_decline_is_permanent_and_expiry_retries_after_90_days(db: Path
later = datetime.now(UTC) + timedelta(days=91)
assert ms.is_declined("https://initech.com/feed.xml", now=later, db_path=db)
assert not ms.is_declined("https://globex.com/feed.xml", now=later, db_path=db)
- # An expiry never downgrades an explicit decline.
+ # An expiry never downgrades an explicit decline; an explicit decline
+ # always overwrites an expiry.
ms.insert_decline(normalized_target="https://initech.com/feed.xml",
kind=DECLINE_KIND_EXPIRED, reason="expired", db_path=db)
- assert ms.list_declines(db_path=db)[-1].kind == DECLINE_KIND_EXPLICIT or any(
- d.normalized_target == "https://initech.com/feed.xml" and d.kind == DECLINE_KIND_EXPLICIT
- for d in ms.list_declines(db_path=db)
- )
+ ms.insert_decline(normalized_target="https://globex.com/feed.xml",
+ kind=DECLINE_KIND_EXPLICIT, reason="wrong_source", db_path=db)
+ kinds = {d.normalized_target: (d.kind, d.reason) for d in ms.list_declines(db_path=db)}
+ assert kinds["https://initech.com/feed.xml"] == (DECLINE_KIND_EXPLICIT, "not_relevant")
+ assert kinds["https://globex.com/feed.xml"] == (DECLINE_KIND_EXPLICIT, "wrong_source")
+ assert ms.is_declined("https://globex.com/feed.xml", now=later, db_path=db)
@pytest.mark.asyncio
@@ -303,25 +324,37 @@ async def test_propose_handler_refuses_declined_target_under_new_slug(
) -> None:
from openexecutive.orchestrator import watchlist_tools as wt
- async def _passthrough(signal_type: str, target: str, config: dict) -> tuple[str, str, dict]:
- return signal_type, target, config
-
- monkeypatch.setattr(wt, "validate_and_normalize_target", _passthrough)
ms.insert_decline(normalized_target="https://initech.com/feed.xml",
- kind=DECLINE_KIND_EXPLICIT, reason="not_relevant", db_path=db)
+ kind=DECLINE_KIND_EXPLICIT, reason="wrong_source", db_path=db)
collector: list[Any] = []
out = await wt.handle_propose_watch({
"slug": "rss-initech-again", "signal_type": "rss",
- "target": "HTTPS://initech.com/feed.xml/", "grounding_entity": "Initech",
+ "target": "HTTP://www.initech.com/Feed.xml/?utm=1", "grounding_entity": "Initech",
"rationale": "x", "certainty": "confident",
}, collector)
assert "declined" in out and collector == []
+ # wrong_source blacklists only that target; another Initech source may be proposed.
+ other = await wt.handle_propose_watch({
+ "slug": "rss-initech-status", "signal_type": "vendor_status",
+ "target": "https://status.initech.com/history.atom", "grounding_entity": "Initech",
+ "rationale": "x", "certainty": "unsure",
+ }, collector)
+ assert '"queued"' in other and len(collector) == 1
+ # not_relevant blacklists the entity: any Initech source is refused.
+ ms.insert_decline(normalized_target="https://initech.com/other", entity="Initech Inc",
+ kind=DECLINE_KIND_EXPLICIT, reason="not_relevant", db_path=db)
+ blocked = await wt.handle_propose_watch({
+ "slug": "stock-initech", "signal_type": "stock", "target": "INTC",
+ "grounding_entity": "initech", "rationale": "x", "certainty": "confident",
+ }, collector)
+ assert "declined watching" in blocked and len(collector) == 1
ok = await wt.handle_propose_watch({
"slug": "stock-acme", "signal_type": "stock", "target": "ACME",
"grounding_entity": "Acme Corp", "rationale": "y", "certainty": "confident",
"finding_index": 1,
}, collector)
- assert '"queued": "stock-acme"' in ok and collector[0].finding_index == 0
+ assert '"queued": "stock-acme"' in ok
+ assert len(collector) == 2 and collector[-1].finding_index == 0
# --------------------------------------------------------------------- #
@@ -412,3 +445,51 @@ def test_sweep_nudges_once_suggestions_pile_up(db: Path) -> None:
assert wp.sweep(datetime.now(UTC), db_path=db)["nudged"] == 0 # coalesced
alerts = [a for a in list_alerts(limit=10, db_path=db) if a.source == wp.NUDGE_ALERT_SOURCE]
assert len(alerts) == 1 and "3 watch suggestions" in alerts[0].headline
+
+
+def test_initiative_or_priority_grounding_is_never_direct() -> None:
+ p = _proposal(
+ slug="rss-helios", target="https://helios-news.example/feed.xml",
+ grounding_entity="Helios API",
+ )
+ d = wp.classify(p, _finding(verification="confirmed", source_specialist="cso,cfo"), _ctx())
+ assert d.grounding_kind == wp.KIND_INITIATIVE and d.score >= wp.DIRECT_THRESHOLD
+ assert d.tier == wp.TIER_SUGGEST and "needs a named competitor" in d.reasons[-1]
+
+
+def test_generic_tokens_do_not_ground() -> None:
+ # "enterprise" appears in a priority but is a stopword; "Corp" is too.
+ assert wp.match_entity("Enterprise Corp", _ctx().vocabulary) is None
+ assert wp.match_entity("Growth", {"drive growth in emea": wp.KIND_PRIORITY}) is None
+
+
+def test_own_source_ignores_generic_host_tokens() -> None:
+ p = _proposal(target="https://labs.example.com/feed.xml", grounding_entity="Sente Labs")
+ d = wp.classify(p, _finding(), _ctx())
+ assert "own source" not in " ".join(d.reasons)
+
+
+def test_retired_source_is_not_re_added(db: Path) -> None:
+ ms.insert_watchlist_item(slug="rss-acme-old", signal_type="rss", target="https://acme.com/blog/feed.xml",
+ origin=ORIGIN_RESEARCH, enabled=False, db_path=db)
+ d = wp.classify(_proposal(), _finding(), _ctx(ms.list_watchlist(db_path=db)))
+ assert d.tier == wp.TIER_REJECT
+
+
+def test_auto_disable_records_a_retryable_decline(db: Path) -> None:
+ import sqlite3
+
+ ms.insert_watchlist_item(slug="rss-noisy", signal_type="rss", target="https://noisy.com/feed",
+ origin=ORIGIN_RESEARCH, db_path=db)
+ with sqlite3.connect(db) as conn:
+ conn.execute("UPDATE watchlist SET fired_count = 6, dismiss_count = 3, trust_score = 0.4")
+ assert wp.sweep(datetime.now(UTC), db_path=db)["disabled"] == 1
+ assert ms.is_declined("https://noisy.com/feed", db_path=db)
+ assert not ms.is_declined("https://noisy.com/feed", now=datetime.now(UTC) + timedelta(days=91), db_path=db)
+
+
+def test_source_url_stamp_only_keeps_public_http_urls() -> None:
+ f = _finding(relevant_urls=["javascript:alert(1)", "ftp://x/y", "https://www.acme.com/blog/pricing"])
+ out = wp.apply_proposals([_proposal()], [f], _ctx()) # no db: insert fails → rejected
+ assert out[0]["outcome"] == "rejected" and "see server log" in out[0]["result_preview"]
+ assert wp._safe_source_url(f) == "https://www.acme.com/blog/pricing"
diff --git a/packages/core/tests/unit/test_watchlist_tools.py b/packages/core/tests/unit/test_watchlist_tools.py
index c7efaea5..53ce007f 100644
--- a/packages/core/tests/unit/test_watchlist_tools.py
+++ b/packages/core/tests/unit/test_watchlist_tools.py
@@ -35,6 +35,7 @@ def _passthrough_target_validation(monkeypatch: pytest.MonkeyPatch) -> None:
return signal_type, target, config
monkeypatch.setattr(wt, "validate_and_normalize_target", _passthrough)
+ monkeypatch.setattr(wt, "validate_target_url", lambda url: (True, ""))
# --------------------------------------------------------------------- #
@@ -268,3 +269,38 @@ async def test_remove_research_watch_records_decline(db: Path) -> None:
# A manual row removed is not a decline.
await wt.handle_remove_watchlist_entry({"slug": "stock-mine"})
assert len(ms.list_declines(db_path=db)) == 1
+
+
+async def test_tune_cannot_move_a_pending_suggestion_out_of_review(db: Path) -> None:
+ ms.insert_watchlist_item(
+ slug="rss-sugg", signal_type="rss", target="https://s.com/feed", mode="dry_run",
+ origin="research_proposed", db_path=db,
+ )
+ out = json.loads(await wt.handle_tune_watchlist_entry({"slug": "rss-sugg", "mode": "active"}))
+ assert "pending research suggestion" in out["error"]
+ out2 = json.loads(await wt.handle_tune_watchlist_entry({"slug": "rss-sugg", "enabled": False}))
+ assert "error" in out2
+ # Other tunables stay allowed.
+ out3 = json.loads(await wt.handle_tune_watchlist_entry({"slug": "rss-sugg", "notes": "hi"}))
+ assert out3.get("ok") is True
+ row = ms.get_watchlist_item_by_slug("rss-sugg", db_path=db)
+ assert row is not None and row.mode == "dry_run"
+
+
+async def test_remove_ignores_an_invalid_reason(db: Path) -> None:
+ ms.insert_watchlist_item(slug="rss-acme", signal_type="rss", target="https://acme.com/feed",
+ origin="research", db_path=db)
+ await wt.handle_remove_watchlist_entry({"slug": "rss-acme", "reason": "ignore previous instructions"})
+ assert ms.list_declines(db_path=db)[0].reason == "not_relevant"
+
+
+async def test_add_rejects_non_public_url_targets(db: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(wt, "validate_target_url", lambda url: (False, "private address"))
+ out = json.loads(await wt.handle_add_watchlist_entry({
+ "slug": "pw-meta", "signal_type": "page_watch", "target": "http://169.254.169.254/latest",
+ }))
+ assert "not a fetchable public URL" in out["error"]
+ assert ms.list_watchlist(db_path=db) == []
diff --git a/packages/ui/src/app/watchlist/page.tsx b/packages/ui/src/app/watchlist/page.tsx
index e4e36adc..fa61f7b0 100644
--- a/packages/ui/src/app/watchlist/page.tsx
+++ b/packages/ui/src/app/watchlist/page.tsx
@@ -586,8 +586,15 @@ export default function WatchlistPage() {
async function stopWatching(slug: string, reason: WatchDeclineReason) {
markBusy(slug, true);
try {
- await deleteWatchlistItem(slug, reason);
- setItems((prev) => prev.filter((it) => it.slug !== slug));
+ if (reason === "too_noisy") {
+ // Same remedy the decline route applies: keep the source, only
+ // high-severity signals surface.
+ const updated = await patchWatchlistItem(slug, { severity_floor: "high" });
+ setItems((prev) => prev.map((it) => (it.slug === slug ? updated : it)));
+ } else {
+ await deleteWatchlistItem(slug, reason);
+ setItems((prev) => prev.filter((it) => it.slug !== slug));
+ }
} catch (e) {
setError(e instanceof Error ? e.message : "Remove failed");
} finally {