GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(opencode): add memory system and GLM thinking corruption fix by terisuke · Pull Request #56 · Cor-Incorporated/opencode ConversationSummary
Closes #37 Fact-checking performed
Claude Code & claude-code-skills comparison
Follow-up Issues created
Codex review findings (all resolved)
Test plan
Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull request overviewAdds a cross-session “memory” feature (SQLite table + file-based index injection) and mitigations for GLM-5.1 thinking-output corruption by adding think-tag stripping and streaming repetition-loop detection. Changes:
Reviewed changesCopilot reviewed 22 out of 22 changed files in this pull request and generated 10 comments. Show a summary per file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return toInfo(row) | |
| return toInfo({ | |
| ...row, | |
| access_count: (row.access_count ?? 0) + 1, | |
| }) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Fire-and-forget memory extraction helper, gated by config | ||
| const memoryExtract = (fn: () => void | Promise<void>) => { | ||
| void Config.get() | ||
| .then((cfg) => { | ||
| if (cfg.memory?.auto_extract === false) return | ||
| return fn() | ||
| }) | ||
| .catch((err) => log.warn("memory extractor error", { error: err })) | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
memoryExtract() gates only on cfg.memory.auto_extract but ignores cfg.memory.enabled. With enabled=false, the extractor will still run and write to SQLite, which contradicts the meaning of the top-level enable/disable flag. Consider short-circuiting when memory.enabled is false (and also ensuring cleanup still runs for any in-memory session state).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Fire-and-forget memory extraction helper, gated by config | ||
| const memoryExtract = (fn: () => void | Promise<void>) => { | ||
| void Config.get() | ||
| .then((cfg) => { | ||
| if (cfg.memory?.auto_extract === false) return | ||
| return fn() | ||
| }) | ||
| .catch((err) => log.warn("memory extractor error", { error: err })) | ||
| } | ||
|
|
||
| const create = Effect.fn("SessionProcessor.create")(function* (input: Input) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
memoryExtract() calls Config.get() for every tracked tool/result/error event, which can add a lot of async overhead during high-frequency streaming/tool use. Since auto_extract is effectively static during a session, consider reading config once in create()/process() and capturing a boolean flag (or using the injected config service) instead of reloading it on every event.
| // Fire-and-forget memory extraction helper, gated by config | |
| const memoryExtract = (fn: () => void | Promise<void>) => { | |
| void Config.get() | |
| .then((cfg) => { | |
| if (cfg.memory?.auto_extract === false) return | |
| return fn() | |
| }) | |
| .catch((err) => log.warn("memory extractor error", { error: err })) | |
| } | |
| const create = Effect.fn("SessionProcessor.create")(function* (input: Input) { | |
| const create = Effect.fn("SessionProcessor.create")(function* (input: Input) { | |
| const autoExtractEnabled = (yield* Config.get()).memory?.auto_extract !== false | |
| // Fire-and-forget memory extraction helper, gated by config captured | |
| // once for this processor run to avoid repeated async config lookups. | |
| const memoryExtract = (fn: () => void | Promise<void>) => { | |
| if (!autoExtractEnabled) return | |
| void Promise.resolve(fn()).catch((err) => log.warn("memory extractor error", { error: err })) | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -132,6 +171,9 @@ export namespace SessionProcessor { | |||
| if (!(value.id in ctx.reasoningMap)) return | |||
| ctx.reasoningMap[value.id].text += value.text | |||
| if (value.providerMetadata) ctx.reasoningMap[value.id].metadata = value.providerMetadata | |||
| if (detectRepetition(ctx.reasoningMap[value.id].text)) { | |||
| yield* Effect.fail(new RepetitionError(ctx.reasoningMap[value.id].text.slice(-80))) | |||
| } | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
detectRepetition() is invoked on every reasoning/text delta once the buffer exceeds 8KB, and its inner loop scans 4..200 pattern lengths each time. On fast streaming models this can become a hot path. Consider throttling checks (e.g., only every N characters / N deltas), or maintaining incremental state so the per-delta cost is bounded.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const [skills, env, instructions, modelMsgs, memory] = yield* Effect.all([ | ||
| Effect.promise(() => SystemPrompt.skills(agent)), | ||
| Effect.promise(() => SystemPrompt.environment(model)), | ||
| instruction.system().pipe(Effect.orDie), | ||
| Effect.promise(() => MessageV2.toModelMessages(msgs, model)), | ||
| Effect.promise(() => MemoryInjector.load()), | ||
| ]) | ||
| const system = [...env, ...(skills ? [skills] : []), ...instructions] | ||
| const system = [...env, ...(skills ? [skills] : []), ...instructions, ...(memory ? [memory] : [])] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
SessionPrompt injects memory via MemoryInjector.load(), which reads .opencode/memory/MEMORY.md, but the auto-extraction pipeline currently persists entries via MemoryStore (SQLite) only. With no DB→file sync in this PR, auto-extracted memories won't ever show up in the injected prompt. Consider either (a) loading injected memory from MemoryStore, or (b) having the extractor update MEMORY.md / entry files so both layers stay consistent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import { Bus } from "@/bus" | ||
| import { Config } from "@/config/config" | ||
| import { Log } from "@/util/log" | ||
| import { MemoryStore } from "./store" | ||
| import type { Memory } from "./types" | ||
| import { Instance } from "@/project/instance" | ||
|
|
||
| const log = Log.create({ service: "memory.extractor" }) | ||
|
|
||
| type SessionState = { | ||
| commands: Map<string, number> | ||
| errors: string[] | ||
| fixes: string[] | ||
| configChanges: string[] | ||
| lastFlush: number | ||
| pending: Memory.Create[] | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
memory/extractor.ts has unused imports (Bus, Config) and unused SessionState fields (fixes, configChanges). Besides compiler/lint noise, the unused arrays can grow without bound if tracking is called repeatedly. Consider removing the unused imports/fields or wiring them into logic that actually consumes them (e.g., for summarization/dedup).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| state.pending = [] | ||
| state.lastFlush = Date.now() | ||
|
|
||
| for (const entry of batch) { | ||
| await MemoryStore.runPromise((svc) => svc.create(entry)).catch((err) => { | ||
| log.warn("failed to flush memory entry", { error: err, topic: entry.topic }) | ||
| }) | ||
| } | ||
| log.info("flushed memory entries", { sessionID, count: batch.length }) | ||
| } | ||
|
|
||
| export async function cleanup(sessionID: string) { | ||
| await flush(sessionID).catch((err) => { | ||
| log.warn("failed to flush on cleanup", { error: err }) | ||
| }) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
flush() clears state.pending before attempting writes. If MemoryStore.create fails (e.g., transient DB errors), the entry is dropped permanently and cannot be retried. Consider only removing entries from pending after a successful create, or collecting failed entries and re-queueing them for the next flush/cleanup.
| state.pending = [] | |
| state.lastFlush = Date.now() | |
| for (const entry of batch) { | |
| await MemoryStore.runPromise((svc) => svc.create(entry)).catch((err) => { | |
| log.warn("failed to flush memory entry", { error: err, topic: entry.topic }) | |
| }) | |
| } | |
| log.info("flushed memory entries", { sessionID, count: batch.length }) | |
| } | |
| export async function cleanup(sessionID: string) { | |
| await flush(sessionID).catch((err) => { | |
| log.warn("failed to flush on cleanup", { error: err }) | |
| }) | |
| const failed: typeof batch = [] | |
| state.pending = [] | |
| state.lastFlush = Date.now() | |
| for (const entry of batch) { | |
| await MemoryStore.runPromise((svc) => svc.create(entry)).catch((err) => { | |
| failed.push(entry) | |
| log.warn("failed to flush memory entry", { error: err, topic: entry.topic }) | |
| }) | |
| } | |
| if (failed.length > 0) { | |
| state.pending = failed.concat(state.pending) | |
| log.warn("failed to flush some memory entries; queued for retry", { | |
| sessionID, | |
| failed: failed.length, | |
| attempted: batch.length, | |
| }) | |
| } | |
| log.info("flushed memory entries", { | |
| sessionID, | |
| count: batch.length - failed.length, | |
| }) | |
| } | |
| export async function cleanup(sessionID: string) { | |
| await flush(sessionID).catch((err) => { | |
| log.warn("failed to flush on cleanup", { error: err }) | |
| }) | |
| const state = sessions.get(sessionID) | |
| if (state && state.pending.length > 0) { | |
| log.warn("skipping session cleanup because memory entries are still pending", { | |
| sessionID, | |
| pending: state.pending.length, | |
| }) | |
| return | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const dir = memoryDir() | ||
| const resolved = path.resolve(dir, filename) | ||
| if (!resolved.startsWith(dir + path.sep) && resolved !== dir) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
entryPath() allows resolved === dir, which means an empty filename (""), ".", etc. would pass the traversal check and result in attempting to read/write the directory path as a file. Consider rejecting empty filenames and any filename that resolves to the directory itself, and/or enforcing that filename is a basename (no path separators).
| const dir = memoryDir() | |
| const resolved = path.resolve(dir, filename) | |
| if (!resolved.startsWith(dir + path.sep) && resolved !== dir) | |
| if (!filename || filename === "." || filename === ".." || path.basename(filename) !== filename) | |
| throw new Error("invalid filename") | |
| const dir = memoryDir() | |
| const resolved = path.resolve(dir, filename) | |
| if (!resolved.startsWith(dir + path.sep)) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (!fm.topic || !fm.type) return undefined | ||
| return { | ||
| frontmatter: { | ||
| topic: fm.topic, | ||
| type: fm.type as Memory.Type, | ||
| }, | ||
| content: match[2].trim(), | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
parseFrontmatter() casts the type string directly to Memory.Type without validating it against the allowed type list. Since these files are user-editable, invalid types can silently propagate through the system. Consider validating fm.type (and fm.topic) and returning undefined (or throwing a clear error) when the value isn't one of Memory.TYPES.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // detectRepetition is a namespace-internal function in SessionProcessor. | ||
| // We replicate the algorithm here to test it in isolation. | ||
| // Constants match processor.ts: REPETITION_THRESHOLD=50, REPETITION_WINDOW=8000 | ||
|
|
||
| const REPETITION_THRESHOLD = 50 | ||
| const REPETITION_WINDOW = 8000 | ||
|
|
||
| function detectRepetition(text: string): boolean { | ||
| if (text.length < REPETITION_WINDOW) return false | ||
| const tail = text.slice(-REPETITION_WINDOW) | ||
| for (let len = 4; len <= 200; len++) { | ||
| const pattern = tail.slice(-len) | ||
| let count = 0 | ||
| let pos = tail.length - len | ||
| while (pos >= 0) { | ||
| if (tail.slice(pos, pos + len) === pattern) { | ||
| count++ | ||
| pos -= len | ||
| } else break | ||
| } | ||
| if (count >= REPETITION_THRESHOLD) return true | ||
| } | ||
| return false | ||
| } | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The test duplicates the detectRepetition algorithm and constants instead of exercising the production implementation. This can easily drift (e.g., threshold/window changes) without failing tests. Consider extracting detectRepetition into a shared util that both processor.ts and the test import, or exporting a small test-only helper/constant from processor.ts so the test stays coupled to the real logic.
| // detectRepetition is a namespace-internal function in SessionProcessor. | |
| // We replicate the algorithm here to test it in isolation. | |
| // Constants match processor.ts: REPETITION_THRESHOLD=50, REPETITION_WINDOW=8000 | |
| const REPETITION_THRESHOLD = 50 | |
| const REPETITION_WINDOW = 8000 | |
| function detectRepetition(text: string): boolean { | |
| if (text.length < REPETITION_WINDOW) return false | |
| const tail = text.slice(-REPETITION_WINDOW) | |
| for (let len = 4; len <= 200; len++) { | |
| const pattern = tail.slice(-len) | |
| let count = 0 | |
| let pos = tail.length - len | |
| while (pos >= 0) { | |
| if (tail.slice(pos, pos + len) === pattern) { | |
| count++ | |
| pos -= len | |
| } else break | |
| } | |
| if (count >= REPETITION_THRESHOLD) return true | |
| } | |
| return false | |
| } | |
| import { | |
| detectRepetition, | |
| REPETITION_THRESHOLD, | |
| REPETITION_WINDOW, | |
| } from "../../src/session/processor" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Implements cross-session persistent memory (Issues #43, #44, #45) and fixes GLM-5.1 thinking output corruption (Issue #52). Memory system: SQLite + file-based storage with auto-extraction and session-start injection, schema aligned with upstream PR anomalyco#20344. GLM fix: model-specific prompt, think tag parsing utility, and streaming repetition loop detection to prevent context exhaustion. Closes #43, Closes #44, Closes #45, Relates #52 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Fixes pre-existing type error where ToolRegistry.layer dependencies (Question.Service, Todo.Service) were not provided in harness.ts. Relates #43 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Wire MemoryExtractor into session processor pipeline (P1) - Fix phantom access_count increment in store.update() (P2) - Document beast.txt memory path inconsistency (P2) Refs #37, #43, #44 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Remove unused Bus and Config imports - Add sessions Map eviction at 100 entries to prevent memory leak - Add .catch() to maybeFlush to handle unhandled promise rejection Refs #43, #44, #45 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- get() returns fresh access_count after increment - memoryExtract respects memory.enabled flag - Cache config read instead of per-event Config.get() - Sync extracted memories to MEMORY.md file system - Retry failed flush entries instead of dropping - Reject empty filenames in entryPath Refs #43, #44, #45 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
3991f79 to
79106aa
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[Bug] GLM-5.1 thinking output corruption — repetition loop + tool call leak Memory: 自動保存トリガー(フィードバック・決定検出) Memory: セッション開始時MEMORY.md自動ロード + system prompt注入 Memory: SQLiteテーブル + ファイルシステム永続化レイヤー [Epic] Persistent Cross-Session Memory System
There was an error while loading. Please reload this page.