From 8fbb8b69b13b040f01465d0a8e8cc9dfa9a05041 Mon Sep 17 00:00:00 2001 From: Self-Managing Codebase Manager <7004983+WillTaylor22@users.noreply.github.com> Date: Tue, 26 May 2026 09:51:55 +0000 Subject: [PATCH] Fix session-id webhook regex: accept both sthr_ and sesn_ prefixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ENG-26 — the Anthropic SDK switched session-id prefixes from sthr_ to sesn_; the webhook regex still required sthr_, so every well-formed marker the agent writes returns null from extractSessionId() and the session-resume path silently fell through to fresh sessions. Fix: - app/api/github-webhook/route.ts:20 — regex now matches (?:sthr_|sesn_)[A-Za-z0-9]+. Keeps sthr_ for back-compat with any pre-switch markers still floating in old PRs. - .claude/memory/conventions/pr-session-id-marker.md — example now shows sesn_xxxxxxxxxxxxxxxx and explicitly notes both prefixes work. - .claude/memory/MEMORY.md — one-line hook updated. Verification: build + lint both green. Webhook payload is HMAC-signed so no easy local repro; regex change is small enough to verify by eye. --- .claude/memory/MEMORY.md | 2 +- .claude/memory/conventions/pr-session-id-marker.md | 6 +++++- app/api/github-webhook/route.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.claude/memory/MEMORY.md b/.claude/memory/MEMORY.md index 115b917..1f8b851 100644 --- a/.claude/memory/MEMORY.md +++ b/.claude/memory/MEMORY.md @@ -14,5 +14,5 @@ Keep this file under 200 lines — anything longer is content bloat, not memory. - [decisions/two-agent-builder-reviewer](decisions/2026-05-25-two-agent-builder-reviewer.md) — Separate agents for build vs. review so the reviewer reads diffs cold ## Conventions -- [conventions/pr-session-id-marker](conventions/pr-session-id-marker.md) — PR body MUST end with `` so webhooks can resume +- [conventions/pr-session-id-marker](conventions/pr-session-id-marker.md) — PR body MUST end with `` (or legacy `sthr_...`) so webhooks can resume - [conventions/agent-review-marker](conventions/agent-review-marker.md) — Reviewer's verdict goes on the first line as `AGENT_REVIEW: APPROVED|REQUEST_CHANGES|ESCALATE — ` diff --git a/.claude/memory/conventions/pr-session-id-marker.md b/.claude/memory/conventions/pr-session-id-marker.md index 8b41f69..1ab5f80 100644 --- a/.claude/memory/conventions/pr-session-id-marker.md +++ b/.claude/memory/conventions/pr-session-id-marker.md @@ -4,7 +4,7 @@ Every PR opened by the manager MUST end with this HTML comment as the **last line** of the PR body: ``` - + ``` The `/api/github-webhook` route extracts this marker when a webhook @@ -12,6 +12,10 @@ fires for the PR (e.g. `issue_comment.created` with `AGENT_REVIEW: APPROVED`). With it, the webhook resumes the original manager session — full implementation context, no re-explaining. +The webhook regex accepts both the legacy `sthr_` prefix and the +current `sesn_` prefix returned by `client.beta.sessions.create()`. +Use whichever prefix the kickoff `user.message` carries. + Without it, the webhook falls back to creating a fresh session. The fresh session loses all design rationale and re-derives everything. Functional but wasteful. diff --git a/app/api/github-webhook/route.ts b/app/api/github-webhook/route.ts index 6f8aa98..7814c9e 100644 --- a/app/api/github-webhook/route.ts +++ b/app/api/github-webhook/route.ts @@ -17,7 +17,7 @@ function verifySignature(rawBody: string, sigHeader: string | null, secret: stri function extractSessionId(text: string | undefined | null): string | null { if (!text) return null; - const m = text.match(//); + const m = text.match(//); return m?.[1] ?? null; }