Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/features/code-index/history-and-prs.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ the PRs of its files (every file that defines a name), newest first; a `numbers`
answers in one page of up to `limit` PRs and refuses `offset`.
`code.symbol_history` narrows this to one function's regression history: the PRs that
touched its span, their linked issues and reverts, and the review comments inside it.
Its `regression_prs` names up to three PRs behind the summary's `named_fix_prs`,
`reverts` and `caused_issues`, read from the whole window whatever `limit` serves. Each
carries its title as the one-line cause, its merge date and `kinds` (`fix`, `revert`,
`caused_issue` with the issue numbers). A fix says `fix_by`: `title` when its title says
fix, crash, regression and the like, or `linked_issue` when it is counted only for closing
an issue, which a feature or performance PR does too. A PR behind more of the counts comes
first, then every entry before a `linked_issue` fix, then a fix before a revert before a
PR issues trace back to, then the newest. When the PR changed test files, `test_gate` holds
the `code.test_gate` arguments (`org`, `namespace`, `files`) that list how to run up to
four of them in the namespace the history was read from: first those `code.test_gate` has
a run recipe for (its built-in ones and `code_test_gate_run_templates`), then files named
as tests, then fixtures that are tests only by their directory, with one file of each run
command (such as one suite's directory) before a second of it. They are the paths the
ledger lists for the PR, so one it deleted or a later PR renamed may be gone. The record
is the PR ledger's; a test file is one `code.test_gate` counts as a test (a test
directory, or a test file name in the languages it lists).

`code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as
release versions (`from_version`, `to_version`) or commit shas. It combines the PR
Expand Down Expand Up @@ -203,6 +219,13 @@ record by its file and name (`path:symbol`), so a name many files define, such a
`path:symbol` form does not parse, such as a path without an extension or with `[`, or a
name such as `(anonymous namespace)::f`, reads the bare name, as does a form past the
op's 300-character name bound; a record of another file's definition is `unknown`.
A row whose counts make the section `regressions` carries that record's `regression_prs`,
so the brief names the earlier fixes, reverts and culprit PRs with their test files; a
brief stored by an earlier build has the counts without it. When a tracker namespace a
record may rest on, the one bound to the code namespace or the one the record says it
read, is restricted, the brief carries the counts without `regression_prs`, as it leaves
that tracker out of its `qa` section. When its classification cannot be read, the brief
leaves them out too and is not stored, so the next read builds it again.

The answer comes first: `verdict` and `verdict_causes`, read off every section the brief
holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict
Expand Down
1 change: 1 addition & 0 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ The regression history of one function: the merged PRs that touched it (with lin
| `review_comments` | `list[dict[str, Any]]` | inline review comments inside the symbol's span, newest first (≤5) |
| `open_issues_naming` | `list[dict[str, Any]]` | open issues whose text names the function (QA), most severe first (≤5) |
| `summary` | `dict[str, Any]` | {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], open_issues_naming, last_touched, oldest_in_window, authors[], note} |
| `regression_prs` | `list[dict[str, Any]]` | Up to 3 PRs behind named_fix_prs, reverts and caused_issues, strongest first, each with its title, merge date, kinds and a code.test_gate query for the tests it changed. |
| `tracker_namespace` | `str` | The tracker namespace that answered the QA side; "" when none is bound or its read failed. |
| `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed. |
| `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. |
Expand Down
1 change: 1 addition & 0 deletions sdk/go/wire/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/python/loom/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8718,6 +8718,7 @@ class CodeSymbolHistoryOutput(TypedDict, total=False):
review_comments: NotRequired[list[dict[str, Any]]]
open_issues_naming: NotRequired[list[dict[str, Any]]]
summary: NotRequired[dict[str, Any]]
regression_prs: NotRequired[list[dict[str, Any]]]
tracker_namespace: NotRequired[str]
tracker_unavailable: NotRequired[bool]
trace_run_id: NotRequired[str]
Expand Down
6 changes: 6 additions & 0 deletions sdk/rust/src/wire_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15764,6 +15764,8 @@ pub struct CodeSymbolHistoryOutput {
pub open_issues_naming: Vec<std::collections::HashMap<String, Value>>,
#[serde(default = "default_code_symbol_history_output_summary")]
pub summary: std::collections::HashMap<String, Value>,
#[serde(default = "default_code_symbol_history_output_regression_prs")]
pub regression_prs: Vec<std::collections::HashMap<String, Value>>,
#[serde(default = "default_code_symbol_history_output_tracker_namespace")]
pub tracker_namespace: String,
#[serde(default = "default_code_symbol_history_output_tracker_unavailable")]
Expand Down Expand Up @@ -69490,6 +69492,10 @@ fn default_code_symbol_history_output_open_issues_naming(
fn default_code_symbol_history_output_summary() -> std::collections::HashMap<String, Value> {
serde_json::from_str("{}").expect("schema default")
}
fn default_code_symbol_history_output_regression_prs(
) -> Vec<std::collections::HashMap<String, Value>> {
serde_json::from_str("[]").expect("schema default")
}
fn default_code_symbol_history_output_tracker_namespace() -> String {
serde_json::from_str("\"\"").expect("schema default")
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/rust/tests/registry_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10697,6 +10697,11 @@ fn code_symbol_history() {
serde_json::from_str::<serde_json::Value>("{}").unwrap(),
"code.symbol_history:summary"
);
assert_eq!(
encoded["regression_prs"],
serde_json::from_str::<serde_json::Value>("[]").unwrap(),
"code.symbol_history:regression_prs"
);
assert_eq!(
encoded["tracker_namespace"],
serde_json::from_str::<serde_json::Value>("\"\"").unwrap(),
Expand Down
1 change: 1 addition & 0 deletions sdk/typescript/src/generated/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,7 @@ export interface CodeSymbolHistoryOutput {
review_comments?: Array<Record<string, unknown>>;
open_issues_naming?: Array<Record<string, unknown>>;
summary?: Record<string, unknown>;
regression_prs?: Array<Record<string, unknown>>;
tracker_namespace?: string;
tracker_unavailable?: boolean;
trace_run_id?: string;
Expand Down
3 changes: 3 additions & 0 deletions server/code/api/models_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ class CodeSymbolHistoryOutput(BaseModel):
# {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[],
# open_issues_naming, last_touched, oldest_in_window, authors[], note}
summary: dict[str, Any] = Field(default_factory=dict)
# Up to 3 PRs behind named_fix_prs, reverts and caused_issues, strongest first, each
# with its title, merge date, kinds and a code.test_gate query for the tests it changed.
regression_prs: list[dict[str, Any]] = Field(default_factory=list)
# The tracker namespace that answered the QA side; "" when none is bound or
# its read failed.
tracker_namespace: str = ""
Expand Down
82 changes: 62 additions & 20 deletions server/code/app/index/review_brief_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,35 @@ def _history_name(name: str, path: str) -> str:
return form if carried else name


# `_tracker_gate`: a tracker the brief may carry rows of, one it may not, and an
# unread classification (closed too, and the brief is not stored, so the next read
# builds it again)
TRACKER_OPEN, TRACKER_CLOSED, TRACKER_UNREAD = "open", "closed", "unread"


async def _tracker_gate(org: str, ns: str, results: list[Any]) -> str:
"""Whether the brief may carry the rows of the tracker namespaces the history records
may rest on: the one bound to the code namespace now (a record whose tracker side
raised names none) and each one a record says it read (the binding may have moved
since). A stored brief is read by every viewer of the code namespace, so as for the
`qa` section, a restricted tracker's rows never enter it."""
from server.auth.directory import ClassificationUnavailable
from server.identity.app.namespace_classification import is_restricted
from server.tracker.app.binding import refresh_overrides, tracker_namespace_for

await refresh_overrides() # the links as of the refresh interval, branches included
trackers = {tracker_namespace_for(org, ns)} | {
str(r.get("tracker_namespace") or "") for r in results if not isinstance(r, BaseException)
}
for tracker in sorted(trackers - {""}):
try:
if await is_restricted(org, tracker):
return TRACKER_CLOSED
except ClassificationUnavailable:
return TRACKER_UNREAD
return TRACKER_OPEN


async def _history_section(
call: CallOp, inp: BriefInputs, defs: list[tuple[str, str]]
) -> dict[str, Any]:
Expand Down Expand Up @@ -922,6 +951,16 @@ async def _history_section(
causes: list[str] = []
unavailable = 0
left = 0 # functions an op refused to read: a cap
# a name that resolved to another file's definition reads as unknown
results = [
r
if isinstance(r, BaseException)
or str((r.get("symbol") or {}).get("path") or "") in ("", path)
else {"verdict": "unknown"}
for (_, path), r in zip(defs, results, strict=True)
]
listed = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results)
gate = await _tracker_gate(inp.org, inp.ns, results) if listed else TRACKER_OPEN
for (name, path), res in zip(defs, results, strict=True):
if isinstance(res, BaseException):
if refused(res):
Expand All @@ -930,26 +969,27 @@ async def _history_section(
degradations.partial("code.review_brief", "symbol_history_failed", res)
causes.append(failure_cause("symbol_history", res))
continue
resolved = str((res.get("symbol") or {}).get("path") or "")
if resolved and resolved != path:
res = {"verdict": "unknown"}
s = dict(res.get("summary") or {})
rows.append(
{
"qualified_name": name,
"path": path,
"verdict": str(res.get("verdict") or "unknown"),
"prs_total": int(s.get("prs_total") or 0),
"fix_prs": int(s.get("fix_prs") or 0),
"named_fix_prs": int(s.get("named_fix_prs") or 0),
"reverts": int(s.get("reverts") or 0),
"caused_issues": len(list(s.get("caused_issues") or [])),
"open_issues_naming": int(s.get("open_issues_naming") or 0),
"last_touched": str(s.get("last_touched") or ""),
"tracker": not bool(res.get("tracker_unavailable"))
and bool(res.get("tracker_namespace")),
}
)
row: dict[str, Any] = {
"qualified_name": name,
"path": path,
"verdict": str(res.get("verdict") or "unknown"),
"prs_total": int(s.get("prs_total") or 0),
"fix_prs": int(s.get("fix_prs") or 0),
"named_fix_prs": int(s.get("named_fix_prs") or 0),
"reverts": int(s.get("reverts") or 0),
"caused_issues": len(list(s.get("caused_issues") or [])),
"open_issues_naming": int(s.get("open_issues_naming") or 0),
"last_touched": str(s.get("last_touched") or ""),
"tracker": not bool(res.get("tracker_unavailable"))
and bool(res.get("tracker_namespace")),
}
prs = list(res.get("regression_prs") or []) if gate == TRACKER_OPEN else []
if prs:
# the PRs behind the counts that make `regressions` (the op names none on a
# row without them), each with its title and the test files it changed
row["regression_prs"] = prs
rows.append(row)
# the tracker is bound and its read failed: the issues it traces are unread
unavailable += bool(res.get("tracker_unavailable"))
rows.sort(
Expand All @@ -966,7 +1006,9 @@ async def _history_section(
epistemic="lower_bound",
causes=causes,
rows=rows,
failed=causes, # every cause here is a read that raised
# every cause here is a read that raised; an unread tracker classification decides
# no verdict, so it keeps the brief unstored without being a cause
failed=[*causes, *(["tracker_classification_unread"] if gate == TRACKER_UNREAD else [])],
note="touch is file-level unless `qa` is true on the row; every count is a floor",
)
_cut(out, NOT_READ, left)
Expand Down
4 changes: 4 additions & 0 deletions server/code/app/symbol_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from server.code.store.index import CodeRepo
from server.core.errors import ValidationError
from server.observability import degradations
from server.settings import settings
from server.tracker.domain import bisect as bi

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -218,6 +219,9 @@ async def handle_code_symbol_history(input: Any) -> Any:
review_comments=span_comments,
open_issues_naming=[_open_issue_view(r) for r in open_issues[:5]],
summary=summary,
regression_prs=sh.regression_prs(
rows, org=org, namespace=ns, run_templates=str(settings.code_test_gate_run_templates)
),
tracker_namespace=tracker_ns,
tracker_unavailable=tracker_unavailable,
trace_run_id=trace_run_id,
Expand Down
Loading
Loading