Skip to content

Share Console stream lifecycle behind one subscription - #1239

Merged
JacobStephens2 merged 2 commits into
mainfrom
issue-1238
Oct 24, 2026
Merged

JacobStephens2 merged 2 commits into
mainfrom
issue-1238

Conversation

@JacobStephens2

@JacobStephens2 JacobStephens2 commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Inbox notices and live log streams now ask one Console subscription when they may do their next work turn. The subscription owns the viewer recheck, revisions, sleeping, channel closure, permanent termination and the shared observer lease. Each caller still builds its own payload and presents its own errors.

 src/console/
+├── subscription.rs        # new(changes, viewer, &notifier); ready(Wait | Drain) -> Result<bool>
+│   └── tests.rs           # scripted-check scheduling tests on real watch channels
 ├── live.rs                # Inbox: ready(Wait) -> `commands` notice
 ├── logs.rs                # log SSE: ready(Drain) before each batch, ready(Wait) after an empty unfinished read
 └── watching.rs            # + #[cfg(test)] Following::idle()
ready(mode)
  terminated                             -> false (forever)
  loop
    channel closed                       -> false, release lease
    accounts revision unchecked          -> still_allowed() off the executor (non-refreshing)
                                            denied -> false; error -> Err once; then loop to recheck
    Drain, or Commands revision is new   -> record Commands revision, true
    sleep until the next change

Log batches drain without waiting for another notification, and a log stream sleeps only after an empty unfinished read. A change that arrives during a read stays unseen, so the next wait returns at once.

Evidence

  • New console::subscription::tests (10 tests): first readiness, account-only change, wait versus drain, coalescing, a revision arriving during authorization, a change during a read, closure (including closure during a check), denial and errors, permanent termination, and lease release on termination or drop. All pass.
    • Deleting the post-check continue fails a_revision_arriving_during_authorization_is_checked_before_work.
    • Deleting the has_changed() closure check fails closure_permits_no_further_work_and_releases_the_lease.
  • Buffered-log regression a_log_buffered_across_several_batches_streams_every_byte_without_another_change: the log is more than 3 × 256 KiB, the writer has finished, and nothing is appended. The stream delivers every line in order, with increasing offsets and exactly one final done:true.
    • Before (logs start in Wait, so the stream waits after every batch): reqwest::Error { kind: Decode, source: TimedOut }.
    • After: passes.
  • Real-account HTTP tests: an_open_log_stream_closes_when_its_session_is_revoked now covers CLI sign-out, password reset and allowlist removal, matching the Inbox test. Both pass.
  • Child-clock expiry: python3 tests/console/session-expiry.py --binary target/debug/thirdshift --settle-seconds 65 now opens both routes. Output: {"expired_session_received_changes": {"inbox": false, "log": false}, "stream_closed": {"inbox": true, "log": true}, "reader_errors": []}.
  • Retained regressions pass: idle_viewers_sleep_and_log_appends_and_completion_wake_the_reader, outcome_does_not_finish_sse_or_polling_before_the_writer_exits, process_death_finishes_the_existing_reader_without_a_record_write, log_stream_starts_at_the_byte_offset_and_sends_only_appended_html.
  • Full Rust suite (cargo test --no-fail-fast; nextest is not installed): 2,494 passed, 3 failed. Every integration target passes.
    • The 3 failures are all in worktree::synchronization_tests, with git tag … failed: fatal: no tag message?. The cause is this host's global tag.gpgsign = true.
    • With GIT_CONFIG_GLOBAL pointing at a config that holds only a user identity, cargo test --bin thirdshift worktree::synchronization_tests passes 36 of 36.
    • scripts/affected-tests origin/main selects the full Rust suite. Its cargo test run stopped at those same three unit failures, which is why the full suite was rerun with --no-fail-fast.
  • Lint and format: cargo clippy --all-targets reports no warnings, and cargo fmt --check is clean.

Merge Danger

Door: two-way

This internal refactor changes no data, config or domain behaviour, and a revert restores the old loops.

Blast Radius: Console streams

If the subscription were wrong, open Inbox pages or log readers could miss updates, stall on buffered output, or stay open after revocation. The tests above pin each of those cases. After an empty unfinished read, a log stream now wakes only on Commands or accounts revisions, no longer on executable-only revisions. Log appends and writer exits already bump Commands.

Review

Both axes were reviewed against origin/main (4519277). The local main ref was stale. Every changed file was read by both reviewers; no changed file was left unread.

  • Standards: no hard violations. 6 judgement-call smells: 4 addressed in 239be80, 2 declined below.
  • Spec: meets the spec. One coverage gap, closure during a successful check in Drain mode, was addressed in 239be80.

Unaddressed findings

Standards

  • Primitive Obsession: ready(...) -> Result<bool> could be a two-variant enum. Declined because the plan settles it. Decision 4 says readiness "returns an ordinary result containing a readiness boolean. True permits one work turn; false means normal terminal closure." (src/console/subscription.rs, pub async fn ready(&mut self, mode: Readiness) -> Result<bool>).
  • Speculative Generality: the permanent-closure latch duplicates state.done in logs.rs. Declined because both are required.
    • Decision 8 says "Make terminal results permanent … later readiness calls return false", and the acceptance criteria say "No further payload is produced after a terminal result." The test denial_and_check_failures_end_the_subscription_permanently covers this.
    • state.done marks the caller's own final batch and read errors, which Decision 2 leaves with the caller.
  • Duplicated Code: session-expiry.py writes the Command record by hand, not through the Rust fixtures. The opaque failure the reviewer raised is fixed: the script now asserts that the log link exists. The record copy stays. Decision 11 asks to "Extend the existing child-clock expiry fixture", which is a standalone Python script that cannot call the Rust record() helper.

Spec

None.

Security

None.

Closes #1238

Built with claude · claude-opus-5-5 · high

Security review outcome

No unaddressed introduced findings.

Inbox notices and live log streams now ask one Console subscription when
they may do their next work turn. It owns the non-refreshing viewer
rechecks on account revisions, sleeping until Commands change or draining
buffered log output, channel closure, permanent termination and the shared
live-work observer lease. Callers keep their own payloads and error
presentation.

Tests cover the subscription's scheduling deterministically, extend the
log route's revocation test to password reset and allowlist removal, add a
regression for logs buffered beyond two batch budgets, and run the
child-clock expiry check against both routes.
…re revocations

Name the subscription's last authorized accounts and granted Commands
revisions, cover closure during a successful check for both modes, share
the revocation switch between the two stream tests, rename the buffered
log regression after what it buffers and fail clearly when the expiry
script cannot find its live log.
@JacobStephens2
JacobStephens2 merged commit c7d506e into main Oct 24, 2026
18 checks passed
@JacobStephens2
JacobStephens2 deleted the issue-1238 branch October 24, 2026 09:02
@JacobStephens2 JacobStephens2 mentioned this pull request Oct 24, 2026
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.

Deepen Console live streams behind one subscription interface

1 participant