r/devops7 • u/Alternative_Pin9598 • 6d ago
One script, one chore: 6 of 12 runbook lines contradict the inventory. Similarity can't tell which (a stale line scores highest, 0.95); one SQL query with an NLI check finds them (real output)
Short one this week: one script, one chore, real output. (This sub is run by the SynapCores team.)
The chore
Runbooks rot. The failover runbook says the orders primary is db-1 in us-east-1. Terraform has said db-3 in us-east-2 since the migration. You find out at 3 a.m., halfway through the failover.
Every runbook line gets a verdict: STALE (the inventory contradicts it), OK (it backs it up) or REVIEW.
Step 1: two files, two tables
facts.txt holds 8 facts rendered from what you trust (Terraform outputs, the CMDB); runbook.txt holds 12 claims from 4 runbooks. Both samples are in the first comment:
The orders database primary is db-3 in us-east-2.
db-failover.md: The orders primary is db-1 in us-east-1.Both go into tables, embedded on the way in:
INSERT INTO rb_facts VALUES (1, 'The orders database primary is db-3 in us-east-2.',
EMBED('The orders database primary is db-3 in us-east-2.')), ...Step 2, the payoff: one query
Similarity pairs each line with its closest fact; then NLI_CLASSIFY (a natural language inference model inside the engine) reads the pair and scores entailment (e: the fact backs the line up) and contradiction (c).
SELECT fid, fact, doc, line, ROUND(sim, 2) AS sim, ROUND(e, 2) AS e, ROUND(c, 2) AS c,
CASE WHEN sim < 0.5 THEN 'REVIEW' WHEN c > 0.5 THEN 'STALE'
WHEN e > 0.5 THEN 'OK' ELSE 'REVIEW' END AS verdict
FROM (SELECT fid, fact, doc, line, sim,
JSON_EXTRACT(NLI_CLASSIFY('nli-default', fact, line), '$.scores.entailment') AS e,
JSON_EXTRACT(NLI_CLASSIFY('nli-default', fact, line), '$.scores.contradiction') AS c
FROM (SELECT f.id AS fid, f.fact, r.doc, r.line, COSINE_SIMILARITY(r.emb, f.emb) AS sim,
ROW_NUMBER() OVER (PARTITION BY r.id ORDER BY COSINE_SIMILARITY(r.emb, f.emb) DESC) AS rn
FROM rb_runbook r CROSS JOIN rb_facts f) best
WHERE rn = 1) checked
ORDER BY fid, sim DESCOutput of rotcheck.py (sim = similarity to the fact):
fact: The orders database primary is db-3 in us-east-2.
0.90 STALE e 0.00 c 0.99 db-failover.md The orders primary is db-1 in us-east-1.
0.73 OK e 1.00 c 0.00 db-restore.md Primary: db-3 (us-east-2).
0.37 REVIEW e 0.00 c 0.01 db-failover.md Escalate to the DBA team in #dba-help.
fact: orders-db backups run every 6 hours.
0.88 STALE e 0.00 c 1.00 db-failover.md orders-db is backed up every 24 hours.
0.86 REVIEW e 0.02 c 0.01 db-restore.md Backups run every 6 hours, so you can lose up to 6 hours of orders.
0.25 REVIEW e 0.00 c 1.00 checkout.md Keep the incident doc updated every 30 minutes.
fact: The edge nginx listens on port 8443.
0.80 STALE e 0.00 c 1.00 edge-tls.md Edge nginx listens on port 443.
fact: The session Redis runs version 7.2.
0.95 STALE e 0.00 c 1.00 checkout.md Session Redis is version 6.2.
fact: The checkout on-call channel is #checkout-oncall.
0.84 OK e 0.99 c 0.00 checkout.md Reach the checkout on-call in #checkout-oncall.
fact: TLS certificates are issued by cert-manager with Let's Encrypt.
0.88 OK e 1.00 c 0.00 edge-tls.md Certificates come from cert-manager with Let's Encrypt.
0.62 STALE e 0.00 c 0.98 edge-tls.md TLS certificates are renewed by hand with certbot on the edge box.
fact: Deploys go through Argo CD.
0.65 STALE e 0.00 c 1.00 checkout.md Deploys go out through Jenkins.
6 of 12 runbook lines contradict the inventory, 3 OK, 3 to reviewLook at the sim column. The stale db-1 line scores 0.90 against the primary fact, the current "Primary: db-3" line 0.73, and the most similar line of all (Redis 6.2, 0.95) is stale. Similarity finds the fact a line is about; whether the line agrees with it is the question NLI models are trained for.
REVIEW means a human looks: one line adds a claim the inventory can't confirm, two aren't about any fact. The 0.5 similarity floor comes first, so only pairs about the same thing reach NLI.
Why one database? Embeddings, pairing and the NLI check all run where the tables are: no embedding API, no NLI model server, no glue code.
Run it after each Terraform apply and send each STALE line to the runbook's owner. rotcheck.py (stdlib only) is in the first comment.
Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-one-script-7
How do you catch stale runbooks today: a "last reviewed" date, game days, or the 3 a.m. page?
1
u/Alternative_Pin9598 6d ago
rotcheck.py (standard library only; set
SC_URLandSC_TOKEN). Run:python3 rotcheck.py facts.txt runbook.txtNLI is a one-time opt-in:
synapcores pull nli-default(about 577 MB), thensynapcores models enable-nli nli-default, both with the--configyour service uses, then restart the server.facts.txt (one sentence per inventory fact):
runbook.txt (
file.md: text, one statement per line):Want the idea behind the NLI step? Recipe of the week #2 on r/synapcores checks new agent memories against old ones the same way: https://www.reddit.com/r/synapcores/comments/1xru0wg/
The pairing step (CROSS JOIN + ROW_NUMBER by similarity, then a floor) is today's SQLv2 Lesson 8, step by step: https://www.reddit.com/r/SQLv2/comments/1xzhmki/