Skip to content

"Vibe-Trading: Your Personal Trading Agent"

docs(scheduling): self-contained docstrings and corrected operator guidance

shadowinlife14003a825d42
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a25b76b8b..f47a37778 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,7 +31,13 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(`VT_MEMORY_CONSOLIDATION`, `VIBE_BR_SYNC_ENABLED`) — and both default off
outside the shipped ZimaOS template, which hardcodes the scheduler and the
daily Brazil sync on. Cancelling a system job by hand-editing the store
- file is undone at the next startup; turning its flag off halts the row.
+ file is undone at the next startup; turning its flag off halts the row. A
+ system job that exhausted its retry budget (terminal `failed` after
+ consecutive dispatch failures) is reset to `pending` with its failure
+ counters cleared at the next startup while its flag is on — no API surface
+ can resurrect a protected row, so the startup reset is its only recovery
+ path; the `scheduled_research` agent tool's draft schema now also rejects
+ unknown keys (`additionalProperties: false`).
- Removed the vestigial `cron_service` residue from the channel stack
(manager.py constructor parameter, gateway_services.py dataclass fields,
channels_config_routes.py docstring), and corrected stale `env_schema.py`
diff --git a/agent/.env.example b/agent/.env.example
index 161da0932..52de6ec32 100644
--- a/agent/.env.example
+++ b/agent/.env.example
@@ -241,7 +241,10 @@ TUSHARE_TOKEN=your-tushare-token
# protected system job 'system:br-data-sync'. Opt-in; also needs the scheduler
# master switch (VIBE_TRADING_ENABLE_SCHEDULER=1, see below). VIBE_BR_SYNC_TIME
# (HH:MM, America/Sao_Paulo, default 21:30) sets the daily slot and drives the
-# FIRST seed only — later changes need a PATCH of the stored job.
+# FIRST seed only — the row is a protected system job (REST/CLI PATCH refuse
+# it), so retiming it later means editing the stored row's `schedule` field in
+# ~/.vibe-trading/scheduled_research/scheduled_research_jobs.json (a valid edit is trusted at the
+# next startup), or deleting that row and restarting to re-seed from this value.
# VIBE_BR_SYNC_ENABLED=false
# OCR engine for scanned PDF pages and images (auto by default).
diff --git a/agent/src/br_data/__init__.py b/agent/src/br_data/__init__.py
index 1367e4f88..c11ac56a8 100644
--- a/agent/src/br_data/__init__.py
+++ b/agent/src/br_data/__init__.py
@@ -10,8 +10,11 @@ Sources (all public, no key):
* Banco Central (SGS) — Selic, CDI, IPCA, IGP-M, PTAX and any other series.
* Tesouro Transparente — Tesouro Direto bond prices and yields.
-``python -m src.br_data sync`` downloads/refreshes everything;
-``python -m src.br_data daemon`` repeats it once a day. Readers
+``python -m src.br_data sync`` downloads/refreshes everything; the daily
+cadence runs as the protected system job ``system:br-data-sync`` inside the
+main service's scheduler (opt-in via ``VIBE_BR_SYNC_ENABLED`` — see
+:mod:`src.br_data.scheduling`). ``python -m src.br_data daemon`` is retired:
+it prints a migration notice and exits 0. Readers
(:mod:`backtest.loaders.b3_cotahist_loader`, ``get_br_market_data``) only
read the SQLite file.
"""
diff --git a/agent/src/br_data/sync.py b/agent/src/br_data/sync.py
index 6af66b70a..bf3dde23e 100644
--- a/agent/src/br_data/sync.py
+++ b/agent/src/br_data/sync.py
@@ -61,9 +61,9 @@ def run_sync(only: Iterable[str] | None = None, *, cotahist_from: int | None = N
def _next_run(hhmm: str) -> tuple[int, int]:
"""Parse a wall-clock "HH:MM" into cron ``(minute, hour)`` fields.
- Repurposed from the retired daemon's next-slot math (scheduler-unification
- T9): the cross-day arithmetic now belongs to the scheduling kernel
- (``next_due``), and this helper is the "HH:MM"→cron-field parser consumed
+ Repurposed from the retired daemon's next-slot math (scheduler
+ unification): the cross-day arithmetic now belongs to the scheduling
+ kernel (``next_due``), and this helper is the "HH:MM"→cron-field parser consumed
by :func:`src.br_data.scheduling.daily_cron_from_env`, which owns the
invalid-value fallback policy.
@@ -78,13 +78,14 @@ def _next_run(hhmm: str) -> tuple[int, int]:
def run_daemon(only: Iterable[str] | None = None) -> int:
- """Retired standalone daemon (scheduler-unification T9): notice + ``0``.
+ """Retired standalone daemon (scheduler unification): notice + ``0``.
The daily sync now runs as the protected system job
``system:br-data-sync`` inside the main service's scheduler. Prints the
migration notice and returns ``0`` in bounded time — exit code 0 is
deliberate and test-pinned: under compose ``restart: unless-stopped`` a
- non-zero exit would crash-loop the legacy sidecar until T10 removes it.
+ non-zero exit would crash-loop any deployment still invoking this
+ command until its compose template drops the sidecar.
Args:
only: Accepted for CLI compatibility and ignored (the system job
diff --git a/agent/src/config/env_schema.py b/agent/src/config/env_schema.py
index 97be98e18..efb4f1a76 100644
--- a/agent/src/config/env_schema.py
+++ b/agent/src/config/env_schema.py
@@ -261,7 +261,7 @@ class DataConfig(_EnvBase):
# FIRST seed of the daily sync system job (see ``vibe_br_sync_enabled``).
vibe_br_sync_time: str = Field(alias="VIBE_BR_SYNC_TIME", default="21:30")
# Opt-in gate for the protected daily-sync system job
- # (``system:br-data-sync``, scheduler-unification T9), read via
+ # (``system:br-data-sync``), read via
# src/br_data/scheduling.py. Deliberately not part of any preset, so
# enabling the scheduler never silently seeds a daily network sync;
# VIBE_BR_SYNC_TIME above drives the first seed's cron slot.
@@ -677,7 +677,7 @@ class MemoryConfig(_EnvBase):
description="Enable SQLite FTS5 search index",
)
- # Scheduled consolidation system job (scheduler-unification T8).
+ # Scheduled consolidation system job (scheduler unification).
# Deliberately NOT listed in the preset flag map or the memory flag alias
# map above: the preset machinery only touches fields in the alias map, so
# VT_MEMORY=on/full can never silently enable a background timer. This
diff --git a/agent/src/memory/consolidation.py b/agent/src/memory/consolidation.py
index 369b94268..528c09bef 100644
--- a/agent/src/memory/consolidation.py
+++ b/agent/src/memory/consolidation.py
@@ -1,4 +1,4 @@
-"""Scheduled memory consolidation (scheduler-unification T8).
+"""Scheduled memory consolidation (scheduler unification).
Thin orchestration surface consumed by the scheduler; it adds NO semantics of
its own — every behavior lives in the existing memory modules and this module
@@ -16,7 +16,7 @@ only decides *whether* and *how* to call them:
``asyncio.to_thread``, so the blocking GC/compression pass never runs on the
event loop.
-Honest no-op contract (plan T8 ②b(ii)): archive GC is gated by
+Honest no-op contract: archive GC is gated by
``VT_MEMORY_GC`` and compression is only ever invoked through GC's
archive→compress handoff (``lifecycle.run_gc`` is the sole production caller
of ``CompressionPipeline``), so with GC off there is nothing this job can
@@ -25,7 +25,7 @@ rather than faking work. ``VT_MEMORY_DECAY`` off degrades importance to raw
quality scores (existing ``compute_importance`` behavior); that is noted in
the log but still a real consolidation pass.
-Concurrency contract (plan T8 ②b(iii)): writes are serialized by the memory
+Concurrency contract: writes are serialized by the memory
layer's own ``memory_lock`` (``fcntl.flock`` on ``<memory_dir>/.lock``) taken
PER ACTION inside ``lifecycle`` — this module must NOT hold that lock around
``run_gc`` because the inner per-action acquisitions would then conflict with
@@ -83,8 +83,8 @@ def consolidate(memory_dir: Optional[Path] = None) -> None:
logger.info("memory consolidation skipped: VT_MEMORY_CONSOLIDATION is off")
return
if not cfg.gc_enabled:
- # Plan ②b(ii): GC gates BOTH the archive pass and the archive→compress
- # handoff, so without it there is nothing to truthfully consolidate.
+ # GC gates BOTH the archive pass and the archive→compress handoff, so
+ # without it there is nothing to truthfully consolidate.
logger.info(
"memory consolidation no-op: VT_MEMORY_GC is off — archive GC and the "
"archive→compress handoff are both gated by it; no files were touched"
@@ -104,8 +104,8 @@ def consolidate(memory_dir: Optional[Path] = None) -> None:
memory = PersistentMemory(memory_dir=memory_dir)
lifecycle = MemoryLifecycle(memory)
- # Plan ②b(i): run_gc's default is dry_run=True (audit-only). The scheduled
- # pass MUST archive for real, so dry_run=False is passed explicitly.
+ # run_gc's default is dry_run=True (audit-only). The scheduled pass MUST
+ # archive for real, so dry_run=False is passed explicitly.
actions = lifecycle.run_gc(dry_run=False)
archived = sum(1 for a in actions if a.get("action") == "archive")
logger.info(
diff --git a/agent/src/scheduled_research/store.py b/agent/src/scheduled_research/store.py
index bcd2fcbda..35874630a 100644
--- a/agent/src/scheduled_research/store.py
+++ b/agent/src/scheduled_research/store.py
@@ -8,7 +8,7 @@ A missing store file is the only clean empty result. A file that exists but
fails to parse is quarantined and ``load`` raises ``CorruptStoreError`` instead
of silently returning an empty list.
-Single-writer invariant (scheduler-unification T12): the sole owner of the
+Single-writer invariant (scheduler unification): the sole owner of the
store is the FastAPI lifespan in ``agent/api_server.py``, which starts exactly
one executor per process (``src/api/scheduled_routes.py``'s singleton). The
atomic replace below protects readers against torn files, but there is NO
diff --git a/agent/src/scheduling/triggers.py b/agent/src/scheduling/triggers.py
index 5ec3ab3ea..65fcd4b5b 100644
--- a/agent/src/scheduling/triggers.py
+++ b/agent/src/scheduling/triggers.py
@@ -1,6 +1,6 @@
"""Trigger grammar and next-run math for the shared scheduling kernel.
-Extracted verbatim (scheduler-unification T1) from two prior owners so every
+Extracted verbatim (scheduler unification) from two prior owners so every
scheduler in the repo can share one trigger vocabulary:
* the schedule grammar — interval-ms strings and simplified 5-field cron with
diff --git a/zimaos/README.md b/zimaos/README.md
index 0989eb7a8..e725afbbf 100644
--- a/zimaos/README.md
+++ b/zimaos/README.md
@@ -47,11 +47,21 @@ separate sidecar container or Compose profile: it now runs inside the main
application container as the protected system job `system:br-data-sync`, which
is seeded and fires only while the main service sets **both**
`VIBE_TRADING_ENABLE_SCHEDULER=1` and `VIBE_BR_SYNC_ENABLED=1`. This compose
-template sets both; set either to `0` to keep the daily network sync off. The
-first sync is no longer launched at container start but at the next
+template sets both; set either to `0` to keep the daily network sync off.
+Note the coupling this creates: `VIBE_TRADING_ENABLE_SCHEDULER=1` is the
+master switch for the whole scheduled-research executor, so besides the sync
+job it also runs **your own** stored scheduled research runs inside this
+container (each firing is an agent run and consumes model tokens). The first
+sync is no longer launched at container start but at the next
`VIBE_BR_SYNC_TIME` slot (São Paulo wall clock, default 21:30), after B3 and
-CVM publish the day's files. `VIBE_BR_SYNC_TIME` drives the **first seed** only
-— changing it later needs a PATCH of the stored job row, not a compose edit.
+CVM publish the day's files, and that multi-GB first download now shares this
+main service's memory/CPU budget (the dedicated sidecar is gone).
+`VIBE_BR_SYNC_TIME` drives the **first seed** only — the row is a protected
+system job (REST/CLI PATCH and DELETE refuse it), so retiming it later means
+editing the `schedule` field of the stored row in
+`~/.vibe-trading/scheduled_research/scheduled_research_jobs.json` (a valid edited schedule is
+trusted at the next startup), or deleting that row and restarting to re-seed
+from the env value.
Historical coverage starts at `VIBE_BR_COTAHIST_START_YEAR` (default 2015) and
`VIBE_BR_CVM_START_YEAR` (default 2022). No sync is launched by opening the UI.
@@ -79,7 +89,13 @@ ativada neste modelo por `VIBE_TRADING_ENABLE_SCHEDULER=1` e
`VIBE_BR_SYNC_ENABLED=1` (defina qualquer um dos dois como `0` para mantê-la
desativada). A primeira sincronização não ocorre ao iniciar o contêiner, mas no
próximo horário `VIBE_BR_SYNC_TIME` (fuso de São Paulo, padrão 21:30); esse
-valor vale apenas para a primeira criação da tarefa — mudanças posteriores
-exigem um PATCH na linha da tarefa armazenada. As atualizações automáticas
+valor vale apenas para a primeira criação da tarefa. Como a tarefa é
+protegida (PATCH/DELETE via REST e CLI são recusados), mudar o horário depois
+exige editar o campo `schedule` da linha armazenada em
+`~/.vibe-trading/scheduled_research/scheduled_research_jobs.json` (uma edição válida é aceita na
+próxima inicialização), ou apagar a linha e reiniciar para recriá-la a partir
+do valor do ambiente. Lembre que `VIBE_TRADING_ENABLE_SCHEDULER=1` também
+executa suas próprias pesquisas agendadas no contêiner principal (cada
+disparo consome tokens do modelo). As atualizações automáticas
ficam desativadas por padrão. O workflow é um modelo inativo para seu próprio
fork; não publica no upstream.
diff --git a/zimaos/docker-compose.yml b/zimaos/docker-compose.yml
index f0de67fdd..ca99bcb51 100644
--- a/zimaos/docker-compose.yml
+++ b/zimaos/docker-compose.yml
@@ -73,10 +73,15 @@ services:
# seeded and fires only while BOTH flags below are set. The first sync
# is no longer launched at container start but at the next 21:30
# America/Sao_Paulo wall time; the initial download can be several GB
- # and later runs only fetch what changed. VIBE_BR_SYNC_TIME drives the
- # FIRST seed only — changing it later needs a PATCH of the stored job
- # row, not an edit here. Set either flag to "0" to keep the daily
- # network sync off.
+ # (now sharing this service's resource budget) and later runs only
+ # fetch what changed. VIBE_BR_SYNC_TIME drives the FIRST seed only —
+ # the row is a protected system job (REST/CLI PATCH refuse it), so
+ # retiming it later means editing the stored row's `schedule` field in
+ # scheduled_research/scheduled_research_jobs.json, or deleting that row and restarting to
+ # re-seed. NOTE: VIBE_TRADING_ENABLE_SCHEDULER=1 is the master switch
+ # for ALL scheduled research — it also runs the user's own stored
+ # scheduled runs (agent runs consuming model tokens) in this service.
+ # Set either flag to "0" to keep the daily network sync off.
VIBE_TRADING_ENABLE_SCHEDULER: "1"
VIBE_BR_SYNC_ENABLED: "1"
VIBE_BR_SYNC_TIME: "21:30"