Skip to content

[codex] Use lightweight context for Foundation#979

Open
mimeding wants to merge 1 commit intoosaurus-ai:mainfrom
mimeding:codex/foundation-light-context
Open

[codex] Use lightweight context for Foundation#979
mimeding wants to merge 1 commit intoosaurus-ai:mainfrom
mimeding:codex/foundation-light-context

Conversation

@mimeding
Copy link
Copy Markdown
Contributor

@mimeding mimeding commented Apr 30, 2026

Business rationale

Apple Foundation is the lightest local chat path, but its small context window makes the default Osaurus harness feel unreliable if baseline tool schemas and memory consume the budget before the user's request arrives. This advances the harness pillar by making Foundation chats start lean while still preserving the agent's ability to add tools on demand when the task actually needs them.

Coding rationale

  • Reused ContextSizeResolver from current main instead of carrying a second Foundation-only detector, so context policy remains centralized.
  • Treated tiny-context models as a baseline-tool trim rather than a hard tool ban, which keeps capabilities_load and other explicit session-loaded tools available when requested.
  • Kept gated guide text, skill suggestions, and memory estimates out of the lightweight prompt so Foundation pays only for active capabilities.
  • Added tests at the prompt-composer boundary because that is where tool visibility, memory disabling, and preview/send parity meet.

What changed

  • Rebased the PR onto origin/main and collapsed stale CI/TTS tail commits out of the branch.
  • Updated context-size comments to describe default-baseline trimming rather than a global tool ban.
  • Added the includeBaselineBuiltIns path through tool resolution and always-loaded-name snapshots.
  • Updated chat budget preview memory accounting for context-size memory disablement.
  • Added SessionPreflightCache coverage for Foundation default-baseline omission, session-loaded tools, and non-Foundation baseline preservation.

Validation

  • swift build --package-path Packages/OsaurusCore
  • swift build --package-path Packages/OsaurusCore -c release
  • swift test --package-path Packages/OsaurusCore (1439 tests, 192 suites)
  • xcrun swift-format lint --strict on touched Swift files
  • swiftlint lint --strict on touched Swift files
  • git diff --check
  • CLI gate skipped; this PR does not touch Packages/OsaurusCLI.

Non-scope

  • No changes to provider selection, model installation, or the broader CI workflow.
  • No changes to the on-demand skills package in [codex] Add on-demand high-fidelity skills #974.
  • No changes to the TTS/FluidAudio commits that previously leaked onto this branch.

Residual risks

  • Foundation can still exceed budget on very long conversations; this PR trims startup weight, not conversation history.
  • GitHub checks restarted after the force-with-lease push and must finish green before merge.

Fixes #973.

@mimeding mimeding marked this pull request as ready for review April 30, 2026 01:14
@tpae
Copy link
Copy Markdown
Contributor

tpae commented Apr 30, 2026

@mimeding thank you for the contribution, however, i feel this PR is a bit redundant because user should be able to disable tools and memory per agent configuration. we're not sure how the foundation model will evolve in the future, would rather prefer user does their own configuration vs. defining specific code paths.

@mimeding mimeding force-pushed the codex/foundation-light-context branch from 98ce1a8 to 98f8e32 Compare May 1, 2026 02:53
@mimeding mimeding force-pushed the codex/foundation-light-context branch 2 times, most recently from da59253 to 1a34054 Compare May 1, 2026 17:37
@tpae
Copy link
Copy Markdown
Contributor

tpae commented May 1, 2026

@mimeding i was able to address this issue from a critical bug that was found: #996

Business rationale: Apple's Foundation model is useful for local, private chat, but its small context window makes the default Osaurus harness too heavy if every baseline tool and memory section is injected up front. This keeps the harness trustworthy by making Foundation chats start light while still allowing explicit on-demand tools when the agent or user needs them.

Coding rationale: Reuse the existing ContextSizeResolver from main instead of adding a second Foundation detector. Treat tiny-context models as a baseline-tool trim, not a hard tool ban, so additional session-loaded tools can still be resolved. Keep gated guide text and memory estimates out of tiny prompts, and pin the behavior with SessionPreflightCacheTests while preserving the preview/send disable-info parity tests.

Co-authored-by: Codex <codex@openai.com>
@mimeding mimeding force-pushed the codex/foundation-light-context branch from 1a34054 to aec5531 Compare May 3, 2026 21:19
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.

Default system prompt is too heavy for Foundation

2 participants