feat(desktop): implement missing Settings API endpoints and desktop providers API fixes - #903
Conversation
…roviders API fixes
Test Results 5 files 997 suites 5m 15s ⏱️ For more details on these errors, see this check. Results for commit fb3a368. |
|
Thanks for this — the cost-aware compaction trigger and the compaction telemetry are a useful direction, and the two TUI shutdown fixes ( Four things before this lands: 1. Could you retitle the PR and update the description?The current title is:
I couldn't find anything in the diff that matches it. There are no new Settings API endpoints, and nothing desktop-specific — What the diff actually contains:
Those Something like 2. Drop
|
| Constant | Change | File |
|---|---|---|
SUBAGENT_DEFAULT_MAX_TURNS |
30 → 100 | src/agent/run_agent.py:35 |
DEFAULT_GOAL_MAX_TURNS |
20 → 100 | src/goals/goals.py:57 |
QueryConfig.max_turns |
50 → 200 | src/query/config.py:10 |
QueryConfig.max_turns |
50 → 200 | src/query/config.py:41 |
DEFAULT_MAX_TURNS |
50 → 200 | src/server/agent_server.py:97 |
These are 2–4x increases to agent iteration budgets, and they're independent of the compaction work in the rest of the PR. What's driving them? If they're required for the cost-aware path, it'd help to say so; if they're a separate concern, they'd be much easier to review (and to revert independently) as their own PR.
4. The test file no longer parses
tests/test_context_analyzer.py currently fails at collection:
E File "tests/test_context_analyzer.py", line 185
E unittest.main()
E IndentationError: expected an indented block after 'if' statement on line 184
Removing test_shows_api_usage left the module guard indented into the class body:
if __name__ == "__main__":
unittest.main()It needs to go back to module level:
self.assertIn("CLAWCODEX.md", markdown)
if __name__ == "__main__":
unittest.main()Worth flagging that the blast radius is bigger than the one deleted test: because it's a parse error rather than a failing assertion, pytest can't collect the module at all, so every remaining test in TestAnalyzeContext / TestFormatContextAsMarkdown stops running too.
Separately on testing — the PR adds roughly 660 lines of new logic (_should_auto_compact_cost_aware, the two telemetry dataclasses, _estimate_compaction_cost_delta, log_post_compaction_telemetry) with no new tests. Could you add coverage for those paths?
For what it's worth, the rest of the suite is green: with that one file excluded, pytest tests/ -m "not integration" gives 10,108 passed, 17 skipped. This is the only thing in the way.
Heads-up: two bugs you'll hit while writing those tests
Flagging these now so you're not debugging them from scratch — as written, the telemetry feature can't fire at all. Both verified by running the code on this branch.
a. CompactionTelemetryData is missing three of the fields /context reads.
src/command_system/builtins.py:420-422 reads:
"cache_hit_rate_after": telemetry.cache_hit_rate_after,
"estimated_cost_delta_usd": telemetry.estimated_cost_delta_usd,
"cost_increased": telemetry.cost_increased,But CompactionTelemetryData in src/bootstrap/state.py defines only trigger, tokens_shed, pre_compact_token_count, post_compact_token_count, compaction_cost_usd, cache_hit_rate_before, model:
>>> CompactionTelemetryData().cache_hit_rate_after
AttributeError: 'CompactionTelemetryData' object has no attribute 'cache_hit_rate_after'
Those three fields exist on the other dataclass — CompactionTelemetry in compact.py — which never reaches state. The except Exception: pass at builtins.py:424 swallows the AttributeError, so compaction_telemetry stays None and the new warning block in format_context_as_markdown never renders. No log line either, so it fails completely silently.
b. _estimate_compaction_cost_delta divides by 1e6 twice.
src/services/compact/compact.py:147:
cost_shed = (uncached_shed * input_rate + cached_shed * cache_read_rate) / 1_000_000get_pricing() already returns per-token rates — src/services/pricing.py:27 is "input": 3.0 / 1_000_000 — and the repo's own compute_cost (pricing.py:441-446) multiplies them directly with no division. So the estimate comes out 1,000,000x too small, which makes cost_increased = estimated_delta > compaction_cost_usd false for any real compaction.
Worth double-checking the sign convention on that return value too while you're in there: the docstring says "positive = compaction increased cost," but the value returned is cost_shed, which is the cost of the tokens compaction removed — i.e. a saving.
Summary
Implements missing Settings API endpoints for the desktop provider integration and fixes desktop providers API issues.
Changes
Testing
Closes: (add issue numbers if applicable)