Skip to content

feat(promote): the runbooks you already have but never wrote down - #29

Merged
matinsaurralde merged 2 commits into
masterfrom
feat/19-mem-promote
Aug 4, 2026
Merged

matinsaurralde merged 2 commits into
masterfrom
feat/19-mem-promote

Conversation

@matinsaurralde

Copy link
Copy Markdown
Owner

mem has two halves that never spoke to each other. It captures everything you type. It also has groups — runbooks you can parameterise and replay — which are the most original thing in the product and are barely used, because creating one means remembering to run mem save, and nobody remembers.

mem promote reads the sequences you already repeat and offers to save them.

Against a fixture of 200 commands — 8 runs of one workflow buried in ad-hoc noise of random length and random order:

   1.      kubectl-logs
           8 times · last 5d ago · strong
           kubectl config use-context $CONFIG_ARG
           helm upgrade api ./chart -n $CONFIG_ARG
           kubectl rollout status deploy/api -n $CONFIG_ARG
           kubectl logs -f deploy/api -n $CONFIG_ARG
           $CONFIG_ARG was staging, prod

           mem promote <n> saves one as a group. It runs nothing.

One workflow found, the namespace extracted as one variable shared across four commands rather than four, the observed values shown, and nothing else proposed.

The measurement that matters

A suggestion engine that proposes junk is dismissed once and never opened again. So it was calibrated on 8 hand-designed 45-day histories (~1,100 commands each): 5 planted workflows against 6 ad-hoc pools generated as random-length, random-order draws — that is what makes work ad-hoc — plus 35% two-activity sessions specifically to invite bad splicing.

false positives workflows surfaced
default listing (5) 0/40 — 0% 88%
at 8 12.5% —
whole mined list (~12) 42% —

The default limit of 5 is load-bearing, not a display preference, and it is commented as such where someone changing it will read it.

Ablation — removing the inspection-command filter: 80% false positives in the top 5, coverage collapses 88% → 15%. That is the measurement that tells the next reader why the filter exists instead of leaving it looking like an arbitrary heuristic. Pinned as a test.

Ranking is occurrences × length, not occurrences. The obvious choice is worse — 88% → 80% coverage — because every prefix of a six-step deploy recurs more often than the deploy does. Also pinned.

Thresholds, each with its reason

  • 3 distinct sessions. mem fix's strong-evidence number. Two is coincidence-compatible: at two the mined pool goes 97 → 223 and its FP rate 42% → 75%. Repetitions inside one session do not count — a build loop is one episode.
  • 300s idle, mirroring SessionTracker, but measured as think time. This was a real defect found on the way: raw timestamps cut every deploy sequence in half at its slowest step, because mem timestamps completion. Third place this has bitten — the shell hooks and mem fix were the others — so it is now written down in the code.
  • 900s max step gap, so removing noise cannot invent adjacency. Length 2–8. At most 2 variables.

"The same sequence" when arguments differ

Commands reduce to a shape where argument positions become holes; a hole with one observed value collapses back to a literal. Never argv[0], never the token after it, never a flag name — that is what separates git checkout main/staging (a branch, one workflow) from git push/pull (different intents). Commands containing shell grammar are never generalised.

Surviving holes group into variables by value vector, not position, which is why one namespace used across four commands comes out as one variable.

The caveat, kept in the README and not just the ADR

Roughly 1 in 8 suggestions is the git add -A; git commit -m ...; git push class: genuine repetition, poor runbook, and indistinguishable from a real workflow from the outside. Better that someone reads we know than concludes the feature is broken.

Nothing is created without confirmation, and nothing is ever executed.

Tests

1450 passed, 91% branch coverage, promote.py at 96%, ruff clean. ADR-012.

…variable already found

mem captures everything and replays named groups, but nothing connected the
two: a group only exists if you remembered to run `mem save` while busy doing
the thing. `mem promote` mines the history instead — sequences recurring
across three separate sessions, with the argument that changed between runs
already turned into a $VAR.

Calibrated on eight hand-designed 45-day histories: 0 false positives in the
default five-candidate listing, 88% of planted workflows surfaced. The
measurements that set the thresholds are pinned as tests, notably that
removing the inspection-command filter takes the false-positive rate to 80%,
and that ranking on occurrences alone puts a deploy's own prefix above the
deploy.

Also fixes a session-splitting defect found on the way: elapsed time was
measured from completion timestamps, so a slow `docker build` read as idle
time and cut every deploy sequence in half at its slowest step.

Refs ADR-012
…is bad

ADR-012 records the calibration rather than asserting a rate: eight
hand-designed 45-day histories, 0/40 false positives in the default listing,
and the three ablations that set the thresholds — the inspection filter (0% ->
80% without it), MIN_OCCURRENCES (mined pool 97 -> 223 at two), and ranking by
occurrences x length rather than occurrences (88% -> 80% workflow coverage).

The README says out loud that mem will sometimes propose the commit dance.
Someone will see it, recognise a poor runbook, and conclude the feature is
broken; better they read that we already know why it happens and cannot tell
from the outside.
@matinsaurralde
matinsaurralde merged commit cb244aa into master Aug 4, 2026
5 checks passed
@matinsaurralde
matinsaurralde deleted the feat/19-mem-promote branch August 4, 2026 05:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1799c28b86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mem/promote.py
Comment on lines +317 to +318
if shape[index] == _HOLE:
return token.start, token.end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve quoting around promoted variables

When a varying argument is quoted, this span includes the quote characters, so promotion rewrites examples such as git commit -m "release one" into git commit -m $COMMIT_ARG. mem run executes the template through a shell and supplies the variable through the environment, meaning an unquoted value containing spaces is split into multiple arguments and wildcard characters may expand. Preserve shell-safe quoting when replacing a quoted token so the promoted command retains the original argument semantics.

Useful? React with 👍 / 👎.

Comment thread src/mem/cli.py
Comment on lines +643 to +644
for step in candidate.steps:
saved, _vars = groups.save_command(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve repeated steps when saving a candidate

If a mined workflow legitimately contains the same command more than once, this loop passes each occurrence through groups.save_command, whose group path returns False whenever that command already exists in the group. A sequence such as make test; deploy; make test is therefore confirmed as three commands but stored with only the first make test, silently changing the runbook and causing it to be suggested again because the saved step list no longer matches. Save the candidate as an ordered sequence without applying the bookmark-style duplicate suppression.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant