Skip to content

test(contract)!: stop the trial broker with SIGTERM alone - #218

Merged
groupsky merged 2 commits into
mainfrom
fix/214-contract-trial-stop
Nov 18, 2026
Merged

groupsky merged 2 commits into
mainfrom
fix/214-contract-trial-stop

Conversation

@groupsky

@groupsky groupsky commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #214

The contract tests sometimes failed at the end, with "the trial broker did not stop cleanly: exit status 1", and no test failed.

The cause is the harness, not nodkey try. trial.stop() in test/contract/harness_linux_test.go closed the stdin of nodkey try, and then sent SIGTERM. nodkey try reads the answers on its stdin. When its input ends, no answer can come any more, so it stops with exit status 1 and says "the terminal approver stopped" (serveTry in cmd/nodkey/try.go). This is on purpose, and TestTryStopsWhenTheInputEnds in cmd/nodkey tests it. After SIGTERM alone, nodkey try ends with exit status 0 (TestTryApproveWindow, TestTryExpiry, TestTryDeny, TestTryStopsOnHangup check this with SIGTERM, SIGINT and SIGHUP). So the harness started a race between two ways to stop: the end of the input (exit 1) and the signal (exit 0). Most often the signal won. Sometimes the end of the input reached serveTry first.

nodkey try is right, so cmd/nodkey does not change.

The change:

  • stop() sends only SIGTERM. It waits until the stdout of nodkey try is closed (so the harness has read every line), and then calls Wait, which closes the stdin. A process that has already ended is not an error of the signal; Wait still gives its exit status.
  • WaitDelay caps Wait, and the two timeouts have their own error text.
  • When the stop fails, runTests prints what nodkey try wrote (tr.output()). It holds names and short codes, never a value.
  • docs/updating.md: the README of test/contract/ says that a change to the harness counts as a change in behavior for callers. So this pull request answers "yes" and adds a section. It says that no caller is affected: nodkey run and nodkey try did not change, and no release had the old harness.

Behavior for callers

Changes behavior for existing callers: yes

(Only because of the rule for files under test/contract/. No caller of nodkey run sees a change.)

Tests

  • go test -race ./..., go vet ./..., golangci-lint run --build-tags e2e.
  • A temporary CI step runs the contract package 20 separate times in a row (go test -race -count=1 ./test/contract/), with the Go of go.mod and with Go stable. It is removed before the merge.

Progress

Checklist

  • The title follows Conventional Commits.
  • Tests cover the deny paths: a failed stop still fails the package (exit 1), and now with the output.
  • The docs are updated: docs/updating.md. DESIGN.md and THREAT-MODEL.md do not change: no message, check or path of a value changes.
  • The security review is done.
  • No private data.

🤖 Generated with Claude Code

The harness closed the stdin of nodkey try and then sent SIGTERM. At the
end of its input, nodkey try stops with exit status 1, by design, so the
two raced. Now the harness sends only SIGTERM, reads all that nodkey try
wrote, and then waits. When the stop fails, it prints what nodkey try
wrote.

Fixes #214

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky force-pushed the fix/214-contract-trial-stop branch from 28177f5 to 10404ba Compare November 18, 2026 21:06
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky marked this pull request as ready for review November 18, 2026 21:13
@groupsky
groupsky merged commit a2fac55 into main Nov 18, 2026
8 of 9 checks passed
@groupsky
groupsky deleted the fix/214-contract-trial-stop branch November 18, 2026 21:17
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.

test: the contract tests sometimes fail at the end: the trial broker did not stop cleanly

1 participant