-
Notifications
You must be signed in to change notification settings - Fork 829
feat(runbooks): local runbook store with runbook-aware diagnosis grounding (#1073 phase 2a) #2029
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
Open
devankitjuneja
wants to merge
12
commits into
Tracer-Cloud:main
Choose a base branch
from
devankitjuneja:feature/1073-phase-2a-runbook-store
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7163588
feat(runbooks): runbook-aware diagnosis grounding (#1073 phase 2a)
6e0474a
feat(runbooks): port phase 2a to ReAct agent architecture
14d9508
fix(runbooks): drop banned docstring ref, fix keyword filter, use pub…
e55f5e6
fix(tests): avoid assert side-effects flagged by CodeQL
21ed076
Update tests/synthetic/runbooks/test_runbook_suite.py
devankitjuneja 6ab2a18
fix(runbooks): match multi-word triggers by checking all tokens present
c7f3d8e
fix(runbooks): sanitize slug in remove(), fix frontmatter regex, avoi…
66fdb02
fix(runbooks): validate slug in save(), clean truncation boundary, gu…
e000f9f
fix(runbooks): catch ValueError in remove command, show clean error i…
5505ea2
fix(runbooks): handle null commonLabels in alert_json to preserve key…
cfc1041
chore: merge upstream/main, resolve conflicts, update runbook dir to …
8202df4
fix(runbooks): add /runbook to slash catalog, fix description parity
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
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,58 @@ | ||
| """``opensre runbook`` CLI group — manage local diagnosis runbooks.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import click | ||
|
|
||
| from app.runbooks.store import ( | ||
| RUNBOOK_DIR, | ||
| RunbookValidationError, | ||
| load_all, | ||
| remove, | ||
| save, | ||
| ) | ||
|
|
||
|
|
||
| @click.group(name="runbook") | ||
| def runbook() -> None: | ||
| """Manage local runbooks that ground diagnosis remediation steps.""" | ||
|
|
||
|
|
||
| @runbook.command("add") | ||
| @click.argument("path", type=click.Path(exists=True, dir_okay=False, path_type=Path)) | ||
| def runbook_add(path: Path) -> None: | ||
| """Copy a markdown runbook into ~/.opensre/runbooks/.""" | ||
| try: | ||
| stored = save(path) | ||
| except RunbookValidationError as exc: | ||
| raise click.ClickException(str(exc)) from exc | ||
| click.echo(f"✓ Saved runbook '{stored.slug}' to {stored.path}") | ||
|
|
||
|
|
||
| @runbook.command("list") | ||
| def runbook_list() -> None: | ||
| """List runbooks currently in the local store.""" | ||
| runbooks = load_all() | ||
| if not runbooks: | ||
| click.echo(f"No runbooks found in {RUNBOOK_DIR}") | ||
| return | ||
| for rb in runbooks: | ||
| service = rb.service or "-" | ||
| triggers = ", ".join(rb.triggers) | ||
| click.echo(f"{rb.slug} service={service} triggers=[{triggers}]") | ||
|
|
||
|
|
||
| @runbook.command("remove") | ||
| @click.argument("slug") | ||
| def runbook_remove(slug: str) -> None: | ||
| """Delete a runbook by slug (the filename without .md).""" | ||
| try: | ||
| found = remove(slug) | ||
| except (ValueError, RunbookValidationError) as exc: | ||
| raise click.ClickException(str(exc)) from exc | ||
| if found: | ||
| click.echo(f"✓ Removed runbook '{slug}'") | ||
| return | ||
| raise click.ClickException(f"no runbook with slug '{slug}' in {RUNBOOK_DIR}") | ||
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
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
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,21 @@ | ||
| """Local runbook store + retrieval used to ground diagnosis remediation steps.""" | ||
|
|
||
| from app.runbooks.retrieval import retrieve_matching_runbook | ||
| from app.runbooks.store import ( | ||
| RUNBOOK_DIR, | ||
| Runbook, | ||
| RunbookValidationError, | ||
| load_all, | ||
| remove, | ||
| save, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "RUNBOOK_DIR", | ||
| "Runbook", | ||
| "RunbookValidationError", | ||
| "load_all", | ||
| "remove", | ||
| "retrieve_matching_runbook", | ||
| "save", | ||
| ] |
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,71 @@ | ||
| """Deterministic top-1 runbook retrieval. | ||
|
|
||
| Pure scoring — no disk I/O, no LLM calls. The caller is responsible for | ||
| loading the candidate runbooks (see ``app.runbooks.store.load_all``) and for | ||
| producing keyword/service inputs from the current alert state. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from app.runbooks.store import Runbook | ||
|
|
||
|
|
||
| def _score( | ||
| runbook: Runbook, | ||
| keyword_set: frozenset[str], | ||
| service: str | None, | ||
| pipeline_name: str | None, | ||
| ) -> int: | ||
| """Score a single runbook against the current alert. | ||
|
|
||
| +2 when ``runbook.service`` matches the alert service or pipeline name. | ||
| +1 for each shared trigger keyword. | ||
| """ | ||
| service_score = 0 | ||
| if runbook.service: | ||
| rb_service = runbook.service.lower() | ||
| if (service and rb_service == service.lower()) or ( | ||
| pipeline_name and rb_service == pipeline_name.lower() | ||
| ): | ||
| service_score = 2 | ||
|
|
||
| keyword_overlap = sum( | ||
| 1 | ||
| for trigger in runbook.triggers | ||
| if (parts := trigger.lower().split()) and all(p in keyword_set for p in parts) | ||
| ) | ||
| return service_score + keyword_overlap | ||
|
|
||
|
|
||
| def retrieve_matching_runbook( | ||
| runbooks: list[Runbook], | ||
| keywords: list[str], | ||
| service: str | None, | ||
| pipeline_name: str | None, | ||
| ) -> Runbook | None: | ||
| """Return the top-1 runbook by score, or ``None`` when nothing matches. | ||
|
|
||
| Ties broken by slug (sorted ascending) for deterministic output. | ||
| """ | ||
| if not runbooks: | ||
| return None | ||
|
|
||
| keyword_set = frozenset(k.lower() for k in keywords if k) | ||
| best: tuple[int, str] | None = None | ||
| winner: Runbook | None = None | ||
|
|
||
| for runbook in runbooks: | ||
| score = _score(runbook, keyword_set, service, pipeline_name) | ||
| if score <= 0: | ||
| continue | ||
| candidate = (score, runbook.slug) | ||
| # Higher score wins; on tie, lexicographically smaller slug wins. | ||
| if ( | ||
| best is None | ||
| or candidate[0] > best[0] | ||
| or (candidate[0] == best[0] and candidate[1] < best[1]) | ||
| ): | ||
| best = candidate | ||
| winner = runbook | ||
|
|
||
| return winner |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.