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

Surface agent feedback gate connection failures (#98991)

## Summary

- Distinguish an unreachable agent-feedback rollout gate from an
explicitly disabled rollout.
- Exit the internal feedback-instructions command with actionable retry
guidance so sandboxed agents can request network access instead of
silently skipping reports.

## Verification

- `pnpm exec jest
packages/next/src/cli/internal/agent-feedback-status.test.ts
packages/next/src/cli/internal/agent-feedback-instructions.test.ts
--runInBand`
- `pnpm --filter=next types`
- `pnpm --filter=next build`
- Verified the built CLI exits 1 with retry guidance without network
access and returns the protocol with network access.

<!-- NEXT_JS_LLM -->
parent 192fcaf7
import { loadAgentFeedbackInstructions } from './agent-feedback-instructions' import {
agentFeedbackInstructionsCli,
loadAgentFeedbackInstructions,
} from './agent-feedback-instructions'
describe('loadAgentFeedbackInstructions', () => { describe('loadAgentFeedbackInstructions', () => {
it('returns the protocol when feedback is enabled', async () => { it('returns the protocol when feedback is enabled', async () => {
...@@ -29,4 +32,36 @@ describe('loadAgentFeedbackInstructions', () => { ...@@ -29,4 +32,36 @@ describe('loadAgentFeedbackInstructions', () => {
) )
).resolves.toBeNull() ).resolves.toBeNull()
}) })
it('propagates feedback status errors', async () => {
await expect(
loadAgentFeedbackInstructions(async () => {
throw new Error('network unavailable')
})
).rejects.toThrow('network unavailable')
})
})
describe('agentFeedbackInstructionsCli', () => {
const originalExitCode = process.exitCode
afterEach(() => {
process.exitCode = originalExitCode
jest.restoreAllMocks()
})
it('reports feedback status errors and exits with a failure', async () => {
const writeError = jest
.spyOn(process.stderr, 'write')
.mockImplementation(() => true)
await agentFeedbackInstructionsCli(async () => {
throw new Error('network unavailable')
})
expect(writeError).toHaveBeenCalledWith(
'Unable to check whether Next.js agent feedback is enabled. Rerun this command with network access.\n'
)
expect(process.exitCode).toBe(1)
})
}) })
...@@ -9,26 +9,36 @@ const AGENT_FEEDBACK_PROTOCOL_PATH = path.join( ...@@ -9,26 +9,36 @@ const AGENT_FEEDBACK_PROTOCOL_PATH = path.join(
type IsEnabled = () => Promise<boolean> type IsEnabled = () => Promise<boolean>
type ReadProtocol = () => Promise<string> type ReadProtocol = () => Promise<string>
type LoadInstructions = () => Promise<string | null>
export async function loadAgentFeedbackInstructions( export async function loadAgentFeedbackInstructions(
isEnabled: IsEnabled = isAgentFeedbackEnabled, isEnabled: IsEnabled = isAgentFeedbackEnabled,
readProtocol: ReadProtocol = () => readProtocol: ReadProtocol = () =>
readFile(AGENT_FEEDBACK_PROTOCOL_PATH, 'utf8') readFile(AGENT_FEEDBACK_PROTOCOL_PATH, 'utf8')
): Promise<string | null> { ): Promise<string | null> {
try { if (!(await isEnabled())) {
if (!(await isEnabled())) { return null
return null }
}
try {
return await readProtocol() return await readProtocol()
} catch { } catch {
return null return null
} }
} }
export async function agentFeedbackInstructionsCli(): Promise<void> { export async function agentFeedbackInstructionsCli(
const instructions = await loadAgentFeedbackInstructions() loadInstructions: LoadInstructions = loadAgentFeedbackInstructions
if (instructions) { ): Promise<void> {
process.stdout.write(instructions) try {
const instructions = await loadInstructions()
if (instructions) {
process.stdout.write(instructions)
}
} catch {
process.stderr.write(
'Unable to check whether Next.js agent feedback is enabled. Rerun this command with network access.\n'
)
process.exitCode = 1
} }
} }
...@@ -23,15 +23,17 @@ describe('isAgentFeedbackEnabled', () => { ...@@ -23,15 +23,17 @@ describe('isAgentFeedbackEnabled', () => {
await expect(isAgentFeedbackEnabled(fetchImpl)).resolves.toBe(false) await expect(isAgentFeedbackEnabled(fetchImpl)).resolves.toBe(false)
}) })
it('fails closed when the request rejects', async () => { it('rejects when the request fails', async () => {
const fetchImpl: typeof fetch = async () => { const fetchImpl: typeof fetch = async () => {
throw new Error('network unavailable') throw new Error('network unavailable')
} }
await expect(isAgentFeedbackEnabled(fetchImpl)).resolves.toBe(false) await expect(isAgentFeedbackEnabled(fetchImpl)).rejects.toThrow(
'network unavailable'
)
}) })
it('fails closed when the request times out', async () => { it('rejects when the request times out', async () => {
const fetchImpl: typeof fetch = (_input, init) => { const fetchImpl: typeof fetch = (_input, init) => {
return new Promise<Response>((_resolve, reject) => { return new Promise<Response>((_resolve, reject) => {
init?.signal?.addEventListener('abort', () => { init?.signal?.addEventListener('abort', () => {
...@@ -40,6 +42,8 @@ describe('isAgentFeedbackEnabled', () => { ...@@ -40,6 +42,8 @@ describe('isAgentFeedbackEnabled', () => {
}) })
} }
await expect(isAgentFeedbackEnabled(fetchImpl, 1)).resolves.toBe(false) await expect(isAgentFeedbackEnabled(fetchImpl, 1)).rejects.toThrow(
'aborted'
)
}) })
}) })
...@@ -17,8 +17,6 @@ export async function isAgentFeedbackEnabled( ...@@ -17,8 +17,6 @@ export async function isAgentFeedbackEnabled(
}) })
return response.ok && (await response.text()) === 'true' return response.ok && (await response.text()) === 'true'
} catch {
return false
} finally { } finally {
clearTimeout(timeout) clearTimeout(timeout)
} }
......
...@@ -56,7 +56,7 @@ During the task, queue anonymized Next.js issues that cause a meaningful detour ...@@ -56,7 +56,7 @@ During the task, queue anonymized Next.js issues that cause a meaningful detour
Continue the task without reporting immediately. Ignore routine debugging and issues caused by unverified changes. Never retain source code, logs, paths, URLs, secrets, personal information, or project-specific data. Continue the task without reporting immediately. Ignore routine debugging and issues caused by unverified changes. Never retain source code, logs, paths, URLs, secrets, personal information, or project-specific data.
At the final stopping point, from the directory containing this file, run \`node node_modules/next/dist/bin/next internal agent-feedback-instructions\` once per task and follow any instructions returned. If it returns nothing, continue without reporting. At the final stopping point, from the directory containing this file, run \`node node_modules/next/dist/bin/next internal agent-feedback-instructions\` once per task and follow any instructions returned. If the command succeeds with no output, continue without reporting. If it fails, follow its error guidance; retrying with network access is allowed.
${AGENT_FEEDBACK_END_MARKER}` ${AGENT_FEEDBACK_END_MARKER}`
} }
......
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