Skip to content

Commit 4667deb

Browse files
feat(learning): migrate retrospective to daily rolling-PR model + bump engine (#245)
## What Migrate the engineer-bot **learning (retrospective)** flow from the legacy per-PR model to the engine's current **daily cron + adaptive-cursor** model, and bump the engine pin so the invocation matches the engine it runs against. Three coupled changes: | File | Change | |---|---| | `.github/actions/bot-prelude/action.yml` | Bump `engine-ref` default `92b3857` → `654a31d0` (engine `main`, 61 commits). **SHA-only** — the locked SDK/CLI (`0.2.102` / `2.1.61`) are unchanged at that SHA. | | `.github/workflows/engineer-bot-learning.yml` | Rewrite trigger + invocation (see below). | | `.bot/config.yaml` | Close the loop + prune a dead key. | ## Why these are coupled The modern `retrospective.py` (at the bump target) is invoked as a **windowed multi-PR sweep** (`--window-hours` / `--since`, adaptive cursor) that gathers each merged PR's diff and comments *itself*. This repo's workflow was still the old shape: `pull_request: [closed]` gated on `merged` + an `extract-learning` label, with a manual step that hand-gathered a single PR's context into `pr_diff.txt` / `review_comments.txt`. Bumping the engine without migrating the trigger would leave a modern engine driven by a legacy trigger; migrating the trigger without the bump would call flags the pinned engine doesn't have. So they land together. ## Workflow changes - **Trigger:** `pull_request: [closed]` → `schedule` (`17 7 * * *`, off-peak/off-:00) + `workflow_dispatch` with string `since` / `window-hours` recovery inputs (string, not number — a number-typed dispatch input fails the whole run at startup when the workflow also triggers on schedule). - **Drop** the "Gather merged-PR context" step — obsolete; the engine now gathers per-PR context over the window (`gather_pr_context`). - **Invocation:** `retrospective --repo-dir "$GITHUB_WORKSPACE" --window-hours "$WINDOW_HOURS"`, appending `--since` only when non-empty. - **Add `actions: read`** — Track B lists engineer-bot author runs + downloads their logs via the App token; without this scope the step 403s and fails the whole run. - Fixed `concurrency.group` (no PR number on a scheduled run). ## Config changes - **Close the loop:** add `author.knowledge_log: .claude/knowledge/learning-log.md`, matching `retrospective.log_path`. The retrospective *writes* that path; the author phase only *reads* it back when the two agree — so fixes benefit from what's been learned. It was previously half-open (learnings written, never read back). - **Remove** the now-dead `retrospective.context_files` key (the windowed sweep ignores it) and refresh the block comments. ## Validation - Both YAML files parse; `author.knowledge_log` == `retrospective.log_path` (verified); no lingering `github.event.pull_request.*` in active logic; trigger/inputs shape matches the engine's own `engineer-bot-learning-cron.yml`. - The `schedule` registers only once this lands on the default branch. Before the first cron, the flow can be exercised via a manual **workflow_dispatch** with a recent `since` — it should open/update the rolling `ai/learning-pr-*` PR. This pull request and its description were written by Isaac. --------- Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
1 parent 3ea1c3b commit 4667deb

3 files changed

Lines changed: 79 additions & 62 deletions

File tree

‎.bot/config.yaml‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ author:
7777
issue_url: ISSUE_URL
7878
context_files:
7979
- issue_body.txt # {{issue_body}}
80+
# Close the loop: the author phase reads this log back so fixes benefit from
81+
# what the retrospective has learned. MUST match `retrospective.log_path` below
82+
# — the retrospective WRITES that path; the author only READS it if the two
83+
# agree. (Set together, they connect learning → application.)
84+
knowledge_log: .claude/knowledge/learning-log.md
8085

8186
# Engine orchestration for the author phase. `bug-fix` runs the plan → author_tests
8287
# → fix pipeline (write a failing test → fix the code → re-run to green) and forces
@@ -85,17 +90,15 @@ author:
8590
# layout, live-E2E discipline) live in prompts/engineer/system.md, not here.
8691
flow: bug-fix
8792

88-
# On-merge learning extraction (retrospective flow). Run by engineer-bot-learning.yml
89-
# via `python -m databricks_bot_engine.engineer_bot.retrospective`: it reads the PR
90-
# diff + review comments (gathered by the workflow into the context_files below), and
91-
# if the model finds a durable, reusable learning, opens a PR appending it to
92-
# log_path. Human-gated — never commits the canonical log directly. Omitting this
93-
# block makes the retrospective a no-op.
93+
# Daily learning extraction (retrospective flow). Run by engineer-bot-learning.yml
94+
# via `python -m databricks_bot_engine.engineer_bot.retrospective`: over an adaptive
95+
# look-back window it sweeps every merged PR (diff + review comments, which the
96+
# engine gathers ITSELF per PR) plus engineer-bot author runs, and if the model
97+
# finds a durable, reusable learning, opens/updates a single rolling PR appending a
98+
# dated section to log_path. Human-gated — never commits the canonical log directly.
99+
# Omitting this block makes the retrospective a no-op.
94100
retrospective:
95101
system_prompt: prompts/retrospective_system.md
96-
log_path: .claude/knowledge/learning-log.md
97-
context_files: # workflow-gathered files the engine inlines into the prompt
98-
- pr_diff.txt
99-
- review_comments.txt
102+
log_path: .claude/knowledge/learning-log.md # author.knowledge_log matches this
100103
branch_prefix: ai/learning-pr-
101104
pr_label: engineer-bot-learning

‎.github/actions/bot-prelude/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ inputs:
3232
# move every bot to a new engine commit; never @main.
3333
description: 'Engine commit SHA (full 40-char) to install.'
3434
required: false
35-
default: '92b3857996b2fbac5d0573ea89db6be9f0c48b9a'
35+
default: '654a31d0d26d2b77bcb58e84f1e4abe018f9fd5a'
3636
engine-repo:
3737
description: 'owner/name of the engine repo.'
3838
required: false
Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
1-
# Engineer Bot — learning (retrospective) extraction.
1+
# Engineer Bot — learning (retrospective) extraction, DAILY.
22
#
3-
# On merge of a PR labelled `extract-learning`, the bot reads the merged PR's diff
4-
# + review comments, decides whether there's a DURABLE, reusable engineering
5-
# learning, and — if so — opens a PR appending an entry to this repo's learning log
3+
# Once a day the bot sweeps every PR merged in an adaptive look-back window (plus
4+
# engineer-bot author runs in that window), decides whether there is a DURABLE,
5+
# reusable engineering learning, and — if so — opens/updates a single rolling PR
6+
# appending a dated section to this repo's learning log
67
# (.claude/knowledge/learning-log.md). Human-gated by design: it NEVER commits the
78
# canonical log directly; the entry lands as a reviewable PR.
89
#
10+
# The window is an ISO adaptive cursor: `since` defaults to the start time of the
11+
# last successful run, falling back to `--window-hours` (24) on the first run or
12+
# when the Actions API is unavailable. A failed or missed run does NOT advance the
13+
# cursor, so the next run automatically widens to cover the gap — no per-PR label
14+
# or per-merge trigger needed. (This REPLACES the old per-PR `extract-learning`
15+
# on-merge model: the engine now gathers each PR's diff/comments itself over the
16+
# window, so there is no manual context-gather step and no `context_files`.)
17+
#
918
# Own job (NOT `uses: databricks/databricks-bot-engine/...`): an external repo
1019
# can't resolve the internal engine's reusable workflows ("not found"). It shares
1120
# the SAME prelude the other bots use — ./.github/actions/bot-prelude (tokens +
1221
# Node + pinned engine install) — so the engine pin stays single-sourced in
1322
# bot-prelude's `engine-ref` default (no second SHA to drift). What's unique to
14-
# this flow stays inline: the default-branch checkout the learning PR is cut from,
15-
# the bot git identity, and the merged-PR context gather.
23+
# this flow stays inline: the default-branch checkout the learning PR is cut from
24+
# and the authenticated push remote.
1625
#
1726
# Opt-in is purely via the `retrospective:` block in .bot/config.yaml + this
1827
# workflow; absent that block the engine phase is a clean no-op.
1928
name: Engineer Bot — Learning
2029

2130
on:
22-
pull_request:
23-
types: [closed]
31+
schedule:
32+
# 07:17 UTC daily — off-peak, off-:00 minute (GitHub delays/drops on-the-hour
33+
# crons). Scheduled runs fire only on the default branch.
34+
- cron: "17 7 * * *"
35+
workflow_dispatch:
36+
inputs:
37+
# Manual-recovery knobs surfaced by the retrospective's failure messages: a
38+
# wedged flow (CatchUpBacklogError / CursorReadError) is recovered by
39+
# re-dispatching with a recent `since`.
40+
since:
41+
description: 'ISO lower bound to bound (shorten) the window and recover a wedged flow. Empty = adaptive cursor.'
42+
type: string
43+
default: ''
44+
window-hours:
45+
# STRING, not number: a `type: number` dispatch input fails the whole run
46+
# at startup when the workflow also triggers on `schedule`. argparse
47+
# coerces it to int downstream (retrospective.py, `type=int`), so string is
48+
# correct here (mirrors the engine's own learning-cron workflow).
49+
description: 'Fallback look-back window (hours) used only when there is no prior successful run.'
50+
type: string
51+
default: '24'
2452

2553
permissions:
2654
contents: write # open the learning-log PR
2755
pull-requests: write
56+
actions: read # Track B lists author runs + downloads their logs via the
57+
# App token; without actions:read that step 403s and fails
58+
# the whole run (no permission escape hatch).
2859
id-token: write # JFrog OIDC exchange for the engine/SDK/CLI install
2960

61+
concurrency:
62+
# Fixed key (no PR number — this is schedule/dispatch driven). cancel-in-progress
63+
# false so a manual recovery dispatch doesn't kill an in-flight scheduled run.
64+
group: engineer-bot-learning-cron
65+
cancel-in-progress: false
66+
3067
jobs:
3168
learning:
32-
# Only on MERGE (not a plain close) of a PR carrying `extract-learning`, and
33-
# never on the learning bot's own PR (head ref ai/learning-pr-*) — that would
34-
# loop.
35-
if: >-
36-
github.event.pull_request.merged == true
37-
&& contains(github.event.pull_request.labels.*.name, 'extract-learning')
38-
&& !startsWith(github.event.pull_request.head.ref, 'ai/learning-pr-')
3969
environment: azure-prod # DATABRICKS_HOST / DATABRICKS_TOKEN live here
4070
runs-on:
4171
group: databricks-protected-runner-group
4272
labels: linux-ubuntu-latest
4373
timeout-minutes: 20
44-
concurrency:
45-
group: engineer-bot-learning-pr-${{ github.event.pull_request.number }}
46-
cancel-in-progress: false
4774
steps:
4875
# Checkout the default branch (the learning PR is cut from it) FIRST, so the
4976
# local `./` composites below resolve. persist-credentials:false — the
@@ -79,50 +106,37 @@ jobs:
79106
app-id: ${{ secrets.ENGINEER_BOT_APP_ID }}
80107
private-key: ${{ secrets.ENGINEER_BOT_APP_PRIVATE_KEY }}
81108

82-
# NOTE: no git-identity step here. The engine's retrospective
83-
# (databricks-bot-engine#139, in the pinned engine SHA) configures the git
84-
# user AND DCO sign-off itself from .bot/config.yaml `bot_login_prefix` —
109+
# NOTE: no git-identity step here. The engine's retrospective configures the
110+
# git user AND DCO sign-off itself from .bot/config.yaml `bot_login_prefix` —
85111
# same as the author/followup flows — so the learning commit is authored and
86-
# signed as the bot without the workflow doing it. (Before #139 this flow had
87-
# to hand-roll the identity; the engine bump removed that need.)
88-
89-
- name: Gather merged-PR context
90-
env:
91-
GH_TOKEN: ${{ steps.prelude.outputs.token }}
92-
REPO: ${{ github.repository }}
93-
PR: ${{ github.event.pull_request.number }}
94-
run: |
95-
set -euo pipefail
96-
# Write the gathered context into the checkout (the engine's repo_dir /
97-
# cwd) under the filenames the .bot/config.yaml `retrospective.context_files`
98-
# resolves against repo_dir (`pr_diff.txt`, `review_comments.txt`); the
99-
# engine inlines those into the prompt.
100-
{ gh pr diff "$PR" --repo "$REPO" || true; } \
101-
| head -c 32000 > "$GITHUB_WORKSPACE/pr_diff.txt"
102-
{ gh api --paginate "/repos/$REPO/pulls/$PR/comments" \
103-
--jq '.[] | "\(.path):\(.line // .original_line) \(.user.login): \(.body)"' || true; } \
104-
| head -c 32000 > "$GITHUB_WORKSPACE/review_comments.txt"
112+
# signed as the bot without the workflow doing it.
105113

106-
- name: Extract learning + open PR
114+
- name: Extract daily learnings + open/update PR
107115
env:
108116
GH_TOKEN: ${{ steps.prelude.outputs.token }}
109117
GITHUB_REPOSITORY: ${{ github.repository }}
110-
PR_NUMBER: ${{ github.event.pull_request.number }}
111-
PR_TITLE: ${{ github.event.pull_request.title }}
112-
PR_URL: ${{ github.event.pull_request.html_url }}
113-
# Only the `<workspace>/serving-endpoints/` prefix matters:
114-
# sdk_agent.translate_endpoint rewrites this to `.../serving-endpoints/anthropic`
115-
# and discards the model path segment. The effective model comes from
116-
# .bot/config.yaml `retrospective.model` (or the engine default).
117-
MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/anthropic/invocations
118+
# Use the concrete `.../serving-endpoints/<model>/invocations` form (same
119+
# as reviewer-bot.yml / engineer-bot.yml). sdk_agent.translate_endpoint
120+
# strips it to the `.../serving-endpoints/anthropic` base the CLI needs.
121+
# Do NOT use `.../serving-endpoints/anthropic/invocations` here: that hits
122+
# translate_endpoint's already-v2 early-return, which keeps the trailing
123+
# `invocations`, so the CLI appends `/v1/messages` →
124+
# `.../anthropic/invocations/v1/messages` → HTTP 400 (unsupported path).
125+
# The effective model is set by the engine default (no retrospective.model).
126+
MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/databricks-claude-opus-4-8/invocations
118127
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
128+
WINDOW_HOURS: ${{ inputs.window-hours || '24' }}
129+
SINCE: ${{ inputs.since || '' }}
119130
RUNNER_TEMP: ${{ runner.temp }}
120131
# The retrospective pushes the learning branch with a plain `git push
121132
# origin` (no in-module set-url), and the checkout ran persist-credentials:
122133
# false — so set an authenticated push remote from the minted App token
123134
# first, mirroring engineer-bot.yml's publish step. retrospective.py
124135
# resolves repo_dir from --repo-dir (cwd = $GITHUB_WORKSPACE otherwise),
125-
# where .bot/ + the gathered context files live.
136+
# where .bot/ lives.
126137
run: |
138+
set -euo pipefail
127139
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
128-
python -m databricks_bot_engine.engineer_bot.retrospective --repo-dir "$GITHUB_WORKSPACE"
140+
args=(--repo-dir "$GITHUB_WORKSPACE" --window-hours "$WINDOW_HOURS")
141+
[ -n "$SINCE" ] && args+=(--since "$SINCE")
142+
python -m databricks_bot_engine.engineer_bot.retrospective "${args[@]}"

0 commit comments

Comments
 (0)