coding-agents: process-local turn counter re-injects the session preamble after every host restart
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- ai
Direzione di ricerca
Inizia dal gate del conteo dei turni e da buildHookOutput in dist/index.js, quindi ispeziona i percorsi di lettura e scrittura della cache di sessione persistente intorno a writeSessionCache, readSessionCache e resetSessionCache. Usa la riproduzione di riavvio e ripresa per verificare che una nuova sessione inietti il preambolo una sola volta, mentre una sessione ripresa non lo inietti di nuovo a meno che la compattazione non reimposti la cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Description
Expected: a session gets the once-per-session preamble (tool guide + page roster) exactly once — on its first user turn.
Actual: on persistent-plugin harnesses (opencode2, pi, dsh), every restart of the host process re-injects the full ~4 KB preamble into the same session, because the turn-1 gate consults a counter that lives in process memory:
// dist/index.js (0.9.0)
turnCount = new Map(); // :19546
const turns = (this.turnCount.get(sessionId) ?? 0) + 1; // :19649
if (turns === 1) { // :19665
blocks.push(buildPagesPreamble(output.pages, ...));
}
Restarting the host resets the counter, so resuming the same session takes turns back to 1 and the gate fires again. Each injected copy lands in the user message, so it stays in the transcript permanently — a long-lived session that survives several host restarts collects one duplicate block per restart.
Impact: since #6053 moved the injection into the user message (fixing the prefix-cache break from #5914), the damage is bounded to transcript pollution — no cache miss — but it is unbounded in count and never cleaned up.
What makes this a one-line-ish fix
The persistent session cache already tracks the session's real turn count — it just isn't used by this gate:
// dist/index.js:19494
writeSessionCache(cacheFile, { turns, reflectAnswer, reflectAttempts, ... });
buildHookOutput already reads it back for cadence decisions (cached3.turns), and #6943 added injectedAtTurn?: number to the cache for autoInjectEveryTurns. The session's durable turn count exists; only the preamble gate consults the in-process map instead.
The gate could read the persisted count the same way onCompacted (dist/index.js:19684) already models "this session needs the preamble again": compaction deliberately resets the cache (resetSessionCache(...) + turnCount.delete(...)) because the model lost the block. A plain process restart is the mirror case with the opposite desired outcome — the model still has the block in the transcript, and re-injecting only duplicates it.
To reproduce
- Start a session on a persistent-plugin host (opencode or pi; any host whose plugin lives in the agent process).
- Send one prompt; observe the preamble block injected on turn 1.
- Restart the host process; reopen/resume the same session.
- Send the next prompt: the full preamble is injected a second time (turn counter is back at 1), even though the first copy is still in the transcript.
Observed with: plugin 0.9.0, server 1.3.0-slim, opencode + pi harnesses.
Suggested fix
Key the gate on the persisted session cache instead of the in-process map, e.g.:
const cachedTurns = readSessionCache(cacheFile).turns ?? 0;
if (turns === 1 && cachedTurns === 0) {
blocks.push(buildPagesPreamble(output.pages, ...));
}
This keeps the intended behavior (fresh session ⇒ one preamble; compaction ⇒ cache reset makes it re-inject) and stops the duplicate after a host restart in the same session.
Happy to send a PR if the approach sounds right.
- Lingua principale
- Python
- Stelle
- 45.2k
- Fork
- 5.9k
- Merge medio
- 5h 57m
- PR unite (30g)
- 351
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vectorize-io/hindsight
-
core
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
vectorize-io/hindsight#7053 ·
I maintainer di solito rispondono entro 1 giorno
-
integration
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
vectorize-io/hindsight#7050 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
core
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vectorize-io/hindsight#7048 ·
I maintainer di solito rispondono entro 1 giorno
-
core
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vectorize-io/hindsight#7046 ·
I maintainer di solito rispondono entro 1 giorno
-
integration:coding-agents
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
vectorize-io/hindsight#7045 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vectorize-io/hindsight
Issue simili
-
docs: powerpc not supportedAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TokenEconomizer#360 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
reasons-gate
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
benthomasson/reasons-service#190 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno