Skip to content

fix: synchronize deferred logging - #87

Closed
hugodutka wants to merge 1 commit into
coder/preview_v0_69from
fix/eng-3489-deferred-log-race
Closed

hugodutka wants to merge 1 commit into
coder/preview_v0_69from
fix/eng-3489-deferred-log-race

Conversation

@hugodutka

@hugodutka hugodutka commented Oct 28, 2026 •

Copy link
Copy Markdown

Trivy's process-wide default slog handler buffers records without synchronization. Concurrent ACP connection shutdowns in Coder race while appending to that buffer.

Protect the shared buffer across derived handlers, clone retained records, and forward subsequent records to the initialized handler after flushing. Add regression coverage for concurrent writers and concurrent flushing.

Consumed by coder/coder#31405.

Refs https://linear.app/codercom/issue/ENG-3489/flake-testagent-acpreadiness-data-race-in-trivy-slog-deferredhandler

Implementation and validation evidence

The mutex belongs to shared state rather than the handler itself so handlers created with WithAttrs synchronize access to the same buffer. Flushing detaches the buffer under the lock and invokes the target handler outside the lock. Existing loggers forward to that target instead of appending to an abandoned buffer or dereferencing nil state.

go test -race -shuffle=on -count=100 ./pkg/log passed. Removing synchronization made both new tests fail with data races and lost records. golangci-lint run ./pkg/log/... passed with no issues.

The matching Coder CI failure is https://github.com/coder/coder/actions/runs/40600292300.

Generated by Coder Agents on behalf of @hugodutka.

@linear-code

linear-code Bot commented Oct 28, 2026

Copy link
Copy Markdown

ENG-3489

@hugodutka hugodutka changed the title fix(pkg/log): synchronize deferred logging fix: synchronize deferred logging Oct 28, 2026
@hugodutka

Copy link
Copy Markdown
Author

Superseded by the requested approach: synchronize ACP SDK logger access and explicitly route ACP diagnostics through Coder logging. The replacement will be linked from coder/coder#31405. Generated by Coder Agents on behalf of @hugodutka.

@hugodutka hugodutka closed this Oct 28, 2026
hugodutka added a commit to coder/coder that referenced this pull request Oct 29, 2026
Route ACP SDK diagnostics through the workspace agent's Coder logger
instead of the process-wide standard slog logger, which Trivy replaces
with an unsafe buffering handler. Install the logger before starting the
harness so even immediate output and disconnects use the configured
logger.

Bump the ACP SDK to commit `0da7315c23b5`, which merged the synchronized
`SetLogger` fix into SDK main in
coder/acp-go-sdk#59. Preserve diagnostic levels
and structured fields, identify the harness, and omit raw protocol
frames that can contain conversation content or workspace secrets. The
previous Trivy dependency update is removed;
coder/trivy#87 is closed as superseded.

Fixes
https://linear.app/codercom/issue/ENG-3489/flake-testagent-acpreadiness-data-race-in-trivy-slog-deferredhandler

Generated by Coder Agents on behalf of @hugodutka.
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