Skip to content

docs(loops): record the due-loop sweep, its idle cost and who reads the loop tables (#3436) - #3485

Draft
vybe wants to merge 2 commits into
devfrom
feature/3436-loops-idle-cost
Draft

vybe wants to merge 2 commits into
devfrom
feature/3436-loops-idle-cost

Conversation

@vybe

@vybe vybe commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #3436. One of five independent stale-code PRs off dev. Docs only — 39 lines added, 3 removed, four files under docs/memory/.

What

The issue asked for agent loops to cost nothing on an instance with no loops. The diagnosis found the cost is already negligible, and the operator ruled no code change (comment on the issue, 2026-10-09). This PR records what was found, so the next reader does not have to rediscover it.

  • architecture/background-services.md — a row for the loop due-run sweep, which was missing: started from main.py, first tick after 8–10 s, then every 5–6 s, in every backend worker with no leader lease (claim_due_loop decides which worker dispatches). With nothing parked it is one index seek on idx_loops_next_run returning no rows. The startup loop hook is renamed to what it does since feat(pull): make loops terminal-driven so they can run on the durable queue #2523: it re-arms or advances, and interrupts nothing.
  • requirements/scheduling.md — §38.8, the restart-recovery behaviour from feat(pull): make loops terminal-driven so they can run on the durable queue #2523, which had no requirements entry; §38.9, the idle cost and why the sweep is deliberately not gated. §38.1's older restart bullet is marked superseded.
  • architecture/execution.md — the sequential-loops paragraph described the pre-feat(pull): make loops terminal-driven so they can run on the durable queue #2523 in-process runner. It now describes the terminal-driven design: the row is the loop, stop stamps stop_requested_at, and the counter and fingerprint are rebuilt from the loop's run rows on every advance.
  • feature-flows/run-agent-loop.md — who reads the loop tables without being asked: the sweep, the boot reconcile, and the per-terminal get_loop_run_by_execution lookup, which cannot be gated because a loop run's terminal can land on a worker that never touched the loop.

Ruling carried (operator, recorded on the issue)

  • No code change. The sweep is the only continuous reader. Measured on a development database: about 6 µs per query, about 15,700 queries a day per worker. Gating it would add arm/disarm state to loop recovery and delay the pickup of a loop parked by a stuck worker until that worker is respawned.
  • Acceptance criterion 2 ("no recurring background query touches the loop tables") is re-ruled as met by cost, not by count. No index, no test change.

Review

/review (reading review, report-only): MERGEABLE. All 14 factual statements the diff adds were checked against the code on the branch tip, each with a quoted line, and are true. One is scoped rather than universal: "index seek" holds for SQLite; PostgreSQL may scan a table this small. Fixed after review: four stale sentences in the touched paragraphs. Docs only, so the security pass is a paragraph: nothing sensitive in the added lines.

Tests

Before merge

Nothing beyond review.

Handoffs (from the plan, not filed)

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 2 commits October 9, 2026 13:52
…he loop tables (#3436)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as it is (#3436)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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