Skip to content

comicbox.config.online.settings ¶

Typed settings for the online-tagging block.

Split out of comicbox.config.settings because the online block is roughly half the config layer on its own.

Invariant: this module must not import comicbox.formats at runtime (TYPE_CHECKING-only is fine). comicbox.formats.* imports these settings, so a runtime import back would close a cycle; test_config_online_leaf pins it.

CacheMode ¶

Bases: StrEnum

Cache tri-state: on / off / refresh.

Source code in comicbox/config/online/settings.py
72
73
74
75
76
77
class CacheMode(StrEnum):
    """Cache tri-state: on / off / refresh."""

    ON = "on"
    OFF = "off"
    REFRESH = "refresh"

Effort ¶

Bases: StrEnum

API-call effort per comic, for fan-out sources.

Orthogonal to MatchMode (which controls how the matcher’s verdict is applied). Effort controls how aggressively pre-call algorithms trade accuracy for API throughput — it only bites on sources that fan out per candidate (ComicVine). Single-call sources (Metron since PR #143) have no fan-out to throttle and ignore it.

  • MINIMAL: aggressive pre-filtering; trade accuracy for throughput.
  • BALANCED: today’s behavior; the default.
  • THOROUGH: spend API budget freely; max accuracy.
Source code in comicbox/config/online/settings.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Effort(StrEnum):
    """
    API-call effort per comic, for fan-out sources.

    Orthogonal to ``MatchMode`` (which controls how the matcher's
    verdict is applied). ``Effort`` controls how aggressively pre-call
    algorithms trade accuracy for API throughput — it only bites on
    sources that fan out per candidate (ComicVine). Single-call sources
    (Metron since PR #143) have no fan-out to throttle and ignore it.

    - ``MINIMAL``: aggressive pre-filtering; trade accuracy for throughput.
    - ``BALANCED``: today's behavior; the default.
    - ``THOROUGH``: spend API budget freely; max accuracy.
    """

    MINIMAL = "minimal"
    BALANCED = "balanced"
    THOROUGH = "thorough"

MatchMode ¶

Bases: StrEnum

Match-resolution aggressiveness.

Strictly increasing aggressiveness: each level auto-writes a superset of what the previous one does (ask ⊂ careful ⊂ auto ⊂ eager). See match-resolution-user-doc.md for the full decision algorithm.

A StrEnum so dataclass equality, dict keys, JSON serialization, and str() all “just work”.

Source code in comicbox/config/online/settings.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class MatchMode(StrEnum):
    """
    Match-resolution aggressiveness.

    Strictly increasing aggressiveness: each level auto-writes a
    superset of what the previous one does (ask ⊂ careful ⊂ auto ⊂
    eager). See ``match-resolution-user-doc.md`` for the full
    decision algorithm.

    A StrEnum so dataclass equality, dict keys, JSON serialization, and
    ``str()`` all "just work".
    """

    ASK = "ask"
    CAREFUL = "careful"
    AUTO = "auto"
    EAGER = "eager"

OnlineAuthSettings dataclass ¶

Per-source credentials, indexed by source name.

Source code in comicbox/config/online/settings.py
146
147
148
149
150
@dataclass(frozen=True, slots=True)
class OnlineAuthSettings:
    """Per-source credentials, indexed by source name."""

    sources: Mapping[str, OnlineSourceCredentials] = field(default_factory=dict)

OnlineCacheSettings dataclass ¶

Where the online response cache lives and how long entries survive.

Source code in comicbox/config/online/settings.py
153
154
155
156
157
158
159
@dataclass(frozen=True, slots=True)
class OnlineCacheSettings:
    """Where the online response cache lives and how long entries survive."""

    mode: CacheMode = CacheMode.ON
    dir: Path | None = None
    ttl: timedelta = field(default_factory=lambda: timedelta(days=7))

OnlineLookupSettings dataclass ¶

What to look up and how aggressively to act on results.

Source code in comicbox/config/online/settings.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@dataclass(frozen=True, slots=True)
class OnlineLookupSettings:
    """What to look up and how aggressively to act on results."""

    # Runtime-only (CLI-derived; never lives in the config file).
    enabled: bool = False
    ids: Mapping[str, int] = field(default_factory=dict)
    series_ids: Mapping[str, int] = field(default_factory=dict)

    # Ordered source selection, run priority AND merge precedence: the
    # first listed source runs first; with ``first_wins`` its match ends
    # the lookup, and without it the first listed source wins every tag
    # the sources disagree on, except that each source keeps its own id
    # (see ``_set_merged_metadata``). None = every configured source in
    # SOURCE_NAMES order. Durable via the ``online.lookup.sources``
    # config-file key; CLI --online and COMICBOX_ONLINE__LOOKUP__SOURCES
    # override it.
    sources: tuple[str, ...] | None = None

    # Behavior toggles.
    match: MatchMode = MatchMode.AUTO
    prompts: Prompts = Prompts.ASK
    rematch: bool = False
    # Stop after the first source that contributes data (the cheap,
    # default mode). False = query every selected source and merge, the
    # first in ``sources`` order winning where they disagree
    # (CLI: --all-sources).
    first_wins: bool = True

OnlineSettings dataclass ¶

Online metadata-tagging settings, split into four concern groups.

Source code in comicbox/config/online/settings.py
227
228
229
230
231
232
233
234
@dataclass(frozen=True, slots=True)
class OnlineSettings:
    """Online metadata-tagging settings, split into four concern groups."""

    lookup: OnlineLookupSettings = field(default_factory=OnlineLookupSettings)
    auth: OnlineAuthSettings = field(default_factory=OnlineAuthSettings)
    cache: OnlineCacheSettings = field(default_factory=OnlineCacheSettings)
    tuning: OnlineTuningSettings = field(default_factory=OnlineTuningSettings)

OnlineSourceCredentials dataclass ¶

Resolved credentials for one online source.

Both sources take an API key and an optional url. The source’s is_configured() decides which fields are required.

Source code in comicbox/config/online/settings.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@dataclass(frozen=True, slots=True)
class OnlineSourceCredentials:
    """
    Resolved credentials for one online source.

    Both sources take an API ``key`` and an optional ``url``. The
    source's ``is_configured()`` decides which fields are required.
    """

    key: str | None = None
    url: str | None = None

    @override
    def __repr__(self) -> str:
        """Redact the key so this object is log-safe."""
        return (
            "OnlineSourceCredentials("
            f"key={'***' if self.key else None}, "
            f"url={self.url!r})"
        )

__repr__() ¶

Redact the key so this object is log-safe.

Source code in comicbox/config/online/settings.py
136
137
138
139
140
141
142
143
@override
def __repr__(self) -> str:
    """Redact the key so this object is log-safe."""
    return (
        "OnlineSourceCredentials("
        f"key={'***' if self.key else None}, "
        f"url={self.url!r})"
    )

OnlineSourceLimits dataclass ¶

Per-source rate-limit overrides.

All fields default to None, in which case comicbox lets the upstream library (mokkari / simyan) apply its own rate limits.

Documented defaults live in comicbox.formats.base.online.rate_limits for citation / audit.

Source code in comicbox/config/online/settings.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@dataclass(frozen=True, slots=True)
class OnlineSourceLimits:
    """
    Per-source rate-limit overrides.

    All fields default to None, in which case comicbox lets the upstream
    library (mokkari / simyan) apply its own rate limits.

    Documented defaults live in
    ``comicbox.formats.base.online.rate_limits`` for citation / audit.
    """

    # Metron overrides. mokkari tracks Metron's actual per-user limits
    # from `X-RateLimit-*` response headers rather than a fixed local
    # bucket. `per_minute` has been comicbox's `RateGate` ceiling since
    # 5.1.0 -- it can lower the server-reported burst limit, never raise
    # it, which is how several processes on one token split the window.
    # `per_day` is still accepted and ignored with a warning at client
    # build (see `_warn_ignored_rate_limit_overrides`).
    per_minute: int | None = None
    per_day: int | None = None
    # Historical ComicVine overrides. simyan builds its rate limiter
    # internally (1/sec, 200/hr) with no injection point; these are
    # accepted but ignored with a warning at client build.
    per_second: int | None = None
    per_hour: int | None = None

OnlineSourceTuning dataclass ¶

Per-source overrides for tuning knobs.

Any field left at None falls back to the global default in OnlineTuningSettings. Advanced fields (min_confidence, disambiguation_margin, solo_threshold) are undocumented in user-facing reference but live here so power users can adjust them per source via YAML.

Source code in comicbox/config/online/settings.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@dataclass(frozen=True, slots=True)
class OnlineSourceTuning:
    """
    Per-source overrides for tuning knobs.

    Any field left at None falls back to the global default in
    ``OnlineTuningSettings``. Advanced fields
    (``min_confidence``, ``disambiguation_margin``, ``solo_threshold``)
    are undocumented in user-facing reference but live here so power
    users can adjust them per source via YAML.
    """

    auto_threshold: float | None = None
    effort: Effort | None = None
    min_confidence: float | None = None
    disambiguation_margin: float | None = None
    solo_threshold: float | None = None
    rate_limit: OnlineSourceLimits = field(default_factory=OnlineSourceLimits)

OnlineTuningSettings dataclass ¶

Global tuning defaults plus per-source overrides.

Source code in comicbox/config/online/settings.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@dataclass(frozen=True, slots=True)
class OnlineTuningSettings:
    """Global tuning defaults plus per-source overrides."""

    # Global defaults. ``effort`` is None when no layer named one:
    # it resolves to ``Effort.BALANCED`` either way, but only an unset
    # effort may be auto-engaged down to ``MINIMAL`` for a large
    # unattended run (see ``auto_engage``). Collapsing the two states
    # meant an explicit ``--effort balanced`` was silently downgraded.
    auto_threshold: float = DEFAULT_AUTO_THRESHOLD
    effort: Effort | None = None
    retry_budget: int = 5

    # Per-source overrides (keyed by source name).
    per_source: Mapping[str, OnlineSourceTuning] = field(default_factory=dict)

Prompts ¶

Bases: StrEnum

Whether comicbox is allowed to prompt the user mid-run.

Source code in comicbox/config/online/settings.py
45
46
47
48
49
class Prompts(StrEnum):
    """Whether comicbox is allowed to prompt the user mid-run."""

    ASK = "ask"
    NEVER = "never"

resolve_auto_threshold(settings, source_name) ¶

Per-source auto_threshold override > global default.

Source code in comicbox/config/online/settings.py
249
250
251
252
def resolve_auto_threshold(settings: OnlineSettings, source_name: str) -> float:
    """Per-source auto_threshold override > global default."""
    override = _tuning_for(settings, source_name).auto_threshold
    return override if override is not None else settings.tuning.auto_threshold

resolve_disambiguation_margin(settings, source_name) ¶

Per-source override > built-in default. Not user-exposed today.

Source code in comicbox/config/online/settings.py
269
270
271
272
def resolve_disambiguation_margin(settings: OnlineSettings, source_name: str) -> float:
    """Per-source override > built-in default. Not user-exposed today."""
    override = _tuning_for(settings, source_name).disambiguation_margin
    return override if override is not None else DEFAULT_DISAMBIGUATION_MARGIN

resolve_effort(settings, source_name) ¶

Per-source effort override > global setting > BALANCED.

Source code in comicbox/config/online/settings.py
255
256
257
258
259
260
def resolve_effort(settings: OnlineSettings, source_name: str) -> Effort:
    """Per-source effort override > global setting > ``BALANCED``."""
    override = _tuning_for(settings, source_name).effort
    if override is not None:
        return override
    return settings.tuning.effort or Effort.BALANCED

resolve_match(settings, source_name) ¶

Per-source match mode falls back to the global default.

Source code in comicbox/config/online/settings.py
241
242
243
244
245
246
def resolve_match(settings: OnlineSettings, source_name: str) -> MatchMode:
    """Per-source match mode falls back to the global default."""
    # No per-source override on this knob (carried in the global
    # ``lookup.match``); helper exists for symmetry and future expansion.
    del source_name  # unused — kept for signature consistency
    return settings.lookup.match

resolve_min_confidence(settings, source_name) ¶

Per-source override > built-in default. Not user-exposed today.

Source code in comicbox/config/online/settings.py
263
264
265
266
def resolve_min_confidence(settings: OnlineSettings, source_name: str) -> float:
    """Per-source override > built-in default. Not user-exposed today."""
    override = _tuning_for(settings, source_name).min_confidence
    return override if override is not None else DEFAULT_MIN_CONFIDENCE

resolve_rate_limit(settings, source_name) ¶

Per-source historical rate-limit override values.

No override path exists for any source anymore — the values only feed the sources’ warn-and-ignore checks (mokkari>=4 tracks Metron’s limits from response headers; simyan manages ComicVine’s internally).

Source code in comicbox/config/online/settings.py
297
298
299
300
301
302
303
304
305
306
307
def resolve_rate_limit(
    settings: OnlineSettings, source_name: str
) -> OnlineSourceLimits:
    """
    Per-source historical rate-limit override values.

    No override path exists for any source anymore — the values only
    feed the sources' warn-and-ignore checks (mokkari>=4 tracks Metron's
    limits from response headers; simyan manages ComicVine's internally).
    """
    return _tuning_for(settings, source_name).rate_limit

resolve_solo_threshold(settings, source_name) ¶

Per-source override > this source’s resolved auto_threshold.

Phase E’s floor is defined as “the same bar as a multi-candidate unambiguous win”, so it tracks whatever auto-write bar this source actually runs at — global, per-source, CLI or env. A constant here would silently decouple the two: raising auto_threshold to 0.98 left a lone 0.96-scoring candidate auto-writing through a 0.95 back door that no configuration could close, and lowering it left the floor stricter than the bar it mirrors.

Lowering solo_threshold per source is the only way to make AUTO/EAGER’s solo carve-out reach below the auto-write bar (see _policy_auto_writes).

Source code in comicbox/config/online/settings.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
def resolve_solo_threshold(settings: OnlineSettings, source_name: str) -> float:
    """
    Per-source override > this source's resolved ``auto_threshold``.

    Phase E's floor is defined as "the same bar as a multi-candidate
    unambiguous win", so it tracks whatever auto-write bar this source
    actually runs at — global, per-source, CLI or env. A constant here
    would silently decouple the two: raising ``auto_threshold`` to 0.98
    left a lone 0.96-scoring candidate auto-writing through a 0.95 back
    door that no configuration could close, and lowering it left the
    floor stricter than the bar it mirrors.

    Lowering ``solo_threshold`` per source is the only way to make
    ``AUTO``/``EAGER``'s solo carve-out reach below the auto-write bar
    (see ``_policy_auto_writes``).
    """
    override = _tuning_for(settings, source_name).solo_threshold
    if override is not None:
        return override
    return resolve_auto_threshold(settings, source_name)