Skip to content

Add session-scoped context experiments - #55066

Open
2001Y wants to merge 2 commits into
NousResearch:mainfrom
2001Y:feat/context-experiments
Open

2001Y wants to merge 2 commits into
NousResearch:mainfrom
2001Y:feat/context-experiments

Conversation

@2001Y

@2001Y 2001Y commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a session-scoped context_experiments config block for A/B testing prompt context arms before system-prompt assembly
  • support deterministic hash or persisted round-robin assignment by session id, with optional platform filters
  • load experiment arm context files and optional preloaded skills in place of normal project context
  • document the config shape in prompt assembly docs

Tests

  • scripts/run_tests.sh tests/agent/test_context_experiments.py tests/agent/test_system_prompt.py tests/agent/test_prompt_builder.py tests/hermes_cli/test_prompt_size.py tests/hermes_cli/test_prompt_compose_command.py -q
  • .venv/bin/python -m ruff check agent/context_experiments.py agent/prompt_builder.py agent/system_prompt.py tests/agent/test_context_experiments.py tests/agent/test_system_prompt.py
  • .venv/bin/ty check agent/context_experiments.py tests/agent/test_context_experiments.py tests/agent/test_system_prompt.py

Notes

  • A full scripts/run_tests.sh attempt initially failed because the newly created local .venv lacked pytest; after syncing the dev extra, the targeted canonical suite above passed.

@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have labels Jun 29, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the session-scoped assignment design and the focused tests. I found one cross-platform correctness issue.

Problems

  • agent/context_experiments.py:67-75 — the msvcrt branch opens an empty a+ lock file and, on OSError, logs then executes the state read-modify-write cycle without a lock. This breaks the stated round-robin serialization guarantee for concurrent Windows processes. Existing lock implementations document and handle this requirement by seeding one byte, opening r+, and seeking to offset zero before msvcrt.locking() (hermes_cli/auth.py:1024-1037; tools/skill_usage.py:99-108).

Suggested changes

  • Seed and seek the Windows lock file using the established helper pattern, and do not perform the assignment update when locking cannot be acquired.
  • Add coverage for the msvcrt path and lock failure/concurrent assignment behavior; the new tests currently exercise only serial direct builder calls (tests/agent/test_context_experiments.py:43-78).

Automated hermes-sweeper review.

/ f"{_safe_state_name(experiment_name)}.json"
)


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On Windows, msvcrt.locking() requires a non-empty lock file and a file pointer at offset zero; this a+ open leaves the new lock file empty, and the exception path below then continues the round-robin read-modify-write cycle unlocked. Please follow the seeded-byte + r+ + seek(0) pattern in hermes_cli/auth.py:1024-1037, and avoid assigning when the process lock cannot be acquired.

@teknium1 teknium1 added sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 15, 2026
@teknium1 teknium1 added the area/sessions Session lifecycle, resume, persistence, history label Jul 19, 2026
@2001Y
2001Y force-pushed the feat/context-experiments branch from 39467f8 to e5eb2a6 Compare July 19, 2026 16:09
@2001Y

2001Y commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Rechecked the current head e5eb2a6 against the context-experiments review feedback.

The current implementation and regression coverage are present; no additional code change was needed in this recheck.

Verification:

  • python -m pytest -q tests/agent/test_context_experiments.py
  • git diff --check

Please re-review the current head.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants