Severity: HIGH
Status: ✅ FIXED
Files: src/options.zig:259, src/server/server.zig:3547, src/char_width.zig:30-31
codepoint-widths is registered in the session option table:
// src/options.zig:259
.{ .name = "codepoint-widths", .type = .string, .default = OptionValue{ .string = "" } },
Registering it in SESSION_OPTIONS means it is inherited and settable per
session, so set -t <session> codepoint-widths "U+2705=1" is accepted and
stored in that session’s option table. The handler that reacts to the change
then discards the session identity entirely and writes a module-global table:
// src/server/server.zig:3547
if (std.mem.eql(u8, s.option, "codepoint-widths") and s.value == .string) {
char_width.applyCodepointWidths(self.allocator, s.value.string) catch |err| {
std.log.warn("codepoint-widths: {s}", .{@errorName(err)});
};
}
// src/char_width.zig:30-31
var override_count: usize = 0;
var overrides: [MAX_OVERRIDES]Override = undefined;
Two consequences follow:
charWidth call reads the same
overrides array. Setting the option on one session changes rendering in
all others. Because these are ambiguous-width and emoji-presentation
codepoints (bug #206), the visible effect is cursor drift and leftover
characters in sessions that never asked for the override.applyCodepointWidths calls clearOverrides() and rebuilds from scratch
(by design, so a full assignment replaces the table). A second session
assigning the default empty string therefore erases the first session’s
overrides rather than merely adding to them.variation-selector-always-wide has the identical shape via
setVariationSelectorAlwaysWide writing the module-global
variation_selector_always_wide (src/char_width.zig:47).
tmux scopes this option at the server level, not the session level:
/* tmux/options-table.c:323 */
{ .name = "codepoint-widths",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER,
So the correct end state is one of:
Session/Pane and pass it to
charWidth, honouring principle 4 in AGENTS.md (“No global state”).The current middle ground — advertised as session-scoped, implemented as
process-global — is wrong under either reading. The docstring at
src/options.zig:258 compounds the confusion by documenting the form
set -g codepoint-widths ... (a global store) on an option registered in the
session table.
Decide the intended scope, then make the registration, the handler, and the docstring agree:
codepoint-widths and
variation-selector-always-wide out of SESSION_OPTIONS into a server
option table, reject set -t for them, and keep the single global override
table. Update the comment at src/options.zig:253-258 to state that the
table is process-wide.overrides / override_count / variation_selector_always_wide onto
Session, change charWidth(cp) to charWidth(cp, widths), and update the
~30 call sites in screen.zig, render.zig, grid.zig, and tty/.Either way, add a regression test asserting that a second session’s assignment does not alter the first session’s resolved widths.
Fixed. codepoint-widths and variation-selector-always-wide are now declared
server-scoped and behave that way.
src/options.zig — added isServerScoped(name), the single place that
answers “is this option’s effect process-wide?”, and documented both option
definitions as SERVER-SCOPED.src/cmd/cmd.zig — setOptionInternal redirects a server-scoped name to the
global store (if (options_mod.isServerScoped(option_name)) is_global = true;)
before the scope branch, so a bare set-option no longer writes a per-session
copy of a value that is applied globally. This matches
Server.applyDirectives, which already wrote every config-file set to
global_options, and tmux’s OPTIONS_TABLE_SERVER.Five regression tests: three in cmd.zig (bare set-option lands in the server
store and the active session mirrors it; the server store is the single
authority; variation-selector-always-wide is server-scoped) and two in
options.zig (the predicate, including near-miss names, and that both names
remain registered in SESSION_OPTIONS with the right type so the set -g write
cannot fail with UnknownOption).
One finding from implementing this: the original report assumed sessions each
kept a live view of the global store. They do not — Session.init clones it,
and setOptionInternal deliberately mirrors a -g write onto the active
session so live config still applies (bug #506’s “session clone” note). So a
session that was never active keeps its creation-time snapshot. That is the
general snapshot-inheritance model shared by every option and is unchanged here;
it does not affect rendering, because the width table is process-wide and holds
the single applied value. show-options on a non-active session will therefore
still report the snapshot for these two options, which is a pre-existing
property of the option model rather than a regression.