Skip to content

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

Single-source the quiet-day lines; close review gaps in the tests

Rufusbe4c7ef8dca5
diff --git a/packages/core/openexecutive/api/routes/today.py b/packages/core/openexecutive/api/routes/today.py
index 05979458..6e1bb017 100644
--- a/packages/core/openexecutive/api/routes/today.py
+++ b/packages/core/openexecutive/api/routes/today.py
@@ -945,6 +945,7 @@ def _build_activity(
Items are merged, sorted by timestamp DESC, and capped at `limit`.
The caller is expected to clamp `limit` (the route does this).
"""
+ from openexecutive.alerts import lifecycle as alert_lifecycle
from openexecutive.alerts import store as alerts_store
from openexecutive.memory import decision_ledger
from openexecutive.memory.episodic import (
@@ -1079,8 +1080,6 @@ def _build_activity(
# alert for a gated booking, already represented by the `decision_resolved`
# rows above (and as a live proposal while pending), so surfacing them here
# would double-count.
- from openexecutive.alerts import lifecycle as alert_lifecycle
-
now_for_alerts = datetime.now(UTC)
for alert in alerts_store.recent_alerts(
limit=pool, exclude_source=decision_ledger.DECISION_ALERT_SOURCE,
@@ -1228,14 +1227,9 @@ def _narrative_inputs(
)
-# Quiet-day lines, one per narrative scope. They match the wording the
-# synthesis prompts tell the model to emit on a quiet day, so a short-circuited
-# narrative is indistinguishable from a model-produced one.
-_QUIET_PRINCIPAL = "Quiet right now — nothing pressing."
-_QUIET_VIEWER = "Quiet right now — nothing needs you."
-
-
-def _narrative_activity(viewer: PersonBriefItem | None, scoped: bool) -> list[dict[str, Any]]:
+def _narrative_activity(
+ viewer: PersonBriefItem | None, viewer_desc: dict[str, str] | None
+) -> list[dict[str, Any]]:
"""The activity list the narrative reasons over, for BOTH the hash and the
synthesis.
@@ -1246,12 +1240,17 @@ def _narrative_activity(viewer: PersonBriefItem | None, scoped: bool) -> list[di
Closed alerts are dropped (`live_alerts_only`) — the narrative describes
what is live, not what once was.
+
+ ``viewer_desc`` is `_narrative_inputs`' third element: non-None only for a
+ non-principal teammate, whose feed is narrowed to their own departments.
+ Taken as-is rather than as a bool so both call sites pass what they already
+ hold instead of each re-deriving the same condition.
"""
activity = [
item.model_dump()
for item in _build_activity(20, live_alerts_only=True).items
]
- if scoped and viewer is not None:
+ if viewer_desc is not None and viewer is not None:
# Teammate view: keep only activity in their departments.
vdepts = set(viewer.department_slugs)
activity = [a for a in activity if a.get("department") in vdepts]
@@ -1293,7 +1292,7 @@ def _attach_narrative(
nhash = narrative_cache.build_narrative_input_hash(
today_data,
scope=scope,
- activity=_narrative_activity(viewer, desc is not None),
+ activity=_narrative_activity(viewer, desc),
)
cached = narrative_cache.get(scope)
if cached is not None:
@@ -1322,7 +1321,11 @@ async def _regen_briefing_narrative(
different scope's cache entry.
"""
from openexecutive.briefing import narrative_cache
- from openexecutive.briefing.narrative import synthesize_briefing_narrative
+ from openexecutive.briefing.narrative import (
+ QUIET_PRINCIPAL,
+ QUIET_VIEWER,
+ synthesize_briefing_narrative,
+ )
try:
snapshot = _build_today()
@@ -1335,12 +1338,12 @@ async def _regen_briefing_narrative(
"regen; skipping write", expected_scope, scope,
)
return
- activity = _narrative_activity(viewer, viewer_desc is not None)
+ activity = _narrative_activity(viewer, viewer_desc)
if _nothing_needs_attention(today_data):
# Nothing awaits a decision — skip the model call entirely and
# write the fixed quiet line. Still cached (below) so the hot path
# sees a fresh hash instead of re-scheduling this task forever.
- text = _QUIET_VIEWER if viewer_desc is not None else _QUIET_PRINCIPAL
+ text = QUIET_VIEWER if viewer_desc is not None else QUIET_PRINCIPAL
else:
period_label = datetime.now(UTC).strftime("%Y-%m-%d")
text = await asyncio.wait_for(
diff --git a/packages/core/openexecutive/briefing/narrative.py b/packages/core/openexecutive/briefing/narrative.py
index a3d652b0..5f527398 100644
--- a/packages/core/openexecutive/briefing/narrative.py
+++ b/packages/core/openexecutive/briefing/narrative.py
@@ -23,6 +23,17 @@ from openexecutive.alerts.lifecycle import parse_aware
logger = logging.getLogger(__name__)
+# The quiet-day lines. Single-sourced here, in the module that owns the
+# prompts, because three different code paths must emit text identical to what
+# the model is told to emit on a quiet day: this module's prompts, `today`'s
+# empty-board short-circuit (which skips the model entirely), and
+# `morning_brief`'s empty fallback. They were five separate literals across
+# three files, matching only by convention — a prompt reword would have
+# silently desynced the short-circuit from the model's own wording.
+# `test_briefing_narrative.py` asserts each prompt still carries its line.
+QUIET_PRINCIPAL = "Quiet right now — nothing pressing."
+QUIET_VIEWER = "Quiet right now — nothing needs you."
+
# Standalone morning-brief DM prompt. Unlike the /today header, this is
# delivered as a DM with NO cards beside it — so it MUST enumerate what needs
# the principal's attention (it's the only thing they see). Whole-company,
@@ -55,7 +66,7 @@ STANDALONE_BRIEF_SYSTEM = (
" 6. **At risk** — departments / goals trending off-track the principal "
"hasn't already been briefed on.\n\n"
"Skip headers entirely for sections with no content. If everything is "
- "genuinely quiet, output one line: 'Quiet right now — nothing pressing.'"
+ "genuinely quiet, output one line: '" + QUIET_PRINCIPAL + "'"
)
@@ -94,7 +105,7 @@ BRIEFING_NARRATIVE_SYSTEM = (
"though: a smart reader should get every line on the FIRST read — short "
"sentences, plain words over jargon, and when a domain term is unavoidable "
"state its consequence plainly. Reference specifics by name. If it's "
- "genuinely quiet, output one line: 'Quiet right now — nothing pressing.'"
+ "genuinely quiet, output one line: '" + QUIET_PRINCIPAL + "'"
)
@@ -121,7 +132,7 @@ def _viewer_system_prompt(name: str, role: str) -> str:
"report. But clarity first: they should get every line on the first "
"read — short sentences, plain words over jargon. Address them directly "
"('you'); the context is already scoped to them. If nothing is on their "
- "plate, output one line: 'Quiet right now — nothing needs you.'"
+ "plate, output one line: '" + QUIET_VIEWER + "'"
)
@@ -305,6 +316,8 @@ async def synthesize_briefing_narrative(
__all__ = [
"BRIEFING_NARRATIVE_SYSTEM",
+ "QUIET_PRINCIPAL",
+ "QUIET_VIEWER",
"STANDALONE_BRIEF_SYSTEM",
"render_briefing_context",
"synthesize_briefing_narrative",
diff --git a/packages/core/openexecutive/workflows/morning_brief.py b/packages/core/openexecutive/workflows/morning_brief.py
index 3f30016b..9aee9fe5 100644
--- a/packages/core/openexecutive/workflows/morning_brief.py
+++ b/packages/core/openexecutive/workflows/morning_brief.py
@@ -194,7 +194,10 @@ class MorningBriefWorkflow(Workflow):
step_title="Synthesize the brief",
)
- from openexecutive.briefing.narrative import synthesize_briefing_narrative
+ from openexecutive.briefing.narrative import (
+ QUIET_PRINCIPAL,
+ synthesize_briefing_narrative,
+ )
try:
# standalone=True → the enumerated DM brief (no cards beside it),
@@ -210,9 +213,9 @@ class MorningBriefWorkflow(Workflow):
return
if not artifact_text:
- # Matches the shared synthesizer's quiet-day line so the empty
+ # The shared synthesizer's own quiet-day line, so the empty
# fallback reads identically to a model-produced quiet brief.
- artifact_text = "Quiet right now — nothing pressing."
+ artifact_text = QUIET_PRINCIPAL
yield WorkflowEvent(
type="step_done",
diff --git a/packages/core/tests/unit/test_briefing_narrative.py b/packages/core/tests/unit/test_briefing_narrative.py
index 7ca9e7c9..0b90929d 100644
--- a/packages/core/tests/unit/test_briefing_narrative.py
+++ b/packages/core/tests/unit/test_briefing_narrative.py
@@ -86,3 +86,40 @@ def test_standalone_dm_prompt_carries_older_items_as_one_line() -> None:
assert "Handled overnight" in STANDALONE_BRIEF_SYSTEM
assert "Top call" in STANDALONE_BRIEF_SYSTEM
assert "delta" in lowered
+
+
+def test_quiet_lines_are_single_sourced_into_the_prompts() -> None:
+ """The quiet-day text exists once and the prompts carry it verbatim.
+
+ `today._regen_briefing_narrative` writes these strings directly when it
+ short-circuits an empty board, and `morning_brief` uses one as its empty
+ fallback — both skip the model, so their text must be exactly what the
+ model is told to emit. They were five hand-copied literals across three
+ files; this is the guard that keeps a prompt reword from silently
+ desyncing them.
+ """
+ import inspect
+
+ from openexecutive.api.routes import today as today_route
+ from openexecutive.briefing.narrative import (
+ BRIEFING_NARRATIVE_SYSTEM,
+ QUIET_PRINCIPAL,
+ QUIET_VIEWER,
+ STANDALONE_BRIEF_SYSTEM,
+ _viewer_system_prompt,
+ )
+ from openexecutive.workflows import morning_brief
+
+ assert QUIET_PRINCIPAL in BRIEFING_NARRATIVE_SYSTEM
+ assert QUIET_PRINCIPAL in STANDALONE_BRIEF_SYSTEM
+ assert QUIET_VIEWER in _viewer_system_prompt("Dan", "CFO")
+
+ # The consumers must import the constants, never re-declare the phrase.
+ # Checked against source because both import them function-locally (this
+ # module's convention), so there is no attribute to compare identities on.
+ phrase = "Quiet right now"
+ for module in (today_route, morning_brief):
+ assert phrase not in inspect.getsource(module), (
+ f"{module.__name__} hardcodes a quiet-day line; import "
+ "QUIET_PRINCIPAL / QUIET_VIEWER from briefing.narrative instead"
+ )
diff --git a/packages/core/tests/unit/test_today_route.py b/packages/core/tests/unit/test_today_route.py
index 1819de82..79cc691f 100644
--- a/packages/core/tests/unit/test_today_route.py
+++ b/packages/core/tests/unit/test_today_route.py
@@ -113,7 +113,19 @@ def test_today_departments_have_fields(client: TestClient) -> None:
# Deprecated alias /morning-brief
# --------------------------------------------------------------------------- #
-def test_morning_brief_alias_returns_same_body(client: TestClient) -> None:
+def test_morning_brief_alias_returns_same_body(
+ client: TestClient, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ # Seed a live proposal so the board is NOT quiet: otherwise both routes
+ # only ever compare the fixed quiet line and alias parity on a real
+ # synthesized narrative would go unexercised.
+ _seed_live_action_alert(episodic.DB_PATH)
+
+ async def _synth(**_kw: object) -> str:
+ return "**Bottom line:** the budget needs you."
+
+ monkeypatch.setattr(briefing_narrative, "synthesize_briefing_narrative", _synth)
+
# Warm the narrative cache first: the very first /today hit is cold
# (narrative null) and its background task populates the cache, so
# comparing a cold call against a warm one would diff on `narrative`
@@ -121,6 +133,7 @@ def test_morning_brief_alias_returns_same_body(client: TestClient) -> None:
client.get("/today")
today = client.get("/today").json()
legacy = client.get("/morning-brief").json()
+ assert today["narrative"] == "**Bottom line:** the budget needs you."
assert today == legacy
@@ -520,7 +533,9 @@ def test_insight_served_from_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPat
def test_morning_brief_alias_unaffected_by_async_today(client: TestClient) -> None:
"""The sync /morning-brief alias must keep returning the same body as
- the now-async /today (both serve insight=None on a cold cache)."""
+ the now-async /today (both serve insight=None on a cold INSIGHT cache;
+ the narrative cache is deliberately warmed first — see the alias test
+ above — so the two calls are compared on equal footing)."""
client.get("/today") # warm the narrative cache — see the alias test above
assert client.get("/today").json() == client.get("/morning-brief").json()
@@ -1719,3 +1734,77 @@ def test_live_board_still_synthesizes(
c.get("/today")
assert c.get("/today").json()["narrative"] == "**Bottom line:** the budget needs you."
assert calls["n"] == 1
+
+
+def test_viewer_slice_scopes_proposals_to_the_teammate(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """`_viewer_slice` keeps only what is routed to the viewer.
+
+ Covered directly because the route-level teammate test can no longer prove
+ it: an empty slice now short-circuits before the synthesizer, so nothing
+ downstream observes the scoped proposal list.
+ """
+ db = tmp_path / "slice.db"
+ _setup_isolated_db(db, monkeypatch)
+ dan = people_store.upsert_person(
+ full_name="Dan", role="CFO", email="[email protected]",
+ department_slugs=["finance"], db_path=db,
+ )
+ other = people_store.upsert_person(
+ full_name="Eve", role="COO", email="[email protected]",
+ department_slugs=["operations"], db_path=db,
+ )
+ alert_store.insert_alert(
+ source="system", external_id="for-dan", severity="high",
+ headline="Dan's item", body="b", routed_to_person_id=dan, db_path=db,
+ )
+ alert_store.insert_alert(
+ source="system", external_id="for-eve", severity="high",
+ headline="Eve's item", body="b", routed_to_person_id=other, db_path=db,
+ )
+
+ snapshot = today_route._build_today()
+ viewer = next(p for p in snapshot.people if p.id == dan)
+ sliced = today_route._viewer_slice(snapshot, viewer)
+
+ assert [p["headline"] for p in sliced["proposals"]] == ["Dan's item"]
+ assert sliced["people"] == [] # the principal-only section is dropped
+
+
+def test_closed_alerts_never_reach_the_synthesizer(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """End-to-end: on a NON-quiet board the model still must not be told about
+ a dismissed alert.
+
+ The quiet short-circuit cannot be what saves us here — a live proposal
+ keeps the board active — so this proves `live_alerts_only` actually
+ survives the trip through `_regen_briefing_narrative`.
+ """
+ db = tmp_path / "e2e-live-only.db"
+ _setup_isolated_db(db, monkeypatch)
+ _seed_live_action_alert(db, headline="Approve the Q3 budget")
+ dismissed = alert_store.insert_alert(
+ source="system", external_id="dismissed-e2e", severity="urgent",
+ headline="St. Albans reconciliation gap", body="b", db_path=db,
+ )
+ assert dismissed is not None
+ alert_store.set_status(dismissed, "dismissed", db_path=db)
+
+ seen: dict[str, list[str]] = {}
+
+ async def _synth(**kw: object) -> str:
+ activity = kw.get("activity") or []
+ seen["summaries"] = [
+ str(a.get("summary", "")) for a in activity # type: ignore[union-attr]
+ ]
+ return "**Bottom line:** the budget needs you."
+
+ monkeypatch.setattr(briefing_narrative, "synthesize_briefing_narrative", _synth)
+
+ c = _make_client()
+ c.get("/today")
+
+ assert "St. Albans reconciliation gap" not in seen["summaries"]
+ assert "Approve the Q3 budget" in seen["summaries"]