Skip to content

feat(prompts): show Improve the brand's earlier Improve rounds on the prompt (learning B5, part 2) - #1693

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/improve-past-outcome
Oct 28, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/improve-past-outcome

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Agentic learning, B5 part 2: Improve sees the brand's earlier Improve rounds on the same prompt.

Improve (PROMPT-008) wrote its suggestions without knowing what was tried before on that prompt, or what came of it.

loadImproveRounds({ promptId, brandId, region }) (from-prompt-improve.js) reads the brand's last 2 prompt_improve actions on this prompt.

  • Filters: payload->>promptId, not dismissed, not deleted, same brand, and the request's region.
  • An unset region reads only actions sent without one, the same way their measure reads all regions.
  • Two queries in total (the actions, then their tasks); no N+1.

Each round (improveRound) carries:

  • the day it was sent, as "N days ago" from today;
  • whether it's still open;
  • each platform's verdict from position_outcome, and whether the reading is final;
  • its suggestions (title and platform, at most 12 per round, on one line each), each marked done, skipped or not done.

buildImprovePrompt({ …, history }) adds an "Earlier Improve rounds on this prompt" block with these rules:

  • build on what moved;
  • don't suggest again what was done on a platform that didn't move;
  • don't suggest again what the team skipped.

No rounds means no block.

Pre-push review fixes:

  • A round whose last reading came less than OUTCOME_WINDOW_DAYS (7) after it was sent reads "too early to read" for its platforms. Its "did not move" rule doesn't apply. Before, a round sent two days ago read "unchanged", and the model could take that as a failure.
  • Rounds are filtered by region, so a Germany run doesn't read US results.
  • Skipped tasks are labelled "(skipped by the team)" instead of "not done".
  • At most 12 suggestions per round; titles are single-lined and quote-safe.
  • The route logs a failed read with req.log.warn, keeping the request id.
  • Tests now pin the read's order, limit, task read and error paths.
  • New route test prompts-improve-generate.test.js: when history can't be read, Improve still answers 200 and calls the model once.

Safety:

Where people see it: Prompts › a prompt's "…" › Improve position… › Improve: the suggestions generated there. On a prompt with an earlier Improve action, a suggestion that didn't move its platform isn't offered again. No new button. Cost: the same model call, with a few more lines of prompt.

Related issue

Agentic learning report, phase B (B5). No GitHub issue. Learning stays within one brand.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/action-center/from-prompt-improve.test.js src/lib/prompt-improve.test.js src/routes/prompts-improve-generate.test.js
  2. On a prompt with an earlier Improve action, generate Improve suggestions. The model's prompt holds the "Earlier Improve rounds" block; a round sent today reads "too early to read".

The region filters (payload->>region equal to a region, or null) were run read-only against the dev database: PostgREST accepts both.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Server checks at 8ade052:

  • format, lint and npm test (no SUPABASE_* env, as in CI): 3,350 tests passed.
  • Two timing tests in content-people.test.js and content-agent.test.js (budgets of 150 ms and 400 ms) ran over while another full check was running (load average 18). This branch doesn't touch either file; both passed in the earlier runs of this batch.

The web is unchanged (docs only).

🤖 Generated with Claude Code

cihan-gyk and others added 7 commits October 28, 2026 09:59
… prompt

Learning B5, part 2. Improve wrote its suggestions from the answers only,
so it could suggest again what an earlier round did on a platform that
didn't move, and never built on what moved.

- loadImproveRounds: the brand's last two prompt_improve actions on the
  prompt (not dismissed or deleted, never another brand's), each with how
  its platforms moved (position_outcome, final a month after it was
  completed) and its suggestions, done or not.
- buildImprovePrompt adds an "Earlier Improve rounds" block and asks to
  build on what moved and not to repeat what was done on a platform that
  didn't. No rounds, no block; unreadable, written as before.
- Docs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…too early, and say how long ago

An Improve action's first read is its baseline, and until a read is 7 days
past the send its days still overlap the baseline's: every platform read
"unchanged", so the next generation could take a round sent yesterday as
one that did not move.

- improveRound: a round whose read is less than OUTCOME_WINDOW_DAYS past
  its send (or has no read) gives its platforms "too_early"; each round
  says how many days ago it was sent, against an injectable `now`.
- buildImprovePrompt: "Sent 2026-10-26, 2 days ago", "too early to read",
  and the "did not move" rule doesn't count those platforms.
- Docs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A skipped task read as "not done", as if it still waited, so the next
generation could suggest again what the team chose not to do.

- improveRound: each suggestion's status is done, skipped or not_done
  (failed and waiting for approval are not done).
- buildImprovePrompt: "(skipped by the team)", and, when a round has one,
  "Do not suggest again what the team skipped."
- Docs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gestions each, one line apiece

A round's every task went into the prompt as typed: a long round, a title
edited over several lines, or one with its own double quotes could swell
the prompt or break its quoted list.

- improveRound: a round's first 12 titled suggestions in task order
  (IMPROVE_ROUND_TASKS), each title's line breaks and runs of spaces read
  as one space.
- buildImprovePrompt: a title's double quotes are written as single ones
  inside its quotes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…region

An Improve set is kept per region and its action keeps that region, but the
earlier rounds were read for every region: a US set could be told how a
German round moved.

- loadImproveRounds takes the set's region: a region reads the actions
  sent with it (payload->>region), '' or none reads those sent without one,
  as they are measured over all regions.
- POST /:promptId/improve passes the request's region.
- Docs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st's logger

The route logs on req.log everywhere else; the earlier-rounds warning used
the module logger and only the error's message.

- POST /:promptId/improve: req.log.warn({ err, promptId }, …), and the
  logger import goes.
- Route test: the set's region's earlier rounds reach the model's prompt,
  and when they can't be read the suggestions are still written, with the
  warning on the request's log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sk read and errors

The supabase stub dropped order() and limit(), so nothing held the read to
the newest two rounds, and the action_tasks read and the error branches
went untested.

- The stub records order and limit and can return an error per table.
- loadImproveRounds: newest first, limit 2, the tasks read by those
  actions' ids in position order and grouped per round; an unreadable
  actions or action_tasks read throws with what failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 28, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 8ade052.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, with follow-ups.

Own change. c0cee01 through 8ade052 on 3f6a4d4. Server and docs only. It merges cleanly on main (b591947), and with #1687–#1689 and #1698 squashed before it; main's change to /from-topics in prompts.js sits apart from this one.

Checked

  • Scope. The brand comes from the prompt's own set after assertBrandAccess, and both reads filter by that brand (actions) or by the ids those returned (tasks). No other brand's rounds can reach the prompt.
  • Region. The send stores region: set.region || null, and the read uses eq('payload->>region', region) or is(..., null) for no region; an empty string from the range reads as no region on both sides. Actions sent before region was in the payload read as no region too, which is how they're measured.
  • Too early. A round whose last read is under OUTCOME_WINDOW_DAYS from the send reads "too early to read" on every platform, and the rule tells the model not to count those as not moving.
  • Cost and failure. The read runs only after the budget is reserved and the model will be called. A failed read logs on req.log and the generation goes on without history; the route test pins one model call and a 200.
  • Speed. The two regexes (\s+ and ") are linear: 24 titles of 200 KB each (whitespace runs and quotes) build the prompt in about 180 ms.
  • Tests. On this PR's tree, the three files pass (47). With main's from-prompt-improve.js, prompt-improve.js and prompts.js put back, 12 fail.

Follow-ups

  1. Cap each title. Titles go into the prompt in full (from-prompt-improve.js:167). The app cuts a task title at 200 characters when it's added or edited, but action_tasks.title has no limit of its own, so a long title written another way makes each later Improve call bigger, and it's charged by tokens. Cutting it at 200 characters here, at a word, bounds the block to 2 × 12 lines.

Before the API deploy. Nothing changes. It's server-only; the guide's new paragraph goes out with the docs before the API does.

@gkhngyk
gkhngyk merged commit 53671d4 into ansvisor:main Oct 28, 2026
7 checks passed
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.

2 participants