Skip to content

feat(core): write logs as state jsonl#30966

Open
opencode-agent[bot] wants to merge 4 commits into
devfrom
feat/jsonl-log-file
Open

feat(core): write logs as state jsonl#30966
opencode-agent[bot] wants to merge 4 commits into
devfrom
feat/jsonl-log-file

Conversation

@opencode-agent
Copy link
Copy Markdown
Contributor

@opencode-agent opencode-agent Bot commented Jun 5, 2026

Summary

  • move local file logging into @opencode-ai/core/effect/logger and delete packages/core/src/util/log.ts
  • remove Log.init and the node Log export; CLI flags now set runtime env (OPENCODE_LOG_FILE, OPENCODE_LOG_LEVEL, OPENCODE_PRINT_LOGS) before Effect runtimes are built
  • keep the default log path as $XDG_STATE_HOME/opencode/log.jsonl
  • write structured JSONL records from Effect logging with ts, level, message, run_id, process_role, pid, service, and fields
  • remove out-of-context startup/fatal/process logs instead of recreating an out-of-band sink

Evidence

Fresh terminal-control snapshot is posted in PR comment: #30966 (comment)

Verification

  • bun test test/util/log.test.ts --timeout 30000
  • bun test test/effect/app-runtime-logger.test.ts --timeout 30000
  • bun test test/server/httpapi-sync.test.ts --timeout 30000
  • bun typecheck in packages/core
  • bun typecheck in packages/opencode
  • bun typecheck in packages/desktop
  • pre-push hook: bun turbo typecheck with Bun 1.3.14

@opencode-agent opencode-agent Bot requested a review from adamdotdevin as a code owner June 5, 2026 14:31
@opencode-agent
Copy link
Copy Markdown
Contributor Author

opencode-agent Bot commented Jun 5, 2026

Updated per review: removed Log.init, deleted packages/core/src/util/log.ts, and moved the JSONL sink into @opencode-ai/core/effect/logger so file logging happens through Effect.log* / EffectLogger.layer. Also removed the node Log export and stripped test Log.init setup.

Fresh terminal-control evidence from the updated tree:

default log file: /tmp/opencode/log-evidence.JOiat8/state/opencode/log.jsonl
raw jsonl:
{"ts":"2026-06-05T14:29:01.372Z","level":"INFO","message":"handle hello","run_id":"6c60e90b-8330-498e-8ff4-be9d8de060da","process_role":"main","pid":9121,"service":"evidence.handle","fields":{"answer":42}}
{"ts":"2026-06-05T14:29:01.373Z","level":"WARN","message":"effect warning","run_id":"6c60e90b-8330-498e-8ff4-be9d8de060da","process_role":"main","pid":9121,"service":"evidence.effect","fields":{"session.id":"session-1"}}
parsed summary:
{"level":"INFO","message":"handle hello","service":"evidence.handle","run_id":"string","pid":9121,"process_role":"main","fields":{"answer":42}}
{"level":"WARN","message":"effect warning","service":"evidence.effect","run_id":"string","pid":9121,"process_role":"main","fields":{"session.id":"session-1"}}

Verification run after this update:

  • bun test test/util/log.test.ts --timeout 30000
  • bun test test/effect/app-runtime-logger.test.ts --timeout 30000
  • bun test test/server/httpapi-sync.test.ts --timeout 30000
  • bun typecheck in packages/core
  • bun typecheck in packages/opencode
  • bun typecheck in packages/desktop
  • pre-push hook: bun turbo typecheck with Bun 1.3.14

@opencode-agent
Copy link
Copy Markdown
Contributor Author

opencode-agent Bot commented Jun 5, 2026

Terminal log output snapshot from this run:

INFO  2026-06-05T14:29:35 service=log.evidence answer=42 jsonl evidence
log_file=/tmp/tmp.rCzfMmNCmt/log.jsonl
{"ts":"2026-06-05T14:29:35.300Z","level":"INFO","message":"jsonl evidence","run_id":"6c60e90b-8330-498e-8ff4-be9d8de060da","process_role":"main","pid":9224,"service":"log.evidence","fields":{"answer":42}}

Verification on the pushed branch:

  • bun test test/util/log.test.ts --timeout 30000: 3 pass
  • bun test test/effect/app-runtime-logger.test.ts --timeout 30000: 4 pass
  • bun test test/server/httpapi-sync.test.ts --timeout 30000: 2 pass, 1 skip
  • bun typecheck in packages/core
  • bun typecheck in packages/opencode
  • bun typecheck in packages/desktop
  • pre-push hook passed: bun turbo typecheck with Bun 1.3.14

@opencode-agent
Copy link
Copy Markdown
Contributor Author

opencode-agent Bot commented Jun 5, 2026

Follow-up for logger-handle removal:

  • Removed the EffectLogger.create handle API and kept the concrete logger sink private to @opencode-ai/core/effect/logger.
  • Replaced app/test logger handle usage with direct Effect.log* + Effect.annotateLogs(...).
  • Removed out-of-Effect-context bridge logging (Effect.runSync(Effect.log*)) instead of preserving non-Effect logs.
  • Deleted the remaining console Log.create util and its actor usage.
  • Kept OTLP + file logging wired through EffectLogger.layerWith(...) without exporting the logger object.

Evidence:

$ grep search: EffectLogger.create|Log.create|EffectLogger.logger|Effect.runSync(Effect.log*)
# no matches in packages/**/*.ts

$ bun test test/util/log.test.ts --timeout 30000
3 pass, 0 fail

$ bun test test/effect/app-runtime-logger.test.ts --timeout 30000
4 pass, 0 fail

$ bun typecheck # packages/core
pass

$ bun typecheck # packages/opencode
pass

$ bun typecheck # packages/console/core
pass

$ PATH="/tmp/opencode/bun-1.3.14/node_modules/.bin:$PATH" git push origin feat/jsonl-log-file
pre-push: bun turbo typecheck
19 successful, 19 total

Commit: 45f257da7 refactor(core): remove logger handles

@opencode-agent
Copy link
Copy Markdown
Contributor Author

opencode-agent Bot commented Jun 5, 2026

follow-up for the logger-handle cleanup:

  • converted the remaining swallowed Effect-flow failures in bus and plugin to direct Effect.logError calls
  • fixed bus finalizers so Effect.logInfo("unsubscribing") actually executes instead of creating an unused Effect value
  • left desktop electron-log alone because it backs desktop debug export/crash/net logs outside the Effect runtime path

verification:

  • bun typecheck in packages/opencode
  • bun typecheck in packages/core
  • bun test test/util/log.test.ts --timeout 30000
  • bun test test/effect/app-runtime-logger.test.ts --timeout 30000
  • bun test test/server/httpapi-sync.test.ts --timeout 30000
  • pre-push bun turbo typecheck with Bun 1.3.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants