Skip to content

docs: 2.0 memory contract (0252) and its implementation tasks - #593

Merged
rmorozov merged 3 commits into
masterfrom
claude/project-thread-y3z2kt
Oct 19, 2026
Merged

rmorozov merged 3 commits into
masterfrom
claude/project-thread-y3z2kt

Conversation

@rmorozov

Copy link
Copy Markdown
Member

Requested by Ruslan · project thread

Before: the 2.0 API document said nothing about where Jinja2C++ allocates, what it keeps per thread, how out-of-memory surfaces, or how output can go anywhere but an ostream or a fresh string.

After: docs/api-2.0.md section 3.9 states the memory contract Ruslan approved on 2026-10-18, and four implementation tasks carry it out.

Decisions (all as recommended in the plan):

  • R1: no allocator parameters in 2.0. Value and its containers stay on std::allocator. A later hook would be an additive TemplateEnv method taking a std::pmr::memory_resource&.
  • R2: std::bad_alloc is only for system out-of-memory. Every limit and every spent budget is ResourceLimitExceeded, matching 0250 (docs: 2.0 error contract (0250) and untrusted-input mode tasks #584).
  • R3: Render(ostream&) stays all-or-nothing.
  • R4: new RenderTo(StringType&) and RenderTo(BasicOutputSink&) overloads, plus a header-only ContainerSink that also covers fmt::memory_buffer. fmt stays a private dependency.
  • ReleaseThreadCaches(): frees what renders keep on a thread, including the last environment's globals, which are currently retained after the TemplateEnv is destroyed.

How: this is a docs-only PR.

  • docs/api-2.0.md gets 3.9, decision 7 and an entry in section 10.
  • The architect plan is added as docs/design/0252-memory-contract-plan.md.
  • 0252 is marked done.
  • New tasks:
    • 0256: Load and Render crash at some allocation-failure points (a probe found 4/24 in Load and 8/96 in Render); fix them and add an OOM sweep test.
    • 0257: RenderTo and the sink.
    • 0275: ReleaseThreadCaches.
    • 0276: user docs.

Notes for the merge steward:

Roles: architect (plan, with an OOM fault-injection probe). Verifier not run (docs only). Pushes red in CI: none so far.


Generated by Claude Code

Ruslan approved the 0252 plan as recommended: no allocator parameters in
2.0, bad_alloc only for system out-of-memory (budgets are
ResourceLimitExceeded, as in 0250), Render(ostream&) stays all-or-nothing,
RenderTo into a string or an output sink plus a header-only ContainerSink,
and ReleaseThreadCaches(). docs/api-2.0.md gains section 3.9, decision 7
and the rejected options; the plan goes to docs/design. Files tasks 0256
(allocation-failure crashes), 0257 (RenderTo), 0275 (ReleaseThreadCaches)
and 0276 (user docs); 0252 is done.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEfqEiJoJF5wCn3xZSp8zW
@rmorozov rmorozov self-assigned this Oct 18, 2026
@rmorozov
rmorozov marked this pull request as ready for review October 18, 2026 15:11
…0279)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEfqEiJoJF5wCn3xZSp8zW
…implies

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEfqEiJoJF5wCn3xZSp8zW
@rmorozov
rmorozov merged commit b2a6c62 into master Oct 19, 2026
3 checks passed
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.

2 participants