Skip to content

fix: Division by zero protection is ineffective#2

Open
coe0718 wants to merge 1 commit into
mainfrom
fix/src-context-adaptive-6du7u
Open

fix: Division by zero protection is ineffective#2
coe0718 wants to merge 1 commit into
mainfrom
fix/src-context-adaptive-6du7u

Conversation

@coe0718
Copy link
Copy Markdown
Owner

@coe0718 coe0718 commented May 3, 2026

Description

Replacing f32::EPSILON with 1.0 prevents extreme scale factors when budget totals are small but non-zero. Both base_total and adjusted_total are updated to use this reasonable minimum. The change keeps the adaptive scaling bounded as intended.

Finding: CRITICAL — Division by zero protection is ineffective
File: src/context/adaptive.rs

Risk Assessment

  • Blast radius: Single file, single concern
  • Change type: Surgical fix — Replacing f32::EPSILON with 1.0 prevents extreme scale factors when budget totals are small but non-zero. Both base_tota
  • Breaking potential: Low — narrow scope, well-defined fix

Validation

  • Test: cargo test
  • Fallback: git apply --check fix.diff && cargo check

Generated by Archiview · Autonomous AI Audit

…udget totals are small but non-zero. Both base_total and adjusted_total are updated to use this reasonable minimum. The change keeps the adaptive scaling bounded as intended.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b8c405a53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/context/adaptive.rs

fn apply(&self, budget: &[ContextSourceConfig]) -> Vec<ContextSourceConfig> {
let base_total = budget.iter().map(|entry| entry.max_pct).sum::<f32>().max(f32::EPSILON);
let base_total = budget.iter().map(|entry| entry.max_pct).sum::<f32>().max(1.0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep adaptive budget normalization based on actual totals

Clamping base_total to 1.0 changes semantics for valid configs where budget percentages sum to less than 1.0 (allowed by context validation), so scaling is no longer anchored to the real pre-adaptation total. In those cases, adaptation can inflate per-source caps and increase total allocated share beyond what the config specified, which breaks the invariant this function is supposed to preserve and can materially change context allocation behavior.

Useful? React with 👍 / 👎.

coe0718 pushed a commit that referenced this pull request May 5, 2026
- Plugin should_block checked in execute_tool_request before SecurityPolicy
- PluginRegistry loaded at session start in PraxisRuntime (cli/core, daemon, tests)
- Curator::run_cycle() called in execute_reflect after learning, gated by LiteCapability::Curator
- LiteMode gains disable_curator field + LiteCapability::Curator variant
- PRAXIS_GAPS.md updated: #2 code exec, #3 plugin wiring, #6 curator wiring,
  #9 voice/TTS, #12 tool policy, #29 model switching — all marked with real impl details
- cargo check clean (0 errors)
coe0718 pushed a commit that referenced this pull request May 6, 2026
New modules implementing all gaps from GAP_ANALYSIS_HERMES_OPENCLAW.md:
- #2 Sessions spawn (src/session/) — programmatic session creation for kanban workers
- #3 Curator (already existed, verified wiring)
- #4 429 fallback (src/backend/retry.rs) — exponential backoff with jitter
- #5 Cron extensions (src/tools/cron_ext.rs) — no_agent script mode, wake_gate
- #6 Live Canvas (src/canvas/) — streaming HTML workspace surface
- #7 LanceDB memory (src/memory/lance.rs) — vector-backed semantic recall
- #8 Auto-reply (src/messaging/auto_reply.rs) — rate-limited proactive responses
- #9 i18n (src/i18n/) — 9 languages, builtin + custom translations
- #10 Plugin marketplace (src/plugins/marketplace.rs) — remote discovery + install

Also added:
- Discord/Slack inbound polling (src/messaging/inbound.rs)
- Plugin registry stub (src/plugins/registry.rs)

Fixed all compiler warnings:
- Unused imports removed (session, kanban, auto_reply, lance, marketplace)
- Dead code annotated with #[allow(dead_code)] for API surface items
- Deprecated tungstenite::read_message -> read
- Unnecessary mut bindings cleaned
- cargo fmt applied
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