Skip to content

feat(server): persist openwork-server logs to a rotating file - #4371

Merged
yomgui merged 4 commits into
devfrom
feat/server-log-file
Sep 3, 2026
Merged

yomgui merged 4 commits into
devfrom
feat/server-log-file

Conversation

@yomgui

@yomgui yomgui commented Sep 3, 2026

Copy link
Copy Markdown
Member

Why

The desktop runs openwork-server in-process, so its structured logger only reached Electron's stdout — invisible in packaged builds. Every Engine rollover requested. {engine.rollover.reason}, reload-watcher trigger, and MCP re-sync error was emitted and lost. Diagnosing today's engine churn (8 engine spawns in 25 min, each 1.1–1.6 GB) had to be reconstructed from sidecar run IDs and file mtimes; the actual rollover reasons are still unknown because nothing persisted them.

What

  • apps/server — OPENWORK_SERVER_LOG_FILE enables an append-only file sink (server-log-file.ts). It always receives structured JSON lines regardless of the stdout format, rotates once at 20 MB (file + file.1), disables itself on I/O errors, and redacts credential-looking attribute keys (authorization|token|secret|password|api[-_]?key|cookie|credential) before any line is written. Writes are synchronous appends on one descriptor; a stream opens its fd asynchronously and races the rotation rename.
  • apps/desktop — defaults the sink to <userData>/logs/openwork-server.log before the embedded bundle loads (the server memoizes the sink from process.env on first logger creation) and exposes logFilePath in the server snapshot.
  • apps/app — Settings › Debug shows Server log: <path> (en + ru).
  • packages/types — OpenworkServerInfo.logFilePath.

No behavior change for the CLI unless the variable is set.

Verification

Lane: local (no Daytona prerequisites are needed for this server-only spec; nothing app-driving).

pnpm evals:pr specs/server-log-file.test.ts
  ✓ openwork-server persists structured, credential-free logs when OPENWORK_SERVER_LOG_FILE is set  (1 passed, 0 failed, 0 skipped) exit 0

Boots the real src/cli.ts twice: with the variable → JSON lines including the listening line (service.name=openwork-server, run.id, process.pid) and a GET /health 200 line with status/durationMs, explicit --token/--host-token values absent, stdout still pretty; without the variable → no file, no directory.

pnpm --filter openwork-server test src/server-log-file.test.ts src/server-logger.test.ts   8 pass / 0 fail
pnpm --filter openwork-server typecheck                                                  exit 0
pnpm --filter @openwork/desktop exec node --test electron/runtime.test.mjs               29 pass / 0 fail
pnpm --filter @openwork/app typecheck                                                    exit 0
pnpm --filter @openwork/app exec bun test --isolate tests/diagnostics-bundle.test.ts tests/desktop-local-openwork.test.ts   12 pass / 0 fail

Verdict: Passed.

Follow-ups (separate PRs)

  1. Exclude volatile MCP auth headers from the engine-rollover fingerprint and shorten the drain window (uses this log to confirm the trigger).
  2. Engine-stall UX: classify stalled vs. down instead of the 10 s "OpenCode unavailable" toast.
  3. Give the isolated headless world its own OPENCODE_DB.

The desktop runs openwork-server in-process, so its structured logger only
reached Electron's stdout and was invisible in packaged builds: engine
rollover reasons, reload triggers, and MCP re-sync errors were emitted and
lost. Diagnosing today's engine churn required reconstructing the timeline
from sidecar run IDs and file mtimes.

- apps/server: OPENWORK_SERVER_LOG_FILE enables an append-only sink that
  always receives JSON lines regardless of the stdout format, rotates once
  at 20 MB (file + .1), disables itself on I/O errors, and redacts
  credential-looking attribute keys before any line is written.
- apps/desktop: default the sink to <userData>/logs/openwork-server.log
  before the embedded bundle loads and expose logFilePath in the server
  snapshot; Settings > Debug shows the path.
- evals/specs/server-log-file.test.ts boots the real CLI with and without
  the variable and asserts structured lines, no token material, and no file
  when unset.
@vercel

vercel Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 3, 2026 11:46pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
openwork-den Ignored Ignored Preview Sep 3, 2026 11:46pm UTC
openwork-diagnostics Ignored Ignored Preview Sep 3, 2026 11:46pm UTC
openwork-landing Ignored Ignored Preview Sep 3, 2026 11:46pm UTC

@yomgui

yomgui commented Sep 3, 2026 •

Copy link
Copy Markdown
Member Author

Test evidence — openwork-server-persists-structured-credential-free-logs-when-openwork-server-lo — ✅ passed

✅ passed · 4 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Server log lines are persisted as structured JSON

4 JSON lines at /var/folders/87/_t5df82d0bv7vnphlldtg_fc0000gp/T/openwork-server-log-spec-4NIKLl/userData/logs/openwork-server.log, including the listening line and a request line with status and durationMs, while stdout stays in pretty format.

  • ✅ PASS Server log lines are persisted as structured JSON — 4 JSON lines at /var/folders/87/_t5df82d0bv7vnphlldtg_fc0000gp/T/openwork-server-log-spec-4NIKLl/userData/logs/openwork-server.log, including the listening line and a request line with status and durationMs, while stdout stays in pretty format.

ℹ️ ASSERTION — 2. Persisted logs never carry the client or host token

The explicit --token and --host-token values are absent from the file even though the server logged startup and a request.

  • ✅ PASS Persisted logs never carry the client or host token — The explicit --token and --host-token values are absent from the file even though the server logged startup and a request.

ℹ️ ASSERTION — 3. Generated startup credentials remain on stdout but are redacted from the file

A real CLI boot without --token/--host-token printed both generated values for the operator; the JSON file contained only Client token: <redacted> and Host token: <redacted>.

  • ✅ PASS Generated startup credentials remain on stdout but are redacted from the file — A real CLI boot without --token/--host-token printed both generated values for the operator; the JSON file contained only Client token: <redacted> and Host token: <redacted>.

ℹ️ ASSERTION — 4. No file sink is created when OPENWORK_SERVER_LOG_FILE is unset

A second server booted without the variable served /health and created neither a log file nor its directory.

  • ✅ PASS No file sink is created when OPENWORK_SERVER_LOG_FILE is unset — A second server booted without the variable served /health and created neither a log file nor its directory.

Test run created 2026-09-03T23:45:51.077Z · Source: evals/results/test-runs/2026-09-03T23-45-51-076Z-openwork-server-persists-structured-credential-free-logs-when-openwork-server-lo/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4371 --test-run 2026-09-03T23-45-51-076Z-openwork-server-persists-structured-credential-free-logs-when-openwork-server-lo

Comment thread apps/server/src/server-log-file.ts Resolved
The file sink redacted credential-looking attribute keys but not message
bodies. CLI startup messages embed generated client and host tokens directly,
so enabling OPENWORK_SERVER_LOG_FILE persisted credentials that authenticate
to the server.

Build a separate file-only record that removes exact configured client, host,
and OpenCode passwords from message bodies and nested attribute values. Keep
stdout unchanged because generated CLI credentials must remain visible to the
person launching the server. Regression coverage asserts stdout retains them
while the file contains only <redacted>.
…d logs

Boot the real CLI without explicit tokens, assert the generated client and host
values remain visible on stdout for the operator, and assert the structured
file contains only <redacted> message bodies.
@yomgui

yomgui commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Addressed the high-severity token finding in f47dfe8: the persisted record now redacts exact client, host, managed-engine, and workspace engine passwords from message bodies and nested attributes. CLI stdout remains unchanged so generated credentials remain usable. The real-CLI test now boots without explicit tokens and proves generated values appear on stdout while the file contains only <redacted>. Final-head proof: 1/1 testkit spec, 9/9 focused logger tests, server typecheck exit 0.

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (f47dfe8c35ef1d5e590b0ebcf984f0532e37fd9d). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@yomgui
yomgui merged commit fe22022 into dev Sep 3, 2026
33 checks passed

This branch was successfully deployed

3 active (2 outdated) deployments
Preview – openwork-app — f47dfe8c Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-landing — a12c972b Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-den — a12c972b Deployed Sep 3, 2026 by vercel[bot]
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