Skip to content

Make command history appends concurrency-safe #1200

Description

@codeforester

Problem

Validated from Claude third-pass finding [86].

lib/python/base_cli/history.py::write_history_record() appends JSONL records with two separate writes and no file lock:

  • one write for the JSON payload
  • one write for the newline

Concurrent basectl invocations can interleave writes to ~/.cache/base/history/runs.jsonl, producing malformed JSONL records or joined lines. The file is also chmodded after append, which is fine for permissions but does not protect append atomicity.

Desired outcome

Make history JSONL writes safe under concurrent Base CLI invocations.

Scope

  • Add an appropriate lock around history append operations, or otherwise make each append atomic and documented.
  • Preserve existing history schema and redaction behavior.
  • Keep failures non-fatal, matching the current best-effort history behavior.
  • Add a focused test that would fail without the locking/atomic append guarantee.

Acceptance criteria

  • Concurrent history writes cannot interleave partial records.
  • History records remain one valid JSON object per line.
  • Existing history tests continue to pass.

Classification

Review finding taxonomy: implementation robustness.

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions