Skip to content

program: keep run shimmer alive past owning-session idle (clear on settle / terminal / inactivity) - #569

Merged
edwin-zvs merged 1 commit into
mainfrom
program-run-clear-on-liveness
Jun 28, 2026
Merged

edwin-zvs merged 1 commit into
mainfrom
program-run-clear-on-liveness

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Why

A live program run cleared all shimmer the instant the owning session went idle. Investigating the "canvas template" session: the agent did everything right — planning pass, kept `shimmer: true` on the one block it delegated, handed it to a subagent — then ended its own turn (AwaitingInput). The daemon's authoritative stop signal fired on that idle transition and reaped the entire run, wiping the still-pending shimmer ~11 minutes before the subagent (still running, 145 events) will finish.

Root cause: the stop signal is bound to the owning turn (note_session_state_for_program_run clears on AwaitingInput|Done|Errored after seen-running). But a self-scheduling agent — delegated subagents, a /loop, a background monitor — returns to idle as soon as it finishes dispatching, not when the work completes. There is no real turn boundary, so "owning session idle" ≠ "run done." This directly contradicts the pending-vs-settled contract (0048/0051): a block delegated to a subagent must keep shimmering until it settles.

What

Re-base the authoritative stop off the owning turn and onto the run itself. A run now clears when, in priority order:

  1. its pending set empties — every executed block has settled (declarations settle them);
  2. the owning session reaches a terminal state (done/errored) after being seen running — the agent is gone and can never settle the rest;
  3. an inactivity backstop expires — the existing 10-min cap, now refreshed by in-run program declarations/edits, firing only after the run goes silent.

AwaitingInput is no longer a stop signal for a run the agent is managing. Any in-run program declaration/edit (program_edit or program_update, both via narrow_program_run) sets a new agent_managed flag on ProgramRunProgress. An unmanaged optimistic run — one no declaration ever narrowed, e.g. on a non-declaring PTY harness — still clears on the idle transition, exactly as before, so dumb-harness shimmer remains turn-duration.

Changes

  • crates/protocol: new #[serde(default)] agent_managed: bool on ProgramRunProgress.
  • crates/daemon: narrow_program_run marks the run managed + refreshes the backstop; note_session_state_for_program_run splits AwaitingInput (clear only if unmanaged) from Done/Errored (always clear after seen-running). Two new lifecycle tests.
  • specs/0042: Stop-signal decision + consequences rewritten for the liveness model. specs/0048: the one "clears at turn end" clause corrected.

Client needs no change — it mirrors the daemon-published run state (on_program_state) and reaps on its local (now-refreshed) deadline.

Tests

  • program_run_managed_survives_idle_and_clears_on_settle — managed run survives AwaitingInput (incl. repeated wake/idle cycles), clears when the pending set empties.
  • program_run_managed_clears_on_terminal_state — terminal state clears even a managed run with pending blocks.
  • Existing test_program_run_lifecycle_daemon (unmanaged → clears on idle) unchanged and passing.
  • Full agentd + agentd-cli program/shimmer suites green (incl. the orchestrator + spinner tests).

Coordination

  • This is the lifecycle change discussed as orthogonal to program: declare per-block shimmer by stable content-id (spec 0053 + implementation) #567 (which is addressing-only and deliberately leaves 0042's stop signal as-is). Both edit specs/0042/0048 but on different lines; expect a trivial merge. No dependency either way.
  • The relevant binary is construct (the daemon runs as construct daemon run); the logic lives in crates/daemon + the crates/protocol field.

A before/after TUI recording would need a live delegation run that goes idle while a subagent works — happy to capture one if useful, but the surface is daemon lifecycle, so I left it out by default.

The daemon cleared a program run's entire shimmer the moment the owning
session returned to AwaitingInput after being seen running. For a run that
delegates work to subagents (or drives it with a /loop or background
monitor), the owning turn ends as soon as the hand-off is done while the
work is still in flight, so every pending-block shimmer was wiped early —
the opposite of the pending-vs-settled contract (specs 0048/0051).

Re-base the authoritative stop off the owning *turn* and onto the *run*:

- clear when the pending set empties (declarations settle every block);
- clear on a terminal owning-session state (done/errored) after seen-running,
  since the agent is gone and can never settle the rest;
- clear via an inactivity backstop (the existing 10-min cap, now refreshed by
  in-run program declarations/edits) once the run goes silent;
- AwaitingInput is no longer a stop signal for a run the agent is actively
  managing. Any in-run declaration/edit sets a new agent_managed flag on
  ProgramRunProgress; an unmanaged optimistic run on a non-declaring harness
  still clears on idle, exactly as before.

Update specs 0042 (stop-signal decision + consequences) and 0048 (the
turn-end clause). Adds two daemon lifecycle tests.
@edwin-zvs
edwin-zvs merged commit ffd56c0 into main Jun 28, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the program-run-clear-on-liveness branch June 28, 2026 19:11
edwin-zvs added a commit that referenced this pull request Jun 29, 2026
…053, break pending_block_signatures compat

main advanced with #569 (keep run shimmer alive past owning-session idle),
which reworked the same shimmer lifecycle and added agent_managed to
ProgramRunProgress, plus #563/#568 (specs 0051 custom-templates, 0052
session-removal-cascades).

Reconcile:
- protocol: keep pending_block_ids rename + the declared-shimmer types
  alongside #569's agent_managed field; DROP the pending_block_signatures
  serde alias (clean break, per request) and remove the legacy-compat test.
- daemon: fold #569's agent_managed + inactivity-backstop refresh into the
  declaration-based narrow_program_run and set_program_run_pending so a
  complete/partial declaration also marks the run agent-managed; #569's
  AwaitingInput/terminal stop-signal split is preserved. Adapt #569's two
  lifecycle tests to the id-based API.
- specs 0042/0048: combine #569's stop-signal model with the declared
  per-block-id model; my new spec collides with main's 0051/0052, renumbered
  to specs/0053-program-shimmer-block-addressing and all references updated.

cargo test --workspace green.
edwin-zvs added a commit that referenced this pull request Jun 29, 2026
…g (0053) (#576)

Diagnosed from the 'construct improvements' session: after the planning pass
declared the task pending, dispatching a subagent moved the task into the
"In progress" section and appended a @{session} clip — which changes the
block's text and therefore its id. The old id dropped from the pending set
before the new id was declared, so the set transiently emptied; the daemon
reaped the whole run on that empty, and the agent's follow-up re-declaration
of the new id hit a removed run and was a silent no-op. All shimmer vanished.
The agent's own narration: "the system won't re-light a settled/new block".

Fix #1 — survive transient empty. narrow_program_run / set_program_run_pending
no longer remove a run when its pending set empties; program_run_snapshot
reports no active run on empty but KEEPS the record so a later declaration
revives it. An empty run is reaped only on a terminal owning-session state,
the owning session going idle with nothing pending, or the inactivity
backstop (note_session_state handles the idle case).

Fix #2 — atomic keep_pending. Re-introduce a per-edit ProgramEdit.keep_pending
flag: an edit that changes a still-pending block re-adds the resulting block's
new id in the SAME narrowing call (anchored on the edit's new_string), so a
move/annotate never transiently empties the set and the agent needn't know the
post-edit id. The call-level shimmer id-list still handles declaring arbitrary
existing blocks (planning pass).

Specs 0042 (stop lifecycle: transient empty is not a stop), 0048 (contract:
use keep_pending when editing an in-flight block), 0053 (both mechanisms +
transient-empty survival). Three new daemon tests; #567/#569 tests unaffected.
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