Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(api): keep state replies no-store; tag them for If-None-Match [N26]
Corey Olsond99a482f0dc1
diff --git a/src/api-http.js b/src/api-http.jsindex ac514f50..a89ea835 100644--- a/src/api-http.js+++ b/src/api-http.js@@ -29,17 +29,18 @@ function stateText(state, eventLogVersion) {}/**- * Send a state reply. A revalidating server (the local one) tags it with a digest of its text and- * answers 304 Not Modified with no body when the caller's If-None-Match already names it, so a poll- * of an unchanged board sends nothing, and lets the browser keep the reply privately and ask again- * on every poll (#1040). The digest blanks the clock readings stamped afresh on every read (flow- * asOf, queue ageMinutes), as the view's own board comparison does (#644). Other adapters keep no-store.+ * Send a state reply. A tagging server (the local one) tags it with a digest of its text and answers+ * 304 Not Modified with no body when the caller's If-None-Match already names it, so a poll of an+ * unchanged board sends nothing (#1040). The digest blanks the clock readings stamped afresh on every+ * read (flow asOf, queue ageMinutes), as the view's own board comparison does (#644). Replies stay+ * no-store: the browser never answers a poll from its cache, so a page that wants the newest clock+ * readings still gets them by not asking If-None-Match.*/-function sendState(req, res, text, revalidate) {+function sendState(req, res, text, tagged) {const headers = { 'cache-control': 'no-store', 'referrer-policy': 'no-referrer', 'x-content-type-options': 'nosniff' };- if (revalidate) {+ if (tagged) {const board = text.replace(/"(asOf|ageMinutes)":(?:"[^"]*"|[-+.0-9eE]+|null)/gu, '"$1":null');- Object.assign(headers, { 'cache-control': 'private, no-cache', etag: '"' + createHash('sha256').update(board).digest('base64url').slice(0, 32) + '"' });+ Object.assign(headers, { etag: '"' + createHash('sha256').update(board).digest('base64url').slice(0, 32) + '"' });const held = String(req.headers['if-none-match'] ?? '').split(',').map((tag) => tag.trim().replace(/^W\//u, ''));if (held.includes(headers.etag)) {res.writeHead(304, headers);@@ -131,7 +132,7 @@ function stateDetail(value) {}/** Create the common API router; an adapter controls authorization and board storage. */-export function createApiHandler(adapter, { pollMs = 200, revalidateState = false } = {}) {+export function createApiHandler(adapter, { pollMs = 200, tagState = false } = {}) {if (!Number.isInteger(pollMs) || pollMs < 10 || pollMs > 60_000) throw new Refused('API_POLL', 'use a poll interval from 10 to 60000 milliseconds');const streams = new Set();@@ -320,17 +321,17 @@ export function createApiHandler(adapter, { pollMs = 200, revalidateState = falsif (options.detail === 'full') throw new Refused('BAD_REQUEST', 'a delta brings item summaries up to date; use since=N without detail=full');if (typeof adapter.delta !== 'function') throw new Refused('DELTA_NOT_AVAILABLE', 'this API adapter does not answer since=N; use its board state');const delta = await adapter.delta(board, who, seen, { since, eventLogVersion: url.searchParams.get('eventLogVersion') });- return sendState(req, res, JSON.stringify({ version: 1, ...delta }), revalidateState);+ return sendState(req, res, JSON.stringify({ version: 1, ...delta }), tagState);}if (typeof adapter.stateJson === 'function') {const state = await adapter.stateJson(board, who, seen, options);if (typeof state !== 'string') throw new TypeError('the local state serializer must return JSON text');const eventLogVersion = await adapter.eventLogVersion?.(board, who);- return sendState(req, res, stateText(state, eventLogVersion), revalidateState);+ return sendState(req, res, stateText(state, eventLogVersion), tagState);}const state = await adapter.state(board, who, seen, options);const eventLogVersion = await adapter.eventLogVersion?.(board, who);- return sendState(req, res, JSON.stringify({ version: 1, state, ...(eventLogVersion === undefined ? {} : { eventLogVersion }) }), revalidateState);+ return sendState(req, res, JSON.stringify({ version: 1, state, ...(eventLogVersion === undefined ? {} : { eventLogVersion }) }), tagState);}if (req.method === 'GET' && route[2] === 'code') {if (typeof adapter.code !== 'function') throw new Refused('CODE_NOT_AVAILABLE', 'this API adapter does not provide committed-code previews; use the local view or a local API server');diff --git a/src/api.js b/src/api.jsindex f05b992e..feaa3941 100644--- a/src/api.js+++ b/src/api.js@@ -1121,7 +1121,7 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =request: (board, body) => createRequest(board.root, body, codeIsMain, personChannel),tokens: async (board) => (await relayTokens(board.root, { err() {} })).tokens,revokeToken: (board, id) => relayRevoke(board.root, id, { personChannel, say() {}, err() {} }),- }, { revalidateState: true });+ }, { tagState: true });}/**