-
Notifications
You must be signed in to change notification settings - Fork 0
feat(portfolio): add decision queue digest #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saagpatel
merged 1 commit into
main
from
codex/portfolio-truth-canonical-remotes-20260619
Jun 19, 2026
+335
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| """Decision-queue compression for portfolio truth. | ||
|
|
||
| This layer is intentionally narrower than default attention. ``active-product`` | ||
| and ``active-infra`` form the watch set; the decision queue is only for current | ||
| truth entries that already carry a concrete decision signal. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any | ||
|
|
||
| CONTRACT_VERSION = "decision_queue_v1" | ||
| MAX_DECISION_QUEUE_ITEMS = 5 | ||
|
|
||
| NON_DEFAULT_STATES = frozenset( | ||
| {"parked", "archived", "experiment", "evidence-history", "manual-only"} | ||
| ) | ||
|
|
||
|
|
||
| def _mapping(value: Any) -> dict[str, Any]: | ||
| return value if isinstance(value, dict) else {} | ||
|
|
||
|
|
||
| def _text(value: Any) -> str: | ||
| return value.strip() if isinstance(value, str) else "" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class DecisionQueueItem: | ||
| project: str | ||
| path: str | ||
| attention_state: str | ||
| decision_type: str | ||
| why_now: str | ||
| evidence: tuple[str, ...] | ||
| source_freshness: str | ||
| recommended_action: str | ||
| do_not_refresh_docs_unless: str | ||
|
|
||
| def to_dict(self) -> dict[str, Any]: | ||
| return { | ||
| "project": self.project, | ||
| "path": self.path, | ||
| "attention_state": self.attention_state, | ||
| "decision_type": self.decision_type, | ||
| "why_now": self.why_now, | ||
| "evidence": list(self.evidence), | ||
| "source_freshness": self.source_freshness, | ||
| "recommended_action": self.recommended_action, | ||
| "do_not_refresh_docs_unless": self.do_not_refresh_docs_unless, | ||
| } | ||
|
|
||
|
|
||
| def _decision_for_project( | ||
| project: dict[str, Any], *, generated_at: str | ||
| ) -> DecisionQueueItem | None: | ||
| identity = _mapping(project.get("identity")) | ||
| derived = _mapping(project.get("derived")) | ||
| risk = _mapping(project.get("risk")) | ||
| security = _mapping(project.get("security")) | ||
|
|
||
| attention_state = _text(derived.get("attention_state")) or "manual-only" | ||
| project_name = _text(identity.get("display_name")) or "Repo" | ||
| path = _text(identity.get("path")) or project_name | ||
|
|
||
| if attention_state in {"archived", "evidence-history"}: | ||
| return None | ||
|
|
||
| evidence: list[str] = [] | ||
| decision_type = "" | ||
| why_now = "" | ||
| recommended_action = "" | ||
|
|
||
| if bool(risk.get("security_risk")): | ||
| critical = int(security.get("dependabot_critical") or 0) | ||
| high = int(security.get("dependabot_high") or 0) | ||
| decision_type = "security follow-up" | ||
| why_now = "Current portfolio truth marks this project with security risk." | ||
| evidence.append(f"security_risk=true; dependabot critical={critical}, high={high}") | ||
| recommended_action = "Decide whether to run the repo's security follow-up lane." | ||
| elif attention_state in NON_DEFAULT_STATES: | ||
| return None | ||
| elif attention_state == "decision-needed": | ||
| decision_type = "owner or human decision" | ||
| why_now = "Current portfolio truth marks this project as decision-needed." | ||
| evidence.append("attention_state=decision-needed") | ||
| risk_summary = _text(risk.get("risk_summary")) | ||
| if risk_summary: | ||
| evidence.append(risk_summary) | ||
| recommended_action = "Resolve the explicit portfolio decision before expanding scope." | ||
| else: | ||
| return None | ||
|
|
||
| return DecisionQueueItem( | ||
| project=project_name, | ||
| path=path, | ||
| attention_state=attention_state, | ||
| decision_type=decision_type, | ||
| why_now=why_now, | ||
| evidence=tuple(evidence), | ||
| source_freshness=generated_at or "unknown", | ||
| recommended_action=recommended_action, | ||
| do_not_refresh_docs_unless=( | ||
| "Do not refresh context, roadmap, handoff, AGENTS, or docs unless " | ||
| "that work directly resolves this decision." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def build_decision_queue(portfolio_truth: dict[str, Any]) -> list[dict[str, Any]]: | ||
| """Return the small decision queue from current portfolio truth. | ||
|
|
||
| This is deliberately stricter than the watch set: active product or active | ||
| infrastructure projects are ignored unless current truth also contains a | ||
| concrete decision signal. | ||
| """ | ||
| projects = portfolio_truth.get("projects") or [] | ||
| generated_at = _text(portfolio_truth.get("generated_at")) | ||
| queue: list[DecisionQueueItem] = [] | ||
| for project in projects: | ||
| if not isinstance(project, dict): | ||
| continue | ||
| item = _decision_for_project(project, generated_at=generated_at) | ||
| if item is not None: | ||
| queue.append(item) | ||
|
|
||
| decision_rank = {"security follow-up": 0, "owner or human decision": 1} | ||
| queue.sort( | ||
| key=lambda item: ( | ||
| decision_rank.get(item.decision_type, 9), | ||
| item.project.lower(), | ||
| ) | ||
| ) | ||
| return [item.to_dict() for item in queue[:MAX_DECISION_QUEUE_ITEMS]] | ||
|
|
||
|
|
||
| def summarize_decision_queue(items: list[dict[str, Any]]) -> dict[str, Any]: | ||
| type_counts: dict[str, int] = {} | ||
| for item in items: | ||
| decision_type = _text(item.get("decision_type")) or "unknown" | ||
| type_counts[decision_type] = type_counts.get(decision_type, 0) + 1 | ||
| return { | ||
| "contract_version": CONTRACT_VERSION, | ||
| "decision_queue_count": len(items), | ||
| "decision_queue_type_counts": type_counts, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from src.portfolio_decision_queue import build_decision_queue, summarize_decision_queue | ||
|
|
||
|
|
||
| def _project( | ||
| name: str, | ||
| *, | ||
| attention_state: str, | ||
| security_risk: bool = False, | ||
| dependabot_critical: int = 0, | ||
| dependabot_high: int = 0, | ||
| ) -> dict: | ||
| return { | ||
| "identity": {"display_name": name, "path": name}, | ||
| "derived": { | ||
| "attention_state": attention_state, | ||
| "registry_status": "active", | ||
| "activity_status": "active", | ||
| }, | ||
| "risk": { | ||
| "risk_tier": "baseline", | ||
| "risk_summary": "No elevated risk factors.", | ||
| "security_risk": security_risk, | ||
| }, | ||
| "security": { | ||
| "dependabot_critical": dependabot_critical, | ||
| "dependabot_high": dependabot_high, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def test_default_attention_without_decision_signal_stays_out_of_queue() -> None: | ||
| truth = { | ||
| "generated_at": "2026-06-19T04:36:19+00:00", | ||
| "projects": [ | ||
| _project("Product", attention_state="active-product"), | ||
| _project("Infra", attention_state="active-infra"), | ||
| _project("Manual", attention_state="manual-only"), | ||
| _project("Experiment", attention_state="experiment"), | ||
| ], | ||
| } | ||
|
|
||
| assert build_decision_queue(truth) == [] | ||
| assert summarize_decision_queue([]) == { | ||
| "contract_version": "decision_queue_v1", | ||
| "decision_queue_count": 0, | ||
| "decision_queue_type_counts": {}, | ||
| } | ||
|
|
||
|
|
||
| def test_decision_needed_project_enters_queue() -> None: | ||
| truth = { | ||
| "generated_at": "2026-06-19T04:36:19+00:00", | ||
| "projects": [_project("NeedsDecision", attention_state="decision-needed")], | ||
| } | ||
|
|
||
| [item] = build_decision_queue(truth) | ||
| assert item["project"] == "NeedsDecision" | ||
| assert item["decision_type"] == "owner or human decision" | ||
| assert item["source_freshness"] == "2026-06-19T04:36:19+00:00" | ||
| assert "attention_state=decision-needed" in item["evidence"] | ||
|
|
||
|
|
||
| def test_security_risk_enters_queue_even_when_manual_only() -> None: | ||
| truth = { | ||
| "generated_at": "2026-06-19T04:36:19+00:00", | ||
| "projects": [ | ||
| _project( | ||
| "ManualSecurity", | ||
| attention_state="manual-only", | ||
| security_risk=True, | ||
| dependabot_critical=1, | ||
| ) | ||
| ], | ||
| } | ||
|
|
||
| [item] = build_decision_queue(truth) | ||
| assert item["project"] == "ManualSecurity" | ||
| assert item["decision_type"] == "security follow-up" | ||
| assert item["evidence"] == ["security_risk=true; dependabot critical=1, high=0"] | ||
|
|
||
|
|
||
| def test_archived_security_risk_stays_out_of_queue() -> None: | ||
| truth = { | ||
| "projects": [ | ||
| _project( | ||
| "ArchivedSecurity", | ||
| attention_state="archived", | ||
| security_risk=True, | ||
| dependabot_critical=1, | ||
| ) | ||
| ], | ||
| } | ||
|
|
||
| assert build_decision_queue(truth) == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When more than five projects carry
security_risk, every security item receives the same rank here and is then ordered only by project name beforequeue[:MAX_DECISION_QUEUE_ITEMS]is applied. That means five alphabetically earlier repos with one high alert can push a later repo with open critical alerts out of the weekly decision queue entirely, even though the digest is meant to surface security follow-up decisions. Include the Dependabot critical/high counts in the sort key for security items before falling back to the name.Useful? React with 👍 / 👎.