GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(session): a harness note does not start a turn when compaction ke… · garysomerhalder/opencode@0c87d14

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • src/session
      • compaction.ts
    • test/session
      • compaction.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/session/compaction.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/session/compaction.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ function turns(messages: SessionV1.WithParts[]) {
130130
const msg = messages[i]
131131
if (msg.info.role !== "user") continue
132132
if (msg.parts.some((part) => part.type === "compaction")) continue
133+
// A harness note (a reminder, a background-task wake, a compaction
134+
// checkpoint) belongs to the turn it was written into; counting it as a
135+
// turn would push a real turn out of `tail_turns`. Prune counts turns the
136+
// same way.
137+
if (HarnessNote.isNote(msg)) continue
133138
result.push({
134139
start: i,
135140
end: messages.length,
Collapse file

‎packages/opencode/test/session/compaction.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/session/compaction.test.ts
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, describe, expect, mock, test } from "bun:test"
22
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
33
import { SessionV1 } from "@opencode-ai/core/v1/session"
4+
import { HarnessNote } from "../../src/session/harness-note"
45
import { Database } from "@opencode-ai/core/database/database"
56
import { EventV2Bridge } from "@/event-v2-bridge"
67
import { APICallError } from "ai"
@@ -1825,6 +1826,43 @@ describe("session.compaction.process", () => {
18251826
{ git: true },
18261827
)
18271828

1829+
itCompaction.instance("a harness note does not count as a turn when the recent tail is kept", () => {
1830+
const stub = llm()
1831+
stub.push(reply("summary"))
1832+
1833+
return Effect.gen(function* () {
1834+
const ssn = yield* SessionNs.Service
1835+
const session = yield* ssn.create({})
1836+
yield* createUserMessage(session.id, "one")
1837+
yield* createUserMessage(session.id, "two")
1838+
const u3 = yield* createUserMessage(session.id, "three")
1839+
// a reminder the harness injected into turn three (accuracy A), not a turn of its own
1840+
const note = HarnessNote.build({
1841+
user: u3 as SessionV1.User,
1842+
kind: "runaway_guard",
1843+
text: "<system-reminder>change approach</system-reminder>",
1844+
})
1845+
yield* ssn.updateMessage(note.info)
1846+
yield* ssn.updatePart(note.part)
1847+
const u4 = yield* createUserMessage(session.id, "four")
1848+
yield* createCompactionMarker(session.id)
1849+
1850+
const msgs = yield* ssn.messages({ sessionID: session.id })
1851+
yield* SessionCompaction.use.process({
1852+
parentID: msgs.at(-1)!.info.id,
1853+
messages: msgs,
1854+
sessionID: session.id,
1855+
auto: false,
1856+
})
1857+
1858+
// the two recent turns are three (with its note) and four
1859+
const ids = MessageV2.filterCompacted(yield* MessageV2.stream(session.id)).map((msg) => msg.info.id)
1860+
expect(ids).toContain(u3.id)
1861+
expect(ids).toContain(note.info.id)
1862+
expect(ids).toContain(u4.id)
1863+
}).pipe(withCompaction({ llm: stub.llmLayer, config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))
1864+
})
1865+
18281866
itCompaction.instance("keeps recent pre-compaction turns across repeated compactions", () => {
18291867
const stub = llm()
18301868
stub.push(reply("summary one"))

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.