Unverified Commit eda07a70 authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

Ignore expected upgrade nudges in Agent Feedback (#100840)

### What?

- Exclude intentional one-time `SecurityFatalError` and
`UpgradeNudgeError` upgrade stops from the private Agent Feedback
reporting protocol.
- Keep retries that remain blocked, or documented remediation that
fails, eligible as unexpected behavior.
- Add an Agent Feedback eval with one genuine documentation mismatch and
one expected upgrade stop. It requires the documentation report and
rejects any report for the expected stop.
- Add focused coverage for the internal protocol loader.

### Why?

The Next.js upgrade gate intentionally stops a successful command once,
explains that an upgrade is recommended, and allows the next run to
continue. Agents were treating that expected stop as a Next.js error and
filing duplicate feedback. The private reporting protocol should
distinguish the expected gate from an actual failure of the retry or
remediation path.

This does not change the public generated `AGENTS.md` instructions.

### Verification

| Check | Result |
| --- | --- |
| Agent Feedback CLI and protocol tests | 25 passed |
| Eval fixture/config validation | Passed |
| Prettier | Passed |
| Agent eval model run | Attempted twice with the rebuilt local package;
both shared AI Gateway requests failed before model execution |
parent f922205f
......@@ -60,5 +60,10 @@
"skills": ["next-bundle-optimizer"],
"publish": false,
"timeout": 2700
},
"agent-061-agent-feedback-upgrade-nudge": {
"agentFeedback": true,
"publish": false,
"timeout": 900
}
}
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { expect, test } from 'vitest'
import { transcriptPath } from '@vercel/agent-eval/eval'
type Report = {
schemaVersion?: unknown
triggerReason?: unknown
title?: unknown
steps?: unknown
observed?: unknown
expected?: unknown
}
const feedbackMarker = '<!-- BEGIN:nextjs-agent-feedback -->'
function feedbackIsEnabled(): boolean {
const path = join(process.cwd(), 'AGENTS.md')
return existsSync(path) && readFileSync(path, 'utf8').includes(feedbackMarker)
}
function reviewPayloads(): string[] {
const raw = readFileSync(transcriptPath(), 'utf8')
return [
...new Set(
[
...raw.matchAll(
/https:\/\/nextjs\.org\/agent-feedback(?:\?[^#\s]*)?#report=([A-Za-z0-9_-]+)/g
),
].map((match) => match[1])
),
]
}
function reportPayloads(): Report[] {
return reviewPayloads().map((payload) =>
JSON.parse(Buffer.from(payload, 'base64url').toString())
)
}
function feedbackCommands(): string[] {
const raw = readFileSync(transcriptPath(), 'utf8')
return [
...new Set(
[...raw.matchAll(/"command"\s*:\s*"((?:\\.|[^"\\])*)"/g)]
.map((match) => JSON.parse(`"${match[1]}"`) as string)
.filter((command) =>
/\bnpx\s+--no-install\s+next\s+internal\s+agent-feedback(?:\s|$)/.test(
command
)
)
),
]
}
test('finishes the requested application change', () => {
const page = readFileSync(join(process.cwd(), 'app/page.tsx'), 'utf8')
expect(page).toContain('Verified')
})
test('reports the documentation mismatch but not the expected upgrade stop', () => {
const reports = reportPayloads()
if (!feedbackIsEnabled()) {
expect(reports).toHaveLength(0)
return
}
expect(reports).toHaveLength(1)
expect(reports[0]).toEqual(
expect.objectContaining({
schemaVersion: expect.any(Number),
triggerReason: 'documentation-mismatch',
title: expect.any(String),
steps: expect.any(Array),
observed: expect.any(Array),
expected: expect.any(String),
})
)
const serialized = JSON.stringify(reports[0]).toLowerCase()
expect(serialized).not.toContain('securityfatalerror')
expect(serialized).not.toContain('upgradenudgeerror')
expect(serialized).not.toContain('upgrade recommendation')
})
test('opens the qualifying report through the feedback CLI', () => {
const commands = feedbackCommands()
if (!feedbackIsEnabled()) {
expect(commands).toHaveLength(0)
return
}
expect(commands.length).toBeGreaterThan(0)
})
Finish the release check by changing the page status to "Verified" and running the production build.
Two separate things happened earlier in this task:
- The bundled documentation linked to a guide that was absent from the installed package, so the relevant API had to be found by searching other bundled pages.
- The first successful production build then exited with `SecurityFatalError`. Next.js said the command intentionally stopped to show an upgrade recommendation and that retrying the same command would continue the original task. The unchanged retry succeeded, and no further build failures occurred.
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export default function ReleaseStatusPage() {
return (
<main>
<h1>Release status</h1>
<p>Pending</p>
</main>
)
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
agentRules: false,
experimental: {
agentFeedback: true,
},
}
export default nextConfig
{
"private": true,
"type": "module",
"scripts": {
"build": "next build"
},
"dependencies": {
"next": "^16",
"react": "19.1.0",
"react-dom": "19.1.0"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5",
"vitest": "^3.1.3"
}
}
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{ "name": "next" }],
"target": "ES2017"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "EVAL.ts"]
}
......@@ -16,6 +16,8 @@ Create a separate report draft for each distinct Next.js friction point that cau
Do not report routine first-pass debugging, vague task scope, problems caused by unverified changes, or issues resolved immediately by following existing guidance. A later fix or workaround does not disqualify friction that already qualified, such as a misleading diagnostic or repeated failed approaches. Keep that candidate through the reporting pass and record its final outcome. Keep unrelated issues in separate report drafts.
Do not report a `SecurityFatalError` or `UpgradeNudgeError` when Next.js says the command intentionally stopped to show an upgrade recommendation and that retrying will continue. This is expected behavior, not a feedback candidate. If the retry remains blocked or the documented remediation fails, treat that deviation as separate unexpected behavior and evaluate it normally.
## Run the reporting pass before the final response
Do not interrupt the current user request when friction first qualifies. Retain each distinct set of bounded, anonymized facts as a feedback candidate in the context of the current user request, then continue the work.
......
......@@ -46,6 +46,9 @@ describe('loadAgentFeedbackInstructions', () => {
expect(instructions).toContain(
'Set `model` to the model identifier and `reasoningEffort`'
)
expect(instructions).toContain(
'Do not report a `SecurityFatalError` or `UpgradeNudgeError` when Next.js says the command intentionally stopped to show an upgrade recommendation and that retrying will continue.'
)
})
it('does not read the protocol when feedback is disabled', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment