Skip to content

fix(042): a panicking decision task answers internal_error - #466

Merged
bartekus merged 1 commit into
mainfrom
impl/042-panic-final
Nov 3, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/042-panic-final

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Closes the item spec 010's record left open against 042: a decision task that panics now ends with an answer.

Before

  • The stream ended without a final event, against 3.7.2's "final is never dropped".
  • The non-streaming call answered an empty HTTP 500.
  • The service began shutting down.

After (owner decision, 2026-11-03: reuse internal_error, no new refusal code)

  • The task's failure answers internal_error (HTTP 500, gRPC INTERNAL, no detail), as the response or as the stream's one final event. This is the same answer as a runtime invariant failure (spec 037 3.12.6).
  • It is counted in rustev_decision_task_panics_total.
  • The decision's retained entry is released as for any refusal, so a resubmission is answered again instead of staying decision_in_progress.
  • The service keeps serving.
  • No contract type changes.

Spec

042 3.7.2, the internal_error row of 3.5, a section 5 row and a record paragraph. 042 stays in-progress. Its completion PR follows once #459 lands and 031 closes.

Tests

integrations/rustev-serve/tests/handlers.rs: panicking_decision_task_answers_internal_error_and_keeps_serving, which uses a SYNTHETIC context source that panics. It checks the handler, a resubmission, the metric, an HTTP stream's single final, and a normal decision afterwards. COVERAGE.md gains the row.

Merge order

This PR and #459 both add a record paragraph to 042, so this one lands after #459 and is restacked then.

Locally: the new test, clippy -D warnings on rustev-serve, make gate and the authored-content check pass.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Looking at the four changed files: service.rs adds panic-handling logic and a new counter; handlers.rs adds a test for the new behavior; COVERAGE.md records the new test; spec.md amends spec 042 to describe the behavior.

service.rs

  • panic_key and panic_finished are cloned from key and finished just before the tokio::spawn(async move {...}), so they remain owned by the outer frame and are available to the unwrap_or_else closure. Structural ownership is correct.
  • On JoinError, the handler locks state, removes the entry (guarded by is_some()), recalculates state.bytes, drops the lock, then calls panic_finished.notify_waiters() unconditionally — the notification fires regardless of whether the entry was found, so any waiter polling finished is always woken. Correct.
  • Ordering::Relaxed on the counter is appropriate for a monotonically increasing metrics gauge.
  • The bytes recalculation is O(entries) while holding the lock — identical to every other path that touches the entry map, so no new concern.
  • The metrics key is "decision_task_panics_total"; the test asserts "rustev_decision_task_panics_total 2\n", consistent with the rustev_ prefix the existing metrics formatter applies to every key in that slice.

handlers.rs

  • The for _ in 0..2 loop dispatches two panicking non-streaming decisions and asserts each returns 500 / InternalError / empty detail, and that a subsequent lookup returns DecisionNotFound. This validates entry release and the "answered again, not decision_in_progress" guarantee from the spec.
  • assert!(!s.is_stopping()) confirms the service does not shut down.
  • The streaming portion sends a raw HTTP/1.1 request over tokio::io::duplex, reads to EOF under a 2-second timeout, and asserts one event: final with "code":"internal_error". This covers the stream path required by 3.7.2.
  • body("after-panic") is used in the final liveness assertion. I cannot confirm the fixture exists (repo context was truncated), but per review instructions I do not report absence of something I cannot observe as absent.

spec.md

  • The internal_error row in the refusal-code table is extended to cover both the existing invariant-failure case and the new panic case — no contradiction with the existing text.
  • Section 3.7.2 prose is added consistently with the implementation: counts the panic, releases the entry as for a refusal, keeps serving.
  • The acceptance map gains a row matching the test name and the behavior described.
  • The revision note is dated 2026-11-03 (today's date) and accurately describes what changed without claiming any contract-type changes.

No concrete defects found.

{"head": "4846be9e681e17181bd405ca7b8eb63abf991cea", "verdict": "no-findings", "findings": []}

Subject: 3dca8fd...4846be9, diff digest e5603e0956b419028e2d7913c8874642799230873dc91a43eebd69c0dde332c8, 1 call(s). An AI comment is not an approval.

Spec 010's record left this open against 042: a decision task that
panicked ended its stream without final, the non-streaming call answered
an empty HTTP 500, and the service began shutting down. The task's
failure now answers internal_error (500, INTERNAL, no detail) as the
response or the stream's final event, is counted in
rustev_decision_task_panics_total, releases the retained entry, and the
service keeps serving. 3.7.2, the internal_error row and section 5 are
amended; no contract type changes.
@bartekus
bartekus force-pushed the impl/042-panic-final branch from 4846be9 to 957fa52 Compare November 3, 2026 12:23
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Looking through the four changed files, I'm checking for bugs, security issues, and spec inconsistencies.

service.rs implementation

The unwrap_or_else handler on the spawned task's JoinHandle catches any JoinError and counts it as a panic. Tokio's JoinError distinguishes panics from cancellations (is_panic() / is_cancelled()). In this call site the JoinHandle is never stored or aborted, so cancellation cannot occur in practice; the conflation is theoretical, not a concrete defect.

The panic_key / panic_finished clones are correctly taken before the async move block that moves the originals. panic_finished.notify_waiters() is called after the state lock is released, which is the correct order. The full O(n) bytes recalculation (state.entries.values().map(|e| e.bytes).sum()) is safe if suboptimal; I cannot see that it diverges from the pattern used elsewhere from this diff alone.

The metric key "decision_task_panics_total" is consistent with the rustev_ prefix the metrics formatter adds, matching both the spec text (rustev_decision_task_panics_total) and the test assertion.

spec.md changes

The internal_error row in the refusal table is correctly extended to cover the panic case. The new 3.7.2 paragraph text matches the implementation (counted, entry released, service keeps serving, no detail). The revision note is dated 2026-11-03, consistent with today. The code comment cites Spec 042 3.7.2 and the spec edit is in that section.

Test

The test registers a plan, then issues two panicking requests and asserts: HTTP 500, InternalError code, empty detail, DecisionNotFound on lookup, counter at 2, service not stopping. It also drives a streaming request through the HTTP/1.1 transport and checks for one final SSE event containing "code":"internal_error". The keep-serving check uses body("after-panic") and asserts 200; the fixture is not in the diff, but the test's structure is internally consistent and CI would catch a broken fixture.

No concrete defects found.

{"head": "957fa52248295fea95a650a29fe5290eaa355b81", "verdict": "no-findings", "findings": []}

Subject: 1485f17...957fa52, diff digest 0e26c3e54fcc08103eb12a6e44074985257d5cf9811016bf6301300d6fdb9cd4, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit ff7b97a Nov 3, 2026
27 checks passed
@bartekus
bartekus deleted the impl/042-panic-final branch November 3, 2026 13:26
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