A lot depends on if/how connection pooling or similar is setup, because each request may be going to a different session that exists on the database, or even a brand new session (eg if all existing sessions that serve requests were busy).
Hence typically for usage of global contexts, the very first part of *every* request is a call to DBMS_SESSION.set_identifier. Effectively, its a "Hey, its 'me' I'm back again" announcement back to the database.
If somewhere in your midst (redirect or otherwise) you potentially have a call that does not set the client_id, then it could be lost, and hence you wont see the global context information you might have been expecting.
Hope that makes sense.
eg
SQL> create or replace context DEMO using p accessed globally;
Context created.
SQL>
SQL> create or replace procedure p(p_attr varchar2) is
2 begin
3 dbms_session.set_context('DEMO','ATTR',p_attr,client_id=>sys_context('USERENV','CLIENT_IDENTIFIER'));
4 end;
5 /
Procedure created.
SQL> exec dbms_session.set_identifier('ME');
PL/SQL procedure successfully completed.
SQL> exec p('MY_VALUE');
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> create or replace
2 procedure good_proc is
3 begin
4 dbms_session.set_identifier('ME');
5 dbms_output.put_line(sys_context('DEMO','ATTR'));
6 end;
7 /
Procedure created.
SQL>
SQL> create or replace
2 procedure bad_proc is
3 begin
4 dbms_output.put_line(sys_context('DEMO','ATTR'));
5 end;
6 /
Procedure created.
So good_proc always sets the client_id and bad_proc does not. Under SOME situations, both will appear to work fine.
SQL> exec good_proc
MY_VALUE
PL/SQL procedure successfully completed.
SQL> exec bad_proc
MY_VALUE
PL/SQL procedure successfully completed.
SQL>
But bad_proc only worked because good_proc ran first, and they were in the same session. If I reconnect ...
SQL> conn scott/tiger
Connected.
SQL> set serverout on
SQL> exec bad_proc
PL/SQL procedure successfully completed.
SQL> exec good_proc
MY_VALUE
PL/SQL procedure successfully completed.
then bad_proc has lost its way.