Skip to content

Memory Audit Diagnostics via DEBUG Log Stream - #12767

Open
rusak47 wants to merge 5 commits into
Kilo-Org:mainfrom
rusak47:pr/memory-audit-log
Open

Memory Audit Diagnostics via DEBUG Log Stream#12767
rusak47 wants to merge 5 commits into
Kilo-Org:mainfrom
rusak47:pr/memory-audit-log

Conversation

@rusak47

@rusak47 rusak47 commented Aug 1, 2026

Copy link
Copy Markdown

Issue

Fixes # — (no reported issue; related to #12674, #12675 and #12748)

Context

Memory-capture diagnostics have been invisible on main since 28d015f8fe ("fix(memory): refine CLI and extension experience" #12422 ) stubbed MemoryAudit.audit() into a no-op. The file-writing machinery it replaced was never called anywhere (record() had zero callers; readChanges/readDecisions are re-exported but unused), so no audit.log was ever produced — parse failures were silent.

Currently, when memory consolidation fails with JSON parse errors, there is no way to debug why the failure occurred. This makes it impossible to understand what model output triggered the failure or whether the schema needs adjustment.

Captured evidence of why this matters (DEBUG run, 2026-08-01): both digest and typed consolidation fell back with Invalid JSON response statusCode=200. The provider returned a valid JSON completion, but the client received the same JSON with an SSE data: [DONE] terminator appended (..."cost":"0"}data: [DONE]\n\n), which the non-streaming AI SDK path cannot parse → InvalidJSONResponseError → memory capture falls back silently. The full response was never visible in the log because the error-path append briefs the reason to 160 chars (MemoryShared.brief), while full= is only attached on the parse_error appends (see tmp/drafts/attachments/streaming-pr-followup-9router-evidence/9router-evidence-data-done-suffix.txt and tmp/drafts/attachments/streaming-pr-followup-9router-evidence/devlog-memory-error-2026-08-01.txt).

This PR restores visibility by routing the diagnostics through the standard DEBUG log stream (consistent with how the rest of the CLI logs) instead of reviving the dead audit.log file mechanism.

Implementation

  • MemoryAudit.audit() — the single choke point every capture decision funnels through (append/decide callers in capture/state/tool/operations/indexer) — now emits MemoryLog.debug("memory audit", input) instead of a no-op. All call sites are unchanged.
  • New MemoryLog.debug/setDebug seam in effect/log.ts (mirrors the existing warn/setWarn), wired to the CLI logger in runtime.ts — so output lands in the standard rotating data/log stream, gated by the normal log level.
  • The two parse-error memory.append sites (digest + consolidate) now include full=<raw model output> so the exact failing text is captured, not just the error brief.
  • Removed the dead file writer: record(), the zod Log schema, and MemoryFs parsing. Nothing that was reachable was dropped.
  • Dropped the separate KILO_MEMORY_DEBUG env gate and audit.log file concept — one gate, the standard log level.

Attachments

devlog-memory-error-2026-08-01.txt
9router-evidence-data-done-suffix.txt
devlog-memory-after-fix-2026-08-01.txt

How to Test

Manual/local verification

  • bun test in packages/kilo-memory: 169 pass (5 new routing tests in audit.test.ts).
  • bun run typecheck in packages/kilo-memory and packages/opencode: clean.

Reviewer test steps

  1. From a source/dev run (DEBUG is the default log level), trigger a memory capture where the model output fails parsing.
  2. Inspect the log stream (data/log/dev.log): entries memory audit with parse_error + full=<raw text> should appear.
  3. In a release build, verify the same requires KILO_LOG_LEVEL=DEBUG (or --logLevel DEBUG) — nothing logged at default INFO.

Blocked checks and substitute verification

  • None.

Bottom line

Full model/9router responses (full=) are logged at DEBUG — the most verbose tier and the dev default. To keep default runs minimal-noise while still allowing full-picture debugging of transport-level parse failures (e.g. the data: [DONE] corruption above), a TRACE level below DEBUG would let us gate raw full-response emission behind an explicit opt-in. Proposal for a follow-up: add TRACE to the log level schema (core/src/util/log.ts Level enum + levelPriority, opencode/src/kilocode/log.ts init literal, index.ts CLI choices) and emit full= payloads at TRACE instead of DEBUG. This PR intentionally keeps DEBUG parity and does not add the level.

Comment thread packages/kilo-memory/src/effect/capture.ts Outdated
Comment thread packages/kilo-memory/src/effect/capture.ts
Comment thread packages/kilo-memory/test/audit.test.ts
Comment thread packages/kilo-memory/test/audit.test.ts
@kilo-code-bot

kilo-code-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-memory/src/effect/capture.ts 430 Typed-consolidation path still appends full=${result.result.text} unredacted, uncapped, and with raw newlines; that completion is produced from a prompt containing existing_memory and full assistant text

SUGGESTION

File Line Issue
packages/kilo-memory/test/audit.test.ts 37 MemoryLog.setWarn is installed and never restored; module-global state leaks into later test files in the same bun test process
packages/kilo-memory/test/audit.test.ts 16 Test named "debug() is a no-op until a logger is injected" installs its own no-op and only asserts no throw - it never exercises the uninjected default
Files Reviewed (1 file changed since last review)
  • packages/kilo-memory/src/effect/capture.ts - 1 issue remaining

Resolved since the last review: the digest parse-error append (line 305) now routes the raw completion through MemoryRedact.text and caps it with MemoryShared.brief(..., 2000), which also collapses newlines so the one-entry-per-line log format holds. Applying the same wrapper at line 430 would close the remaining warning.

Fix these issues in Kilo Cloud

Previous Review Summary (commit 2d64473)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 2d64473)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-memory/src/effect/capture.ts 305 full=${result.result.text} bypasses MemoryRedact.text and MemoryShared.brief: raw model output (possible secrets/PII) is written to data/log unredacted, unbounded, and with raw newlines that break the one-entry-per-line log format
packages/kilo-memory/src/effect/capture.ts 430 Same unredacted/uncapped full= payload on the typed-consolidation path, whose prompt includes existing_memory and full assistant text

SUGGESTION

File Line Issue
packages/kilo-memory/test/audit.test.ts 37 MemoryLog.setWarn is installed and never restored; module-global state leaks into every later test file in the same bun test process
packages/kilo-memory/test/audit.test.ts 16 Test named "debug() is a no-op until a logger is injected" installs its own no-op and only asserts that calling it doesn't throw - it never exercises the uninjected default
Files Reviewed (6 files)
  • .changeset/memory-audit-log.md - 0 issues
  • packages/kilo-memory/src/effect/capture.ts - 2 issues
  • packages/kilo-memory/src/effect/log.ts - 0 issues
  • packages/kilo-memory/src/storage/audit.ts - 0 issues
  • packages/kilo-memory/test/audit.test.ts - 2 issues
  • packages/opencode/src/kilocode/memory/runtime.ts - 0 issues

Notes: the MemoryAudit dead-code removal (record, zod Log schema, readChanges parsing) was verified as unreachable - readChanges/readDecisions have no callers beyond the MemoryFiles re-exports. audit() becoming synchronous is safe: append/decide remain async, so existing .catch() call sites (e.g. storage/state.ts:26) still work.

Fix these issues in Kilo Cloud


Reviewed by claude-opus-5 · Input: 30 · Output: 4.3K · Cached: 613.3K

Review guidance: REVIEW.md from base branch main

rusak47 and others added 2 commits August 1, 2026 23:45
Co-authored-by: kilo-code-bot[bot] <240665456+kilo-code-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant