Skip to content

fix(graph-buffer): log why an atomic publish failed instead of a successful dump - #2259

Merged
DeusData merged 2 commits into
mainfrom
carry/2051-atomic-publish-errno
Sep 21, 2026
Merged

DeusData merged 2 commits into
mainfrom
carry/2051-atomic-publish-errno

Conversation

@DeusData

Copy link
Copy Markdown
Owner

This is #2051 by @junk151516, rebased onto current main by the maintainer. His commit, his authorship, his sign-off — unchanged except for one conflict resolution. #2051 stays open until this merges, then closes with credit.

Why a carried branch

#2051 was approved on merit today, and the actual merge attempt found one conflict in src/graph_buffer/graph_buffer.c: the PR adds a log_dump_failed(...) call ahead of three free calls that yesterday's memwaste merge converted to cbm_free. Resolved by keeping both — main's cbm_free with his log call ahead of it. Nothing else in the four files conflicted, and no raw allocator calls are added (checked against the memory-core linter's regex).

The alternative was asking him to rebase after we had already sat on the PR for sixteen days. Carrying one hunk with his authorship intact seemed the fairer trade.

What the fix does

The cleanup path was destroying the evidence of the failure it was cleaning up after: unlink during cleanup clobbers errno, so an atomic-publish failure reported the wrong reason or none. errno is saved before cleanup and restored after, at three sites — and his comment names the part people get wrong: a successful library call may set errno, so reading it late yields a plausible but fictional cause. The translated platform error from cbm_rename_replace (#1620) survives the cleanup, and the two truncation cases where nothing sets errno are named explicitly.

Verification on the rebased result

…essful dump

cbm_gbuf_dump_to_sqlite() emitted gbuf.dump regardless of the writer's
result, so a run that published nothing still logged node and edge counts
as if it had worked, and the failure reached the user only as the generic
"Pipeline failed. Check repo_path exists and contains source files."

The writer's temp -> final rename in publish_writer_output() returned a
bare ERR_WRITE_FAILED. #1628 taught cbm_rename_replace() to translate the
platform error into errno so callers could report why, and wired up the
stage -> final rename in pipeline.c. This is the other rename on that
path, and it is the one that runs first.

Preserve errno across the cleanup in every publish error branch. That
includes cbm_writer_open(), where the cleanup unlinks a file that was never
created: without the save it leaves ENOENT behind, so a directory that
denied the create is reported as a missing path — the #1620 case, stated
wrongly. Read the value in graph_buffer.c before the profiling macro can
clobber it, and report gbuf.dump_failed with the return code and that errno.
A sticky append failure clears errno rather than attach a reason it does not
have, and the field is omitted when there is none. No logging is added
inside internal/cbm/, which has none today.

Tests cover both halves: the dump reports a failure instead of a summary,
the writer names its truncation reason, and the publish rename's errno
survives a cleanup that itself fails.

Refs #1620, #2001.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012FxkVF773gDGNmBmsLnzN7
Signed-off-by: juan Carlos Estrada Montoya <junk151516@users.noreply.github.com>
@DeusData
DeusData merged commit d615088 into main Sep 21, 2026
40 checks passed
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.

2 participants