From 47bdf2bcb4653b026c7bfd5945895781b1975a4a Mon Sep 17 00:00:00 2001 From: eric-wang-1990 Date: Wed, 12 Aug 2026 17:52:40 -0700 Subject: [PATCH 1/2] feat(learning): migrate retrospective to the daily rolling-PR model + bump engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The engine's retrospective flow moved from a per-PR, on-merge, label-gated model to a daily cron + adaptive-cursor window sweep. This repo was still on the legacy shape end to end. Migrate it, and bump the engine pin so the new invocation matches the engine it runs against. - bot-prelude: bump engine-ref 92b3857 -> 654a31d0 (engine main; 61 commits). The locked SDK/CLI (0.2.102 / 2.1.61) are unchanged at that SHA, so this is a SHA-only bump — no install-bot-engine edit needed. - engineer-bot-learning.yml: replace `pull_request: [closed]` (gated on merged + `extract-learning`) with `schedule` (07:17 UTC, off-peak/off-:00) + `workflow_dispatch` (string `since` / `window-hours` recovery inputs). Drop the now-obsolete "Gather merged-PR context" step — the modern retrospective gathers each PR's diff/comments itself over the window (gather_pr_context). Invoke with `--window-hours` (and `--since` when non-empty). Add `actions: read` (Track B lists author runs + downloads their logs via the App token; without it the run 403s and fails). Fixed concurrency group (no PR number on a scheduled run). - .bot/config.yaml: close the loop — add `author.knowledge_log` matching `retrospective.log_path` (.claude/knowledge/learning-log.md), so the author phase reads back what the retrospective learns. Remove the dead `retrospective.context_files` key (the windowed sweep ignores it) and refresh the block comments to describe the multi-PR window model. The schedule registers only once this lands on the default branch; the flow can be validated before the first cron via a manual workflow_dispatch with a recent `since`. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 --- .bot/config.yaml | 23 +++-- .github/actions/bot-prelude/action.yml | 2 +- .github/workflows/engineer-bot-learning.yml | 102 +++++++++++--------- 3 files changed, 70 insertions(+), 57 deletions(-) diff --git a/.bot/config.yaml b/.bot/config.yaml index f5c23871..9f4e4941 100644 --- a/.bot/config.yaml +++ b/.bot/config.yaml @@ -77,6 +77,11 @@ author: issue_url: ISSUE_URL context_files: - issue_body.txt # {{issue_body}} + # Close the loop: the author phase reads this log back so fixes benefit from + # what the retrospective has learned. MUST match `retrospective.log_path` below + # — the retrospective WRITES that path; the author only READS it if the two + # agree. (Set together, they connect learning → application.) + knowledge_log: .claude/knowledge/learning-log.md # Engine orchestration for the author phase. `bug-fix` runs the plan → author_tests # → fix pipeline (write a failing test → fix the code → re-run to green) and forces @@ -85,17 +90,15 @@ author: # layout, live-E2E discipline) live in prompts/engineer/system.md, not here. flow: bug-fix -# On-merge learning extraction (retrospective flow). Run by engineer-bot-learning.yml -# via `python -m databricks_bot_engine.engineer_bot.retrospective`: it reads the PR -# diff + review comments (gathered by the workflow into the context_files below), and -# if the model finds a durable, reusable learning, opens a PR appending it to -# log_path. Human-gated — never commits the canonical log directly. Omitting this -# block makes the retrospective a no-op. +# Daily learning extraction (retrospective flow). Run by engineer-bot-learning.yml +# via `python -m databricks_bot_engine.engineer_bot.retrospective`: over an adaptive +# look-back window it sweeps every merged PR (diff + review comments, which the +# engine gathers ITSELF per PR) plus engineer-bot author runs, and if the model +# finds a durable, reusable learning, opens/updates a single rolling PR appending a +# dated section to log_path. Human-gated — never commits the canonical log directly. +# Omitting this block makes the retrospective a no-op. retrospective: system_prompt: prompts/retrospective_system.md - log_path: .claude/knowledge/learning-log.md - context_files: # workflow-gathered files the engine inlines into the prompt - - pr_diff.txt - - review_comments.txt + log_path: .claude/knowledge/learning-log.md # author.knowledge_log matches this branch_prefix: ai/learning-pr- pr_label: engineer-bot-learning diff --git a/.github/actions/bot-prelude/action.yml b/.github/actions/bot-prelude/action.yml index c5504e01..081386d4 100644 --- a/.github/actions/bot-prelude/action.yml +++ b/.github/actions/bot-prelude/action.yml @@ -32,7 +32,7 @@ inputs: # move every bot to a new engine commit; never @main. description: 'Engine commit SHA (full 40-char) to install.' required: false - default: '92b3857996b2fbac5d0573ea89db6be9f0c48b9a' + default: '654a31d0d26d2b77bcb58e84f1e4abe018f9fd5a' engine-repo: description: 'owner/name of the engine repo.' required: false diff --git a/.github/workflows/engineer-bot-learning.yml b/.github/workflows/engineer-bot-learning.yml index bf0b26cc..72866aff 100644 --- a/.github/workflows/engineer-bot-learning.yml +++ b/.github/workflows/engineer-bot-learning.yml @@ -1,49 +1,76 @@ -# Engineer Bot — learning (retrospective) extraction. +# Engineer Bot — learning (retrospective) extraction, DAILY. # -# On merge of a PR labelled `extract-learning`, the bot reads the merged PR's diff -# + review comments, decides whether there's a DURABLE, reusable engineering -# learning, and — if so — opens a PR appending an entry to this repo's learning log +# Once a day the bot sweeps every PR merged in an adaptive look-back window (plus +# engineer-bot author runs in that window), decides whether there is a DURABLE, +# reusable engineering learning, and — if so — opens/updates a single rolling PR +# appending a dated section to this repo's learning log # (.claude/knowledge/learning-log.md). Human-gated by design: it NEVER commits the # canonical log directly; the entry lands as a reviewable PR. # +# The window is an ISO adaptive cursor: `since` defaults to the start time of the +# last successful run, falling back to `--window-hours` (24) on the first run or +# when the Actions API is unavailable. A failed or missed run does NOT advance the +# cursor, so the next run automatically widens to cover the gap — no per-PR label +# or per-merge trigger needed. (This REPLACES the old per-PR `extract-learning` +# on-merge model: the engine now gathers each PR's diff/comments itself over the +# window, so there is no manual context-gather step and no `context_files`.) +# # Own job (NOT `uses: databricks/databricks-bot-engine/...`): an external repo # can't resolve the internal engine's reusable workflows ("not found"). It shares # the SAME prelude the other bots use — ./.github/actions/bot-prelude (tokens + # Node + pinned engine install) — so the engine pin stays single-sourced in # bot-prelude's `engine-ref` default (no second SHA to drift). What's unique to -# this flow stays inline: the default-branch checkout the learning PR is cut from, -# the bot git identity, and the merged-PR context gather. +# this flow stays inline: the default-branch checkout the learning PR is cut from +# and the authenticated push remote. # # Opt-in is purely via the `retrospective:` block in .bot/config.yaml + this # workflow; absent that block the engine phase is a clean no-op. name: Engineer Bot — Learning on: - pull_request: - types: [closed] + schedule: + # 07:17 UTC daily — off-peak, off-:00 minute (GitHub delays/drops on-the-hour + # crons). Scheduled runs fire only on the default branch. + - cron: "17 7 * * *" + workflow_dispatch: + inputs: + # Manual-recovery knobs surfaced by the retrospective's failure messages: a + # wedged flow (CatchUpBacklogError / CursorReadError) is recovered by + # re-dispatching with a recent `since`. + since: + description: 'ISO lower bound to bound (shorten) the window and recover a wedged flow. Empty = adaptive cursor.' + type: string + default: '' + window-hours: + # STRING, not number: a `type: number` dispatch input fails the whole run + # at startup when the workflow also triggers on `schedule`. argparse + # coerces it to int downstream (retrospective.py, `type=int`), so string is + # correct here (mirrors the engine's own learning-cron workflow). + description: 'Fallback look-back window (hours) used only when there is no prior successful run.' + type: string + default: '24' permissions: contents: write # open the learning-log PR pull-requests: write + actions: read # Track B lists author runs + downloads their logs via the + # App token; without actions:read that step 403s and fails + # the whole run (no permission escape hatch). id-token: write # JFrog OIDC exchange for the engine/SDK/CLI install +concurrency: + # Fixed key (no PR number — this is schedule/dispatch driven). cancel-in-progress + # false so a manual recovery dispatch doesn't kill an in-flight scheduled run. + group: engineer-bot-learning-cron + cancel-in-progress: false + jobs: learning: - # Only on MERGE (not a plain close) of a PR carrying `extract-learning`, and - # never on the learning bot's own PR (head ref ai/learning-pr-*) — that would - # loop. - if: >- - github.event.pull_request.merged == true - && contains(github.event.pull_request.labels.*.name, 'extract-learning') - && !startsWith(github.event.pull_request.head.ref, 'ai/learning-pr-') environment: azure-prod # DATABRICKS_HOST / DATABRICKS_TOKEN live here runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest timeout-minutes: 20 - concurrency: - group: engineer-bot-learning-pr-${{ github.event.pull_request.number }} - cancel-in-progress: false steps: # Checkout the default branch (the learning PR is cut from it) FIRST, so the # local `./` composites below resolve. persist-credentials:false — the @@ -79,50 +106,33 @@ jobs: app-id: ${{ secrets.ENGINEER_BOT_APP_ID }} private-key: ${{ secrets.ENGINEER_BOT_APP_PRIVATE_KEY }} - # NOTE: no git-identity step here. The engine's retrospective - # (databricks-bot-engine#139, in the pinned engine SHA) configures the git - # user AND DCO sign-off itself from .bot/config.yaml `bot_login_prefix` — + # NOTE: no git-identity step here. The engine's retrospective configures the + # git user AND DCO sign-off itself from .bot/config.yaml `bot_login_prefix` — # same as the author/followup flows — so the learning commit is authored and - # signed as the bot without the workflow doing it. (Before #139 this flow had - # to hand-roll the identity; the engine bump removed that need.) - - - name: Gather merged-PR context - env: - GH_TOKEN: ${{ steps.prelude.outputs.token }} - REPO: ${{ github.repository }} - PR: ${{ github.event.pull_request.number }} - run: | - set -euo pipefail - # Write the gathered context into the checkout (the engine's repo_dir / - # cwd) under the filenames the .bot/config.yaml `retrospective.context_files` - # resolves against repo_dir (`pr_diff.txt`, `review_comments.txt`); the - # engine inlines those into the prompt. - { gh pr diff "$PR" --repo "$REPO" || true; } \ - | head -c 32000 > "$GITHUB_WORKSPACE/pr_diff.txt" - { gh api --paginate "/repos/$REPO/pulls/$PR/comments" \ - --jq '.[] | "\(.path):\(.line // .original_line) \(.user.login): \(.body)"' || true; } \ - | head -c 32000 > "$GITHUB_WORKSPACE/review_comments.txt" + # signed as the bot without the workflow doing it. - - name: Extract learning + open PR + - name: Extract daily learnings + open/update PR env: GH_TOKEN: ${{ steps.prelude.outputs.token }} GITHUB_REPOSITORY: ${{ github.repository }} - PR_NUMBER: ${{ github.event.pull_request.number }} - PR_TITLE: ${{ github.event.pull_request.title }} - PR_URL: ${{ github.event.pull_request.html_url }} # Only the `/serving-endpoints/` prefix matters: # sdk_agent.translate_endpoint rewrites this to `.../serving-endpoints/anthropic` # and discards the model path segment. The effective model comes from # .bot/config.yaml `retrospective.model` (or the engine default). MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/anthropic/invocations DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} + WINDOW_HOURS: ${{ inputs.window-hours || '24' }} + SINCE: ${{ inputs.since || '' }} RUNNER_TEMP: ${{ runner.temp }} # The retrospective pushes the learning branch with a plain `git push # origin` (no in-module set-url), and the checkout ran persist-credentials: # false — so set an authenticated push remote from the minted App token # first, mirroring engineer-bot.yml's publish step. retrospective.py # resolves repo_dir from --repo-dir (cwd = $GITHUB_WORKSPACE otherwise), - # where .bot/ + the gathered context files live. + # where .bot/ lives. run: | + set -euo pipefail git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - python -m databricks_bot_engine.engineer_bot.retrospective --repo-dir "$GITHUB_WORKSPACE" + args=(--repo-dir "$GITHUB_WORKSPACE" --window-hours "$WINDOW_HOURS") + [ -n "$SINCE" ] && args+=(--since "$SINCE") + python -m databricks_bot_engine.engineer_bot.retrospective "${args[@]}" From 21b31d3538546fd539733ab5bde9f0d04a9967ca Mon Sep 17 00:00:00 2001 From: eric-wang-1990 Date: Wed, 12 Aug 2026 22:39:49 -0700 Subject: [PATCH 2/2] fix(learning): correct MODEL_ENDPOINT to the concrete serving-endpoint form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The learning workflow set MODEL_ENDPOINT to `.../serving-endpoints/anthropic/invocations`. That is NOT translated the way the old comment claimed: sdk_agent.translate_endpoint has an early-return for URLs already containing `/serving-endpoints/anthropic`, which keeps the trailing `/invocations` — so the CLI appends `/v1/messages` and calls `.../serving-endpoints/anthropic/invocations/v1/messages`, which the gateway rejects with `400 Unsupported native API path`. Proof: databricks-sql-python's learning cron (same endpoint form) has failed every scheduled run with exactly this 400. The reviewer-bot flagged it on the sibling PRs (Low), and it is the real cause. Use the concrete `.../serving-endpoints/databricks-claude-opus-4-8/invocations` form that reviewer-bot.yml / engineer-bot.yml already use successfully: translate_endpoint strips `/invocations` to the `.../serving-endpoints/ anthropic` base the CLI needs. Comment corrected to explain the trap. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 --- .github/workflows/engineer-bot-learning.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/engineer-bot-learning.yml b/.github/workflows/engineer-bot-learning.yml index 72866aff..bc7d6754 100644 --- a/.github/workflows/engineer-bot-learning.yml +++ b/.github/workflows/engineer-bot-learning.yml @@ -115,11 +115,15 @@ jobs: env: GH_TOKEN: ${{ steps.prelude.outputs.token }} GITHUB_REPOSITORY: ${{ github.repository }} - # Only the `/serving-endpoints/` prefix matters: - # sdk_agent.translate_endpoint rewrites this to `.../serving-endpoints/anthropic` - # and discards the model path segment. The effective model comes from - # .bot/config.yaml `retrospective.model` (or the engine default). - MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/anthropic/invocations + # Use the concrete `.../serving-endpoints//invocations` form (same + # as reviewer-bot.yml / engineer-bot.yml). sdk_agent.translate_endpoint + # strips it to the `.../serving-endpoints/anthropic` base the CLI needs. + # Do NOT use `.../serving-endpoints/anthropic/invocations` here: that hits + # translate_endpoint's already-v2 early-return, which keeps the trailing + # `invocations`, so the CLI appends `/v1/messages` → + # `.../anthropic/invocations/v1/messages` → HTTP 400 (unsupported path). + # The effective model is set by the engine default (no retrospective.model). + MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/databricks-claude-opus-4-8/invocations DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} WINDOW_HOURS: ${{ inputs.window-hours || '24' }} SINCE: ${{ inputs.since || '' }}